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
@@ -3,24 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BCryptWrapper = void 0;
4
4
  const index_1 = require("./../../index");
5
5
  class BCryptWrapper {
6
+ /**
7
+ * Verifies a password with BCrypt on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
6
12
  verifyThreadPool(hashedPassword, passwordToCheck) {
7
13
  if (!hashedPassword || !passwordToCheck) {
8
14
  throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
9
15
  }
10
16
  return (0, index_1.bcryptVerifyThreadpool)(hashedPassword, passwordToCheck);
11
17
  }
18
+ /**
19
+ * Hashes a password with BCrypt on the threadpool.
20
+ * @param password
21
+ * @returns string
22
+ */
12
23
  hashPasswordThreadPool(password) {
13
24
  if (!password) {
14
25
  throw new Error("You must provide a password to hash with Argon2");
15
26
  }
16
27
  return (0, index_1.bcryptHashThreadpool)(password);
17
28
  }
29
+ /**
30
+ * Hashes a password with BCrypt
31
+ * @param password
32
+ * @returns string
33
+ */
18
34
  hashPassword(password) {
19
35
  if (!password) {
20
36
  throw new Error("You must provide a password to hash with Argon2");
21
37
  }
22
38
  return (0, index_1.bcryptHash)(password);
23
39
  }
40
+ /**
41
+ * Verifies that a password is the same as the hashed password with BCrypt.
42
+ * @param hashedPassword
43
+ * @param passwordToVerify
44
+ * @returns boolean
45
+ */
24
46
  verify(hashedPassword, passwordToVerify) {
25
47
  if (!hashedPassword || !passwordToVerify) {
26
48
  throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
@@ -1,4 +1,9 @@
1
1
  import { PasswordHasherType } from "./password-hasher-type";
2
2
  export declare class PasswordHasherFactory {
3
+ /**
4
+ * Returns the appropriate hasher type based upon the type passed in.
5
+ * @param type
6
+ * @returns
7
+ */
3
8
  static getHasher(type: PasswordHasherType): any;
4
9
  }
@@ -6,6 +6,11 @@ const bcrypt_wrapper_1 = require("./bcrypt-wrapper");
6
6
  const password_hasher_type_1 = require("./password-hasher-type");
7
7
  const scrypt_wrapper_1 = require("./scrypt-wrapper");
8
8
  class PasswordHasherFactory {
9
+ /**
10
+ * Returns the appropriate hasher type based upon the type passed in.
11
+ * @param type
12
+ * @returns
13
+ */
9
14
  static getHasher(type) {
10
15
  // Argon2 by default
11
16
  let hasher = new argon2_wrapper_1.Argon2Wrapper();
@@ -1,7 +1,29 @@
1
1
  import { IPasswordHasherBase } from "./password-hasher-base";
2
2
  export declare class ScryptWrapper implements IPasswordHasherBase {
3
+ /**
4
+ * Verifies a password with SCrypt 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 SCrypt on the threadpool.
12
+ * @param password
13
+ * @returns string
14
+ */
4
15
  hashPasswordThreadPool(password: string): string;
16
+ /**
17
+ * Hashes a password with SCrypt
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 SCrypt.
24
+ * @param hashedPassword
25
+ * @param passwordToVerify
26
+ * @returns boolean
27
+ */
6
28
  verify(hashedPassword: string, passwordToVerify: string): boolean;
7
29
  }
@@ -3,24 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ScryptWrapper = void 0;
4
4
  const index_1 = require("../../index");
5
5
  class ScryptWrapper {
6
+ /**
7
+ * Verifies a password with SCrypt on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
6
12
  verifyThreadPool(hashedPassword, passwordToCheck) {
7
13
  if (!hashedPassword || !passwordToCheck) {
8
14
  throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
9
15
  }
10
16
  return (0, index_1.scryptVerifyThreadpool)(hashedPassword, passwordToCheck);
11
17
  }
18
+ /**
19
+ * Hashes a password with SCrypt on the threadpool.
20
+ * @param password
21
+ * @returns string
22
+ */
12
23
  hashPasswordThreadPool(password) {
13
24
  if (!password) {
14
25
  throw new Error("You must provide a password to hash with Scrypt");
15
26
  }
16
27
  return (0, index_1.scryptHashThreadpool)(password);
17
28
  }
29
+ /**
30
+ * Hashes a password with SCrypt
31
+ * @param password
32
+ * @returns string
33
+ */
18
34
  hashPassword(password) {
19
35
  if (!password) {
20
36
  throw new Error("You must provide a password to hash with Scrypt");
21
37
  }
22
38
  return (0, index_1.scryptHash)(password);
23
39
  }
40
+ /**
41
+ * Verifies that a password is the same as the hashed password with SCrypt.
42
+ * @param hashedPassword
43
+ * @param passwordToVerify
44
+ * @returns boolean
45
+ */
24
46
  verify(hashedPassword, passwordToVerify) {
25
47
  if (!hashedPassword || !passwordToVerify) {
26
48
  throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
@@ -1,6 +1,28 @@
1
1
  export declare class AsconWrapper {
2
+ /**
3
+ * Generates an Ascon 128 key
4
+ * @returns Array<number>
5
+ */
2
6
  ascon128Key(): Array<number>;
7
+ /**
8
+ * Generates and Ascon 128 nonce.
9
+ * @returns Array<number>
10
+ */
3
11
  ascon128Nonce(): Array<number>;
12
+ /**
13
+ * Encrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
14
+ * @param key
15
+ * @param nonce
16
+ * @param plaintext
17
+ * @returns
18
+ */
4
19
  ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
20
+ /**
21
+ * Decrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
22
+ * @param key
23
+ * @param nonce
24
+ * @param ciphertext
25
+ * @returns Array<number>
26
+ */
5
27
  ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
6
28
  }
@@ -3,12 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AsconWrapper = void 0;
4
4
  const index_1 = require("../../index");
5
5
  class AsconWrapper {
6
+ /**
7
+ * Generates an Ascon 128 key
8
+ * @returns Array<number>
9
+ */
6
10
  ascon128Key() {
7
11
  return (0, index_1.ascon128KeyGenerate)();
8
12
  }
13
+ /**
14
+ * Generates and Ascon 128 nonce.
15
+ * @returns Array<number>
16
+ */
9
17
  ascon128Nonce() {
10
18
  return (0, index_1.ascon128NonceGenerate)();
11
19
  }
20
+ /**
21
+ * Encrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
22
+ * @param key
23
+ * @param nonce
24
+ * @param plaintext
25
+ * @returns
26
+ */
12
27
  ascon128Encrypt(key, nonce, plaintext) {
13
28
  if (!key || key.length === 0) {
14
29
  throw new Error("Key is required");
@@ -21,6 +36,13 @@ class AsconWrapper {
21
36
  }
22
37
  return (0, index_1.ascon128Encrypt)(key, nonce, plaintext);
23
38
  }
39
+ /**
40
+ * Decrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
41
+ * @param key
42
+ * @param nonce
43
+ * @param ciphertext
44
+ * @returns Array<number>
45
+ */
24
46
  ascon128Decrypt(key, nonce, ciphertext) {
25
47
  if (!key || key.length === 0) {
26
48
  throw new Error("Key is required");
@@ -1,16 +1,4 @@
1
1
  import { AesKeyFromX25519SharedSecret } from "../../index";
2
- /**
3
- * @description A wrapper class that contains methods to construct keys, nonces, and methods to encrypt and decrypt with AES-128-GCM and AES-256-GCM
4
- *
5
- * @example
6
- * ```ts
7
- * const nonce = aesWrapper.generateAESNonce();
8
- const key = aesWrapper.aes128Key();
9
- const textEncoder = new TextEncoder();
10
- const array = Array.from(textEncoder.encode("Hello World"));
11
- const encrypted = aesWrapper.aes128Encrypt(key, nonce, array);
12
- * ```
13
- */
14
2
  export declare class AESWrapper {
15
3
  /**
16
4
  * @description Generates a 128 bit AES key
@@ -22,11 +10,53 @@ export declare class AESWrapper {
22
10
  * @returns returns a 256 bit AES key
23
11
  */
24
12
  aes256Key(): Array<number>;
13
+ /**
14
+ * Generates an 96 bit AES nonce
15
+ * @returns Array<number>
16
+ */
25
17
  generateAESNonce(): Array<number>;
18
+ /**
19
+ * Encrypts with AES 128.
20
+ * @param aesKey
21
+ * @param nonce
22
+ * @param plaintext
23
+ * @returns Array<number>
24
+ */
26
25
  aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
26
+ /**
27
+ * Decrypts with AES 128
28
+ * @param aesKey
29
+ * @param nonce
30
+ * @param ciphertext
31
+ * @returns Array<number>
32
+ */
27
33
  aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
34
+ /**
35
+ * Encrypts with AES-256
36
+ * @param aesKey
37
+ * @param nonce
38
+ * @param plaintext
39
+ * @returns
40
+ */
28
41
  aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
42
+ /**
43
+ * Decrypts with AES 256
44
+ * @param aesKey
45
+ * @param nonce
46
+ * @param ciphertext
47
+ * @returns
48
+ */
29
49
  aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
50
+ /**
51
+ * Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
52
+ * @param shared_secret
53
+ * @returns
54
+ */
30
55
  aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
56
+ /**
57
+ * Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
58
+ * @param shared_secret
59
+ * @returns
60
+ */
31
61
  aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
32
62
  }
@@ -2,18 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AESWrapper = void 0;
4
4
  const index_1 = require("../../index");
5
- /**
6
- * @description A wrapper class that contains methods to construct keys, nonces, and methods to encrypt and decrypt with AES-128-GCM and AES-256-GCM
7
- *
8
- * @example
9
- * ```ts
10
- * const nonce = aesWrapper.generateAESNonce();
11
- const key = aesWrapper.aes128Key();
12
- const textEncoder = new TextEncoder();
13
- const array = Array.from(textEncoder.encode("Hello World"));
14
- const encrypted = aesWrapper.aes128Encrypt(key, nonce, array);
15
- * ```
16
- */
17
5
  class AESWrapper {
18
6
  /**
19
7
  * @description Generates a 128 bit AES key
@@ -29,24 +17,66 @@ class AESWrapper {
29
17
  aes256Key() {
30
18
  return (0, index_1.aes256Key)();
31
19
  }
20
+ /**
21
+ * Generates an 96 bit AES nonce
22
+ * @returns Array<number>
23
+ */
32
24
  generateAESNonce() {
33
25
  return (0, index_1.aesNonce)();
34
26
  }
27
+ /**
28
+ * Encrypts with AES 128.
29
+ * @param aesKey
30
+ * @param nonce
31
+ * @param plaintext
32
+ * @returns Array<number>
33
+ */
35
34
  aes128Encrypt(aesKey, nonce, plaintext) {
36
35
  return (0, index_1.aes128Encrypt)(aesKey, nonce, plaintext);
37
36
  }
37
+ /**
38
+ * Decrypts with AES 128
39
+ * @param aesKey
40
+ * @param nonce
41
+ * @param ciphertext
42
+ * @returns Array<number>
43
+ */
38
44
  aes128Decrypt(aesKey, nonce, ciphertext) {
39
45
  return (0, index_1.aes128Decrypt)(aesKey, nonce, ciphertext);
40
46
  }
47
+ /**
48
+ * Encrypts with AES-256
49
+ * @param aesKey
50
+ * @param nonce
51
+ * @param plaintext
52
+ * @returns
53
+ */
41
54
  aes256Encrypt(aesKey, nonce, plaintext) {
42
55
  return (0, index_1.aes256Encrypt)(aesKey, nonce, plaintext);
43
56
  }
57
+ /**
58
+ * Decrypts with AES 256
59
+ * @param aesKey
60
+ * @param nonce
61
+ * @param ciphertext
62
+ * @returns
63
+ */
44
64
  aes256Decrypt(aesKey, nonce, ciphertext) {
45
65
  return (0, index_1.aes256Decrypt)(aesKey, nonce, ciphertext);
46
66
  }
67
+ /**
68
+ * Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
69
+ * @param shared_secret
70
+ * @returns
71
+ */
47
72
  aes256KeyNonceX25519DiffieHellman(shared_secret) {
48
73
  return (0, index_1.aes256KeyFromX25519SharedSecret)(shared_secret);
49
74
  }
75
+ /**
76
+ * Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
77
+ * @param shared_secret
78
+ * @returns
79
+ */
50
80
  aes128KeyNonceX25519DiffieHellman(shared_secret) {
51
81
  return (0, index_1.aes128KeyFromX25519SharedSecret)(shared_secret);
52
82
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  {
3
3
  "name": "cas-typescript-sdk",
4
- "version": "1.0.22",
4
+ "version": "1.0.23",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,6 +1,12 @@
1
1
  import { decryptCiphertextRsa, encryptPlaintextRsa, generateRsaKeys, RsaKeyPairResult, signRsa, verifyRsa } from "../../index";
2
2
 
3
3
  export class RSAWrapper {
4
+
5
+ /**
6
+ * Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
7
+ * @param keySize
8
+ * @returns RsaKeyPairResult
9
+ */
4
10
  public generateKeys(keySize: number): RsaKeyPairResult {
5
11
  if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
6
12
  throw new Error("You must provide an appropriate key size to generate RSA keys");
@@ -8,6 +14,13 @@ export class RSAWrapper {
8
14
  return generateRsaKeys(keySize);
9
15
  }
10
16
 
17
+ /**
18
+ * Encrypts a plaintext byte array with a RSA public key
19
+ * @param publicKey
20
+ * @param plaintext
21
+ * @returns Array<number>
22
+ */
23
+
11
24
  public encrypt(publicKey: string, plaintext: Array<number>): Array<number> {
12
25
  if (!publicKey) {
13
26
  throw new Error("You must provide a public key to encrypt with RSA");
@@ -18,6 +31,13 @@ export class RSAWrapper {
18
31
  return encryptPlaintextRsa(publicKey, plaintext);
19
32
  }
20
33
 
34
+ /**
35
+ * Decrypts a ciphertext with an RSA private key.
36
+ * @param privateKey
37
+ * @param ciphertext
38
+ * @returns Array<number>
39
+ */
40
+
21
41
  public decrypt(privateKey: string, ciphertext: Array<number>): Array<number> {
22
42
  if (!privateKey) {
23
43
  throw new Error("You must provide a private key to encrypt with RSA");
@@ -28,16 +48,29 @@ export class RSAWrapper {
28
48
  return decryptCiphertextRsa(privateKey, ciphertext);
29
49
  }
30
50
 
31
- public sign(privateKey: string, hash: Array<number>): Array<number> {
51
+ /**
52
+ * Signs a byte array with an RSA private key for verification.
53
+ * @param privateKey
54
+ * @param hash
55
+ * @returns Array<number>
56
+ */
57
+ public sign(privateKey: string, dataToSign: Array<number>): Array<number> {
32
58
  if (!privateKey) {
33
59
  throw new Error("You must provide a private key to sign with RSA");
34
60
  }
35
- if (!hash || hash.length === 0) {
61
+ if (!dataToSign || dataToSign.length === 0) {
36
62
  throw new Error("You must provide an allocated hash to sign with RSA");
37
63
  }
38
- return signRsa(privateKey, hash);
64
+ return signRsa(privateKey, dataToSign);
39
65
  }
40
66
 
67
+ /**
68
+ * Verifies signed data by the corresponding private key with an RSA public key.
69
+ * @param publicKey
70
+ * @param hash
71
+ * @param signature
72
+ * @returns boolean
73
+ */
41
74
  public verify(publicKey: string, hash: Array<number>, signature: Array<number>): boolean {
42
75
  if (!publicKey) {
43
76
  throw new Error("You must provide a public key to verify with RSA");
@@ -3,13 +3,25 @@ import { IDigitalSignature } from "./digital-signature-base";
3
3
 
4
4
  export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
5
5
 
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: number[]): SHAED25519DalekDigitalSignatureResult {
7
12
  if (dataToSign?.length === 0) {
8
13
  throw new Error("Must provide allocated data to sign");
9
14
  }
10
15
  return sha512Ed25519DigitalSignature(dataToSign);
11
16
  }
12
-
17
+
18
+ /**
19
+ * Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
20
+ * @param publicKey
21
+ * @param dataToVerify
22
+ * @param signature
23
+ * @returns boolean
24
+ */
13
25
  verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean {
14
26
  if (!publicKey) {
15
27
  throw new Error("You must provide a public key for verify with ED25519");
@@ -23,6 +35,12 @@ export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
23
35
  return sha512Ed25519DigitalSignatureVerify(publicKey, dataToVerify, signature);
24
36
  }
25
37
 
38
+ /**
39
+ * Generates and RSA digital signature with SHA3-512
40
+ * @param rsa_key_size
41
+ * @param data_to_sign
42
+ * @returns RsaDigitalSignatureResult
43
+ */
26
44
  createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult {
27
45
  if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
28
46
  throw new Error("You need to provide an appropriate RSA key size.");
@@ -33,6 +51,13 @@ export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
33
51
  return sha512RsaDigitalSignature(rsa_key_size, data_to_sign);
34
52
  }
35
53
 
54
+ /**
55
+ * Verifies a digital signature created with the RSA public key.
56
+ * @param public_key
57
+ * @param data_to_verify
58
+ * @param signature
59
+ * @returns boolean
60
+ */
36
61
  verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean {
37
62
  if (!public_key) {
38
63
  throw new Error("Must provide a public key");
@@ -7,6 +7,12 @@ export enum DigitalSignatureType {
7
7
  }
8
8
 
9
9
  export class DigitalSignatureFactory {
10
+
11
+ /**
12
+ * Get the appropriate digital signature wrapper based upon the type passed in.
13
+ * @param type
14
+ * @returns
15
+ */
10
16
  public static get(type: DigitalSignatureType) {
11
17
  let ds = new DigitalSignatureSHA512Wrapper();
12
18
  switch (type) {
@@ -3,6 +3,11 @@ import { IDigitalSignature } from "./digital-signature-base";
3
3
 
4
4
  export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
5
5
 
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: number[]): Shaed25519DalekDigitalSignatureResult {
7
12
  if (dataToSign?.length === 0) {
8
13
  throw new Error("Must provide allocated data to sign");
@@ -10,6 +15,13 @@ export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
10
15
  return sha256Ed25519DigitalSignature(dataToSign);
11
16
  }
12
17
 
18
+ /**
19
+ * Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
20
+ * @param publicKey
21
+ * @param dataToVerify
22
+ * @param signature
23
+ * @returns boolean
24
+ */
13
25
  verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean {
14
26
  if (!publicKey) {
15
27
  throw new Error("You must provide a public key for verify with ED25519");
@@ -23,6 +35,12 @@ export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
23
35
  return sha256Ed25519DigitalSignatureVerify(publicKey, dataToVerify, signature);
24
36
  }
25
37
 
38
+ /**
39
+ * Generates and RSA digital signature with SHA3-512
40
+ * @param rsa_key_size
41
+ * @param data_to_sign
42
+ * @returns RsaDigitalSignatureResult
43
+ */
26
44
  createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult {
27
45
  if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
28
46
  throw new Error("You need to provide an appropriate RSA key size.");
@@ -33,6 +51,13 @@ export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
33
51
  return sha256RsaDigitalSignature(rsa_key_size, data_to_sign);
34
52
  }
35
53
 
54
+ /**
55
+ * Verifies a digital signature created with the RSA public key.
56
+ * @param public_key
57
+ * @param data_to_verify
58
+ * @param signature
59
+ * @returns boolean
60
+ */
36
61
  verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean {
37
62
  if (!public_key) {
38
63
  throw new Error("Must provide a public key");
@@ -2,6 +2,11 @@ import { HasherType } from "./hasher-type";
2
2
  import { SHAWrapper } from "./sha-wrapper";
3
3
 
4
4
  export class HasherFactory {
5
+ /**
6
+ * Get the appropriate hasher wrapper based upon the type based in.
7
+ * @param type
8
+ * @returns
9
+ */
5
10
  getHasher(type: HasherType): any {
6
11
  let result: SHAWrapper = new SHAWrapper();
7
12
  switch(type) {
@@ -2,6 +2,11 @@ import { sha256, sha256Verify, sha512, sha512Verify } from "../../index";
2
2
  import { IHasherBase } from "./hasher-base";
3
3
 
4
4
  export class SHAWrapper implements IHasherBase {
5
+ /**
6
+ * Hashes a byte array with SHA3-512.
7
+ * @param dataToHash
8
+ * @returns number[]
9
+ */
5
10
  hash512(dataToHash: number[]): number[] {
6
11
  if (!dataToHash || dataToHash.length === 0) {
7
12
  throw new Error("You must provide an allocated array of data");
@@ -9,6 +14,12 @@ export class SHAWrapper implements IHasherBase {
9
14
  return sha512(dataToHash);
10
15
  }
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: number[], dataToVerify: number[]): boolean {
13
24
  if (!dataToHash || dataToHash.length === 0) {
14
25
  throw new Error("You must provide an allocated array of data");
@@ -19,6 +30,11 @@ export class SHAWrapper implements IHasherBase {
19
30
  return sha512Verify(dataToHash, dataToVerify);
20
31
  }
21
32
 
33
+ /**
34
+ * Hashes a byte array with SHA3-256.
35
+ * @param dataToHash
36
+ * @returns number[]
37
+ */
22
38
  hash256(dataToHash: number[]): number[] {
23
39
  if (!dataToHash || dataToHash.length === 0) {
24
40
  throw new Error("You must provide an allocated array of data");
@@ -26,6 +42,12 @@ export class SHAWrapper implements IHasherBase {
26
42
  return sha256(dataToHash);
27
43
  }
28
44
 
45
+ /**
46
+ * Verifies unsigned data against an SHA3-256 hash.
47
+ * @param dataToHash
48
+ * @param dataToVerify
49
+ * @returns boolean
50
+ */
29
51
  verify256(dataToHash: number[], dataToVerify: number[]): boolean {
30
52
  if (!dataToHash || dataToHash.length === 0) {
31
53
  throw new Error("You must provide an allocated array of data");
@@ -12,6 +12,12 @@ export class HybridEncryptionWrapper {
12
12
  this.rsaWrapper = new RSAWrapper();
13
13
  }
14
14
 
15
+ /**
16
+ * 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.
17
+ * @param dataToEncrypt
18
+ * @param initalizer
19
+ * @returns AesRsaHybridEncryptResult
20
+ */
15
21
  public encrypt(
16
22
  dataToEncrypt: Array<number>,
17
23
  initalizer: AESRSAHybridInitializer,
@@ -40,6 +46,12 @@ export class HybridEncryptionWrapper {
40
46
  return result;
41
47
  }
42
48
 
49
+ /**
50
+ * Decrypts data with RSA/AES hybrid encryption. The RSA private key decrypts the AES key and then the data is decrypted with AES-GCM.
51
+ * @param dataToEncrypt
52
+ * @param initalizer
53
+ * @returns AesRsaHybridEncryptResult
54
+ */
43
55
  public decrypt(
44
56
  privateKey: string,
45
57
  encryptResult: AesRsaHybridEncryptResult,
@@ -8,6 +8,11 @@ export class AESRSAHybridInitializer {
8
8
  public aesNonce: Array<number>;
9
9
  public rsaKeyPair: RsaKeyPairResult;
10
10
 
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: number, rsaSize: number) {
12
17
  if (aesType !== 128 && aesType !== 256) {
13
18
  throw new Error("Need an appropriate AES size to generate a hybrid initalizer");