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
@@ -1,11 +1,23 @@
1
1
  import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey, X25519SecretPublicKeyResult } from "../../index"
2
2
 
3
3
  export class X25519Wrapper {
4
+ /**
5
+ * Generates and secret and public key to be used to create a shared secret with Diffie Hellman.
6
+ * 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.
7
+ * @returns X25519SecretPublicKeyResult
8
+ */
4
9
  public generateSecretAndPublicKey(): X25519SecretPublicKeyResult {
5
10
  return x25519GenerateSecretAndPublicKey();
6
11
  }
7
12
 
8
- public generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>) {
13
+ /**
14
+ * User takes their secret key and the other user's public key to generate a shared secret.
15
+ * Can be used to derive an AES key over insecure channel.
16
+ * @param secretKey
17
+ * @param publicKey
18
+ * @returns Array<number>
19
+ */
20
+ public generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>): Array<number> {
9
21
  return x25519DiffieHellman(secretKey, publicKey);
10
22
  }
11
23
  }
@@ -3,6 +3,12 @@ import { IPasswordHasherBase } from "./password-hasher-base";
3
3
 
4
4
  export class Argon2Wrapper implements IPasswordHasherBase {
5
5
 
6
+ /**
7
+ * Verifies a password with Argon2 on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
6
12
  verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
7
13
  if (!hashedPassword) {
8
14
  throw new Error("You must provide a password to verify with Argon2");
@@ -13,6 +19,11 @@ export class Argon2Wrapper implements IPasswordHasherBase {
13
19
  return argon2VerifyThreadpool(hashedPassword, passwordToCheck);
14
20
  }
15
21
 
22
+ /**
23
+ * Hashes a password with Argon2 on the threadpool.
24
+ * @param password
25
+ * @returns string
26
+ */
16
27
  public hashPasswordThreadPool(password: string): string {
17
28
  if (!password) {
18
29
  throw new Error("You must provide a password to hash with Argon2");
@@ -20,6 +31,11 @@ export class Argon2Wrapper implements IPasswordHasherBase {
20
31
  return argon2HashThreadPool(password);
21
32
  }
22
33
 
34
+ /**
35
+ * Hashes a password with Argon2
36
+ * @param password
37
+ * @returns string
38
+ */
23
39
  public hashPassword(password: string): string {
24
40
  if (!password) {
25
41
  throw new Error("You must provide a password to hash with Argon2");
@@ -27,6 +43,12 @@ export class Argon2Wrapper implements IPasswordHasherBase {
27
43
  return argon2Hash(password);
28
44
  }
29
45
 
46
+ /**
47
+ * Verifies that a password is the same as the hashed password with Argon2.
48
+ * @param hashedPassword
49
+ * @param passwordToVerify
50
+ * @returns boolean
51
+ */
30
52
  public verify(hashedPassword: string, passwordToVerify: string): boolean {
31
53
  if (!hashedPassword || !passwordToVerify) {
32
54
  throw new Error(
@@ -3,6 +3,12 @@ import { bcryptHash, bcryptHashThreadpool, bcryptVerify, bcryptVerifyThreadpool
3
3
 
4
4
  export class BCryptWrapper implements IPasswordHasherBase {
5
5
 
6
+ /**
7
+ * Verifies a password with BCrypt on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
6
12
  verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
7
13
  if (!hashedPassword || !passwordToCheck) {
8
14
  throw new Error(
@@ -12,6 +18,11 @@ export class BCryptWrapper implements IPasswordHasherBase {
12
18
  return bcryptVerifyThreadpool(hashedPassword, passwordToCheck);
13
19
  }
14
20
 
21
+ /**
22
+ * Hashes a password with BCrypt on the threadpool.
23
+ * @param password
24
+ * @returns string
25
+ */
15
26
  public hashPasswordThreadPool(password: string): string {
16
27
  if (!password) {
17
28
  throw new Error("You must provide a password to hash with Argon2");
@@ -19,6 +30,11 @@ export class BCryptWrapper implements IPasswordHasherBase {
19
30
  return bcryptHashThreadpool(password);
20
31
  }
21
32
 
33
+ /**
34
+ * Hashes a password with BCrypt
35
+ * @param password
36
+ * @returns string
37
+ */
22
38
  public hashPassword(password: string): string {
23
39
  if (!password) {
24
40
  throw new Error("You must provide a password to hash with Argon2");
@@ -26,6 +42,12 @@ export class BCryptWrapper implements IPasswordHasherBase {
26
42
  return bcryptHash(password);
27
43
  }
28
44
 
45
+ /**
46
+ * Verifies that a password is the same as the hashed password with BCrypt.
47
+ * @param hashedPassword
48
+ * @param passwordToVerify
49
+ * @returns boolean
50
+ */
29
51
  public verify(
30
52
  hashedPassword: string,
31
53
  passwordToVerify: string,
@@ -4,6 +4,11 @@ import { PasswordHasherType } from "./password-hasher-type";
4
4
  import { ScryptWrapper } from "./scrypt-wrapper";
5
5
 
6
6
  export class PasswordHasherFactory {
7
+ /**
8
+ * Returns the appropriate hasher type based upon the type passed in.
9
+ * @param type
10
+ * @returns
11
+ */
7
12
  static getHasher(type: PasswordHasherType): any {
8
13
  // Argon2 by default
9
14
  let hasher = new Argon2Wrapper();
@@ -3,6 +3,12 @@ import { IPasswordHasherBase } from "./password-hasher-base";
3
3
 
4
4
  export class ScryptWrapper implements IPasswordHasherBase {
5
5
 
6
+ /**
7
+ * Verifies a password with SCrypt on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
6
12
  verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
7
13
  if (!hashedPassword || !passwordToCheck) {
8
14
  throw new Error(
@@ -12,6 +18,11 @@ export class ScryptWrapper implements IPasswordHasherBase {
12
18
  return scryptVerifyThreadpool(hashedPassword, passwordToCheck);
13
19
  }
14
20
 
21
+ /**
22
+ * Hashes a password with SCrypt on the threadpool.
23
+ * @param password
24
+ * @returns string
25
+ */
15
26
  hashPasswordThreadPool(password: string): string {
16
27
  if (!password) {
17
28
  throw new Error("You must provide a password to hash with Scrypt");
@@ -19,6 +30,11 @@ export class ScryptWrapper implements IPasswordHasherBase {
19
30
  return scryptHashThreadpool(password);
20
31
  }
21
32
 
33
+ /**
34
+ * Hashes a password with SCrypt
35
+ * @param password
36
+ * @returns string
37
+ */
22
38
  public hashPassword(password: string): string {
23
39
  if (!password) {
24
40
  throw new Error("You must provide a password to hash with Scrypt");
@@ -26,6 +42,12 @@ export class ScryptWrapper implements IPasswordHasherBase {
26
42
  return scryptHash(password);
27
43
  }
28
44
 
45
+ /**
46
+ * Verifies that a password is the same as the hashed password with SCrypt.
47
+ * @param hashedPassword
48
+ * @param passwordToVerify
49
+ * @returns boolean
50
+ */
29
51
  public verify(hashedPassword: string, passwordToVerify: string): boolean {
30
52
  if (!hashedPassword || !passwordToVerify) {
31
53
  throw new Error(
@@ -6,14 +6,29 @@ import {
6
6
  } from "../../index";
7
7
 
8
8
  export class AsconWrapper {
9
+ /**
10
+ * Generates an Ascon 128 key
11
+ * @returns Array<number>
12
+ */
9
13
  ascon128Key(): Array<number> {
10
14
  return ascon128KeyGenerate();
11
15
  }
12
16
 
17
+ /**
18
+ * Generates and Ascon 128 nonce.
19
+ * @returns Array<number>
20
+ */
13
21
  ascon128Nonce(): Array<number> {
14
22
  return ascon128NonceGenerate();
15
23
  }
16
24
 
25
+ /**
26
+ * Encrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
27
+ * @param key
28
+ * @param nonce
29
+ * @param plaintext
30
+ * @returns
31
+ */
17
32
  ascon128Encrypt(
18
33
  key: Array<number>,
19
34
  nonce: Array<number>,
@@ -31,6 +46,13 @@ export class AsconWrapper {
31
46
  return ascon128Encrypt(key, nonce, plaintext);
32
47
  }
33
48
 
49
+ /**
50
+ * Decrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
51
+ * @param key
52
+ * @param nonce
53
+ * @param ciphertext
54
+ * @returns Array<number>
55
+ */
34
56
  ascon128Decrypt(
35
57
  key: Array<number>,
36
58
  nonce: Array<number>,
@@ -11,18 +11,7 @@ import {
11
11
  aesNonce,
12
12
  } from "../../index";
13
13
 
14
- /**
15
- * @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
16
- *
17
- * @example
18
- * ```ts
19
- * const nonce = aesWrapper.generateAESNonce();
20
- const key = aesWrapper.aes128Key();
21
- const textEncoder = new TextEncoder();
22
- const array = Array.from(textEncoder.encode("Hello World"));
23
- const encrypted = aesWrapper.aes128Encrypt(key, nonce, array);
24
- * ```
25
- */
14
+
26
15
  export class AESWrapper {
27
16
 
28
17
  /**
@@ -41,30 +30,72 @@ export class AESWrapper {
41
30
  return aes256Key();
42
31
  }
43
32
 
33
+ /**
34
+ * Generates an 96 bit AES nonce
35
+ * @returns Array<number>
36
+ */
44
37
  public generateAESNonce(): Array<number> {
45
38
  return aesNonce();
46
39
  }
47
40
 
41
+ /**
42
+ * Encrypts with AES 128.
43
+ * @param aesKey
44
+ * @param nonce
45
+ * @param plaintext
46
+ * @returns Array<number>
47
+ */
48
48
  public aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
49
49
  return aes128Encrypt(aesKey, nonce, plaintext);
50
50
  }
51
51
 
52
+ /**
53
+ * Decrypts with AES 128
54
+ * @param aesKey
55
+ * @param nonce
56
+ * @param ciphertext
57
+ * @returns Array<number>
58
+ */
52
59
  public aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
53
60
  return aes128Decrypt(aesKey, nonce, ciphertext);
54
61
  }
55
62
 
63
+ /**
64
+ * Encrypts with AES-256
65
+ * @param aesKey
66
+ * @param nonce
67
+ * @param plaintext
68
+ * @returns
69
+ */
56
70
  public aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
57
71
  return aes256Encrypt(aesKey, nonce, plaintext);
58
72
  }
59
73
 
74
+ /**
75
+ * Decrypts with AES 256
76
+ * @param aesKey
77
+ * @param nonce
78
+ * @param ciphertext
79
+ * @returns
80
+ */
60
81
  public aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
61
82
  return aes256Decrypt(aesKey, nonce, ciphertext);
62
83
  }
63
84
 
85
+ /**
86
+ * Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
87
+ * @param shared_secret
88
+ * @returns
89
+ */
64
90
  public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
65
91
  return aes256KeyFromX25519SharedSecret(shared_secret);
66
92
  }
67
93
 
94
+ /**
95
+ * Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
96
+ * @param shared_secret
97
+ * @returns
98
+ */
68
99
  public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
69
100
  return aes128KeyFromX25519SharedSecret(shared_secret);
70
101
  }
@@ -1,3 +0,0 @@
1
- export declare class NonceGenerator {
2
- generateNonce(): string;
3
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.NonceGenerator = void 0;
27
- const crypto = __importStar(require("crypto"));
28
- class NonceGenerator {
29
- generateNonce() {
30
- const nonceBytes = crypto.randomBytes(12);
31
- return nonceBytes.toString('hex').substring(0, 12);
32
- }
33
- }
34
- exports.NonceGenerator = NonceGenerator;
@@ -1,9 +0,0 @@
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
- }