cas-typescript-sdk 1.0.22 → 1.0.24

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 (94) hide show
  1. package/Cargo.toml +3 -17
  2. package/README.md +7 -5
  3. package/index.d.ts +22 -21
  4. package/index.node +0 -0
  5. package/lib/asymmetric/RSAWrapper.d.ts +33 -3
  6. package/lib/asymmetric/RSAWrapper.js +33 -3
  7. package/lib/asymmetric/index.d.ts +2 -2
  8. package/lib/asymmetric/index.js +1 -3
  9. package/lib/digital-signature/digital-siganture-sha-512.d.ts +28 -3
  10. package/lib/digital-signature/digital-siganture-sha-512.js +25 -0
  11. package/lib/digital-signature/digital-signature-base.d.ts +3 -3
  12. package/lib/digital-signature/digital-signature-factory.d.ts +5 -0
  13. package/lib/digital-signature/digital-signature-factory.js +5 -0
  14. package/lib/digital-signature/digital-signaturte-sha-256.d.ts +28 -3
  15. package/lib/digital-signature/digital-signaturte-sha-256.js +25 -0
  16. package/lib/digital-signature/index.d.ts +2 -1
  17. package/lib/hashers/hasher-factory.d.ts +5 -0
  18. package/lib/hashers/hasher-factory.js +5 -0
  19. package/lib/hashers/sha-wrapper.d.ts +22 -0
  20. package/lib/hashers/sha-wrapper.js +22 -0
  21. package/lib/hybrid/hybrid-encryption-wrapper.d.ts +12 -0
  22. package/lib/hybrid/hybrid-encryption-wrapper.js +12 -0
  23. package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +7 -2
  24. package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +5 -0
  25. package/lib/index.d.ts +8 -9
  26. package/lib/index.js +22 -29
  27. package/lib/key_exchange/index.d.ts +2 -1
  28. package/lib/key_exchange/x25519.d.ts +15 -3
  29. package/lib/key_exchange/x25519.js +12 -0
  30. package/lib/password-hashers/argon2-wrapper.d.ts +22 -0
  31. package/lib/password-hashers/argon2-wrapper.js +22 -0
  32. package/lib/password-hashers/bcrypt-wrapper.d.ts +22 -0
  33. package/lib/password-hashers/bcrypt-wrapper.js +22 -0
  34. package/lib/password-hashers/password-hasher-factory.d.ts +5 -0
  35. package/lib/password-hashers/password-hasher-factory.js +5 -0
  36. package/lib/password-hashers/scrypt-wrapper.d.ts +22 -0
  37. package/lib/password-hashers/scrypt-wrapper.js +22 -0
  38. package/lib/sponges/ascon-wrapper.d.ts +22 -0
  39. package/lib/sponges/ascon-wrapper.js +22 -0
  40. package/lib/symmetric/aes-wrapper.d.ts +45 -15
  41. package/lib/symmetric/aes-wrapper.js +42 -12
  42. package/lib/symmetric/index.d.ts +2 -1
  43. package/package.json +1 -1
  44. package/src/asymmetric/cas_rsa.rs +13 -59
  45. package/src/digital_signature/sha_256_ed25519.rs +6 -42
  46. package/src/digital_signature/sha_256_rsa.rs +7 -63
  47. package/src/digital_signature/sha_512_ed25519.rs +8 -48
  48. package/src/digital_signature/sha_512_rsa.rs +9 -62
  49. package/src/digital_signature/types.rs +34 -0
  50. package/src/hashers/sha.rs +1 -35
  51. package/src/key_exchange/types.rs +17 -0
  52. package/src/key_exchange/x25519.rs +4 -36
  53. package/src/lib.rs +3 -8
  54. package/src/password_hashers/argon2.rs +4 -44
  55. package/src/password_hashers/bcrypt.rs +4 -31
  56. package/src/password_hashers/scrypt.rs +3 -42
  57. package/src/sponges/ascon_aead.rs +9 -39
  58. package/src/symmetric/aes.rs +12 -88
  59. package/src/symmetric/types.rs +17 -0
  60. package/src-ts/asymmetric/RSAWrapper.ts +38 -5
  61. package/src-ts/asymmetric/index.ts +2 -2
  62. package/src-ts/digital-signature/digital-siganture-sha-512.ts +29 -4
  63. package/src-ts/digital-signature/digital-signature-base.ts +3 -3
  64. package/src-ts/digital-signature/digital-signature-factory.ts +6 -0
  65. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +28 -3
  66. package/src-ts/digital-signature/index.ts +4 -1
  67. package/src-ts/hashers/hasher-factory.ts +5 -0
  68. package/src-ts/hashers/sha-wrapper.ts +22 -0
  69. package/src-ts/hybrid/hybrid-encryption-wrapper.ts +12 -0
  70. package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +7 -2
  71. package/src-ts/index.ts +8 -46
  72. package/src-ts/key_exchange/index.ts +2 -1
  73. package/src-ts/key_exchange/x25519.ts +15 -3
  74. package/src-ts/password-hashers/argon2-wrapper.ts +22 -0
  75. package/src-ts/password-hashers/bcrypt-wrapper.ts +22 -0
  76. package/src-ts/password-hashers/password-hasher-factory.ts +5 -0
  77. package/src-ts/password-hashers/scrypt-wrapper.ts +22 -0
  78. package/src-ts/sponges/ascon-wrapper.ts +22 -0
  79. package/src-ts/symmetric/aes-wrapper.ts +46 -15
  80. package/src-ts/symmetric/index.ts +2 -1
  81. package/test-ts/asymmetric.test.spec.ts +3 -3
  82. package/test-ts/digital-signature.test.spec.ts +5 -5
  83. package/test-ts/insecure-channel.test.spec.ts +5 -5
  84. package/lib/helpers/nonce-generator.d.ts +0 -3
  85. package/lib/helpers/nonce-generator.js +0 -34
  86. package/src/asymmetric/cas_asymmetric_encryption.rs +0 -15
  87. package/src/digital_signature/cas_digital_signature_rsa.rs +0 -27
  88. package/src/hashers/blake2.rs +0 -37
  89. package/src/hashers/cas_hasher.rs +0 -8
  90. package/src/key_exchange/cas_key_exchange.rs +0 -6
  91. package/src/password_hashers/cas_password_hasher.rs +0 -4
  92. package/src/sponges/cas_ascon_aead.rs +0 -6
  93. package/src/symmetric/cas_symmetric_encryption.rs +0 -14
  94. package/src-ts/helpers/nonce-generator.ts +0 -9
@@ -1,8 +1,13 @@
1
- import { RsaKeyPairResult } from "../../..";
1
+ import { CASRSAKeyPairResult } from "../../..";
2
2
  export declare class AESRSAHybridInitializer {
3
3
  aesType: number;
4
4
  aesKey: Array<number>;
5
5
  aesNonce: Array<number>;
6
- rsaKeyPair: RsaKeyPairResult;
6
+ rsaKeyPair: CASRSAKeyPairResult;
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");
package/lib/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { Argon2Wrapper, BCryptWrapper, PasswordHasherFactory, PasswordHasherType, ScryptWrapper } from "./password-hashers/index";
2
- import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
3
- import { X25519Wrapper } from "./key_exchange/index";
4
- import { AESWrapper } from "./symmetric/index";
5
- import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
6
- import { AesRsaHybridEncryptResult, AESRSAHybridInitializer, HybridEncryptionWrapper } from "./hybrid/index";
7
- import { DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType } from "./digital-signature";
8
- import { AsconWrapper } from "./sponges/index";
9
- export { AesRsaHybridEncryptResult, AESRSAHybridInitializer, AESWrapper, Argon2Wrapper, AsconWrapper, BCryptWrapper, DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType, HasherFactory, HasherType, HybridEncryptionWrapper, PasswordHasherFactory, PasswordHasherType, RsaKeyPairResult, RSAWrapper, ScryptWrapper, SHAWrapper, X25519Wrapper, };
1
+ export * from "./password-hashers/index";
2
+ export * from "./hashers/index";
3
+ export * from "./key_exchange/index";
4
+ export * from "./symmetric/index";
5
+ export * from "./asymmetric/index";
6
+ export * from "./hybrid/index";
7
+ export * from "./digital-signature";
8
+ export * from "./sponges/index";
package/lib/index.js CHANGED
@@ -1,31 +1,24 @@
1
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.X25519Wrapper = exports.SHAWrapper = exports.ScryptWrapper = exports.RSAWrapper = exports.RsaKeyPairResult = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.HybridEncryptionWrapper = exports.HasherType = exports.HasherFactory = exports.DigitalSignatureType = exports.DigitalSignatureSHA512Wrapper = exports.DigitalSignatureSHA256Wrapper = exports.DigitalSignatureFactory = exports.BCryptWrapper = exports.AsconWrapper = exports.Argon2Wrapper = exports.AESWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
4
- const index_1 = require("./password-hashers/index");
5
- Object.defineProperty(exports, "Argon2Wrapper", { enumerable: true, get: function () { return index_1.Argon2Wrapper; } });
6
- Object.defineProperty(exports, "BCryptWrapper", { enumerable: true, get: function () { return index_1.BCryptWrapper; } });
7
- Object.defineProperty(exports, "PasswordHasherFactory", { enumerable: true, get: function () { return index_1.PasswordHasherFactory; } });
8
- Object.defineProperty(exports, "PasswordHasherType", { enumerable: true, get: function () { return index_1.PasswordHasherType; } });
9
- Object.defineProperty(exports, "ScryptWrapper", { enumerable: true, get: function () { return index_1.ScryptWrapper; } });
10
- const index_2 = require("./hashers/index");
11
- Object.defineProperty(exports, "HasherFactory", { enumerable: true, get: function () { return index_2.HasherFactory; } });
12
- Object.defineProperty(exports, "HasherType", { enumerable: true, get: function () { return index_2.HasherType; } });
13
- Object.defineProperty(exports, "SHAWrapper", { enumerable: true, get: function () { return index_2.SHAWrapper; } });
14
- const index_3 = require("./key_exchange/index");
15
- Object.defineProperty(exports, "X25519Wrapper", { enumerable: true, get: function () { return index_3.X25519Wrapper; } });
16
- const index_4 = require("./symmetric/index");
17
- Object.defineProperty(exports, "AESWrapper", { enumerable: true, get: function () { return index_4.AESWrapper; } });
18
- const index_5 = require("./asymmetric/index");
19
- Object.defineProperty(exports, "RsaKeyPairResult", { enumerable: true, get: function () { return index_5.RsaKeyPairResult; } });
20
- Object.defineProperty(exports, "RSAWrapper", { enumerable: true, get: function () { return index_5.RSAWrapper; } });
21
- const index_6 = require("./hybrid/index");
22
- Object.defineProperty(exports, "AesRsaHybridEncryptResult", { enumerable: true, get: function () { return index_6.AesRsaHybridEncryptResult; } });
23
- Object.defineProperty(exports, "AESRSAHybridInitializer", { enumerable: true, get: function () { return index_6.AESRSAHybridInitializer; } });
24
- Object.defineProperty(exports, "HybridEncryptionWrapper", { enumerable: true, get: function () { return index_6.HybridEncryptionWrapper; } });
25
- const digital_signature_1 = require("./digital-signature");
26
- Object.defineProperty(exports, "DigitalSignatureFactory", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureFactory; } });
27
- Object.defineProperty(exports, "DigitalSignatureSHA256Wrapper", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureSHA256Wrapper; } });
28
- Object.defineProperty(exports, "DigitalSignatureSHA512Wrapper", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureSHA512Wrapper; } });
29
- Object.defineProperty(exports, "DigitalSignatureType", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureType; } });
30
- const index_7 = require("./sponges/index");
31
- Object.defineProperty(exports, "AsconWrapper", { enumerable: true, get: function () { return index_7.AsconWrapper; } });
17
+ __exportStar(require("./password-hashers/index"), exports);
18
+ __exportStar(require("./hashers/index"), exports);
19
+ __exportStar(require("./key_exchange/index"), exports);
20
+ __exportStar(require("./symmetric/index"), exports);
21
+ __exportStar(require("./asymmetric/index"), exports);
22
+ __exportStar(require("./hybrid/index"), exports);
23
+ __exportStar(require("./digital-signature"), exports);
24
+ __exportStar(require("./sponges/index"), exports);
@@ -1,2 +1,3 @@
1
+ import { CASx25519SecretPublicKeyResult } from "../../index";
1
2
  import { X25519Wrapper } from "./x25519";
2
- export { X25519Wrapper };
3
+ export { X25519Wrapper, CASx25519SecretPublicKeyResult };
@@ -1,5 +1,17 @@
1
- import { X25519SecretPublicKeyResult } from "../../index";
1
+ import { CASx25519SecretPublicKeyResult } from "../../index";
2
2
  export declare class X25519Wrapper {
3
- generateSecretAndPublicKey(): X25519SecretPublicKeyResult;
4
- generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>): number[];
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
+ */
8
+ generateSecretAndPublicKey(): CASx25519SecretPublicKeyResult;
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
  }
@@ -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
- 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
- */
1
+ import { CASAesKeyFromX25519SharedSecret } from "../../index";
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>;
30
- aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
31
- aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
50
+ /**
51
+ * Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
52
+ * @param shared_secret
53
+ * @returns
54
+ */
55
+ aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret;
56
+ /**
57
+ * Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
58
+ * @param shared_secret
59
+ * @returns
60
+ */
61
+ aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret;
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
  }
@@ -1,2 +1,3 @@
1
+ import { CASAesKeyFromX25519SharedSecret } from "../../index";
1
2
  import { AESWrapper } from "./aes-wrapper";
2
- export { AESWrapper };
3
+ export { AESWrapper, CASAesKeyFromX25519SharedSecret };
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.24",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",