cas-typescript-sdk 1.0.21 → 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 (59) hide show
  1. package/Cargo.toml +1 -0
  2. package/README.md +7 -5
  3. package/index.d.ts +6 -0
  4. package/index.node +0 -0
  5. package/lib/asymmetric/RSAWrapper.d.ts +31 -1
  6. package/lib/asymmetric/RSAWrapper.js +33 -3
  7. package/lib/digital-signature/digital-siganture-sha-512.d.ts +25 -0
  8. package/lib/digital-signature/digital-siganture-sha-512.js +25 -0
  9. package/lib/digital-signature/digital-signature-factory.d.ts +5 -0
  10. package/lib/digital-signature/digital-signature-factory.js +5 -0
  11. package/lib/digital-signature/digital-signaturte-sha-256.d.ts +25 -0
  12. package/lib/digital-signature/digital-signaturte-sha-256.js +25 -0
  13. package/lib/hashers/hasher-factory.d.ts +5 -0
  14. package/lib/hashers/hasher-factory.js +5 -0
  15. package/lib/hashers/sha-wrapper.d.ts +22 -0
  16. package/lib/hashers/sha-wrapper.js +22 -0
  17. package/lib/hybrid/hybrid-encryption-wrapper.d.ts +12 -0
  18. package/lib/hybrid/hybrid-encryption-wrapper.js +12 -0
  19. package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +5 -0
  20. package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +5 -0
  21. package/lib/key_exchange/x25519.d.ts +13 -1
  22. package/lib/key_exchange/x25519.js +12 -0
  23. package/lib/password-hashers/argon2-wrapper.d.ts +24 -0
  24. package/lib/password-hashers/argon2-wrapper.js +37 -0
  25. package/lib/password-hashers/bcrypt-wrapper.d.ts +24 -0
  26. package/lib/password-hashers/bcrypt-wrapper.js +34 -0
  27. package/lib/password-hashers/password-hasher-base.d.ts +2 -0
  28. package/lib/password-hashers/password-hasher-factory.d.ts +5 -0
  29. package/lib/password-hashers/password-hasher-factory.js +5 -0
  30. package/lib/password-hashers/scrypt-wrapper.d.ts +24 -0
  31. package/lib/password-hashers/scrypt-wrapper.js +34 -0
  32. package/lib/sponges/ascon-wrapper.d.ts +22 -0
  33. package/lib/sponges/ascon-wrapper.js +22 -0
  34. package/lib/symmetric/aes-wrapper.d.ts +42 -12
  35. package/lib/symmetric/aes-wrapper.js +42 -12
  36. package/package.json +1 -1
  37. package/src/password_hashers/argon2.rs +40 -1
  38. package/src/password_hashers/bcrypt.rs +39 -0
  39. package/src/password_hashers/scrypt.rs +39 -0
  40. package/src-ts/asymmetric/RSAWrapper.ts +36 -3
  41. package/src-ts/digital-signature/digital-siganture-sha-512.ts +26 -1
  42. package/src-ts/digital-signature/digital-signature-factory.ts +6 -0
  43. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +25 -0
  44. package/src-ts/hashers/hasher-factory.ts +5 -0
  45. package/src-ts/hashers/sha-wrapper.ts +22 -0
  46. package/src-ts/hybrid/hybrid-encryption-wrapper.ts +12 -0
  47. package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +5 -0
  48. package/src-ts/key_exchange/x25519.ts +13 -1
  49. package/src-ts/password-hashers/argon2-wrapper.ts +46 -4
  50. package/src-ts/password-hashers/bcrypt-wrapper.ts +40 -1
  51. package/src-ts/password-hashers/password-hasher-base.ts +2 -0
  52. package/src-ts/password-hashers/password-hasher-factory.ts +5 -0
  53. package/src-ts/password-hashers/scrypt-wrapper.ts +54 -15
  54. package/src-ts/sponges/ascon-wrapper.ts +22 -0
  55. package/src-ts/symmetric/aes-wrapper.ts +43 -12
  56. package/test-ts/password-hasher.test.spec.ts +53 -3
  57. package/lib/helpers/nonce-generator.d.ts +0 -3
  58. package/lib/helpers/nonce-generator.js +0 -34
  59. package/src-ts/helpers/nonce-generator.ts +0 -9
@@ -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");
@@ -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
  }
@@ -1,17 +1,59 @@
1
- import {argon2Hash, argon2Verify} from "./../../index";
2
- import { IPasswordHasherBase} from "./password-hasher-base";
1
+ import { argon2Hash, argon2HashThreadPool, argon2Verify, argon2VerifyThreadpool } from "./../../index";
2
+ import { IPasswordHasherBase } from "./password-hasher-base";
3
3
 
4
4
  export class Argon2Wrapper implements IPasswordHasherBase {
5
+
6
+ /**
7
+ * Verifies a password with Argon2 on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
12
+ verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
13
+ if (!hashedPassword) {
14
+ throw new Error("You must provide a password to verify with Argon2");
15
+ }
16
+ if (!passwordToCheck) {
17
+ throw new Error("You must provide a password to check to verify with Argon2");
18
+ }
19
+ return argon2VerifyThreadpool(hashedPassword, passwordToCheck);
20
+ }
21
+
22
+ /**
23
+ * Hashes a password with Argon2 on the threadpool.
24
+ * @param password
25
+ * @returns string
26
+ */
27
+ public hashPasswordThreadPool(password: string): string {
28
+ if (!password) {
29
+ throw new Error("You must provide a password to hash with Argon2");
30
+ }
31
+ return argon2HashThreadPool(password);
32
+ }
33
+
34
+ /**
35
+ * Hashes a password with Argon2
36
+ * @param password
37
+ * @returns string
38
+ */
5
39
  public hashPassword(password: string): string {
6
- if (!password){
40
+ if (!password) {
7
41
  throw new Error("You must provide a password to hash with Argon2");
8
42
  }
9
43
  return argon2Hash(password);
10
44
  }
11
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
+ */
12
52
  public verify(hashedPassword: string, passwordToVerify: string): boolean {
13
53
  if (!hashedPassword || !passwordToVerify) {
14
- throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
54
+ throw new Error(
55
+ "You must provide a hashed password and a plaintext password to verify with Argon2",
56
+ );
15
57
  }
16
58
  return argon2Verify(hashedPassword, passwordToVerify);
17
59
  }
@@ -1,7 +1,40 @@
1
1
  import { IPasswordHasherBase } from "./password-hasher-base";
2
- import { bcryptHash, bcryptVerify } from "./../../index";
2
+ import { bcryptHash, bcryptHashThreadpool, bcryptVerify, bcryptVerifyThreadpool } from "./../../index";
3
3
 
4
4
  export class BCryptWrapper implements IPasswordHasherBase {
5
+
6
+ /**
7
+ * Verifies a password with BCrypt on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
12
+ verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
13
+ if (!hashedPassword || !passwordToCheck) {
14
+ throw new Error(
15
+ "You must provide a hashed password and a plaintext password to verify with Argon2",
16
+ );
17
+ }
18
+ return bcryptVerifyThreadpool(hashedPassword, passwordToCheck);
19
+ }
20
+
21
+ /**
22
+ * Hashes a password with BCrypt on the threadpool.
23
+ * @param password
24
+ * @returns string
25
+ */
26
+ public hashPasswordThreadPool(password: string): string {
27
+ if (!password) {
28
+ throw new Error("You must provide a password to hash with Argon2");
29
+ }
30
+ return bcryptHashThreadpool(password);
31
+ }
32
+
33
+ /**
34
+ * Hashes a password with BCrypt
35
+ * @param password
36
+ * @returns string
37
+ */
5
38
  public hashPassword(password: string): string {
6
39
  if (!password) {
7
40
  throw new Error("You must provide a password to hash with Argon2");
@@ -9,6 +42,12 @@ export class BCryptWrapper implements IPasswordHasherBase {
9
42
  return bcryptHash(password);
10
43
  }
11
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
+ */
12
51
  public verify(
13
52
  hashedPassword: string,
14
53
  passwordToVerify: string,
@@ -1,4 +1,6 @@
1
1
  export interface IPasswordHasherBase {
2
2
  hashPassword(password: string): string;
3
3
  verify(hashedPassword: string, passwordToVerify: string): boolean;
4
+ hashPasswordThreadPool(password: string): string;
5
+ verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
4
6
  }
@@ -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();
@@ -1,20 +1,59 @@
1
- import { scryptHash, scryptVerify } from "../../index";
1
+ import { scryptHash, scryptHashThreadpool, scryptVerify, scryptVerifyThreadpool } from "../../index";
2
2
  import { IPasswordHasherBase } from "./password-hasher-base";
3
3
 
4
4
  export class ScryptWrapper implements IPasswordHasherBase {
5
5
 
6
- public hashPassword(password: string): string {
7
- if (!password){
8
- throw new Error("You must provide a password to hash with Scrypt");
9
- }
10
- return scryptHash(password);
11
- }
12
-
13
- public verify(hashedPassword: string, passwordToVerify: string): boolean {
14
- if (!hashedPassword || !passwordToVerify) {
15
- throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
16
- }
17
- return scryptVerify(hashedPassword, passwordToVerify);
18
- }
6
+ /**
7
+ * Verifies a password with SCrypt on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
12
+ verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
13
+ if (!hashedPassword || !passwordToCheck) {
14
+ throw new Error(
15
+ "You must provide a hashed password and a plaintext password to verify with Scrypt",
16
+ );
17
+ }
18
+ return scryptVerifyThreadpool(hashedPassword, passwordToCheck);
19
+ }
19
20
 
20
- }
21
+ /**
22
+ * Hashes a password with SCrypt on the threadpool.
23
+ * @param password
24
+ * @returns string
25
+ */
26
+ hashPasswordThreadPool(password: string): string {
27
+ if (!password) {
28
+ throw new Error("You must provide a password to hash with Scrypt");
29
+ }
30
+ return scryptHashThreadpool(password);
31
+ }
32
+
33
+ /**
34
+ * Hashes a password with SCrypt
35
+ * @param password
36
+ * @returns string
37
+ */
38
+ public hashPassword(password: string): string {
39
+ if (!password) {
40
+ throw new Error("You must provide a password to hash with Scrypt");
41
+ }
42
+ return scryptHash(password);
43
+ }
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
+ */
51
+ public verify(hashedPassword: string, passwordToVerify: string): boolean {
52
+ if (!hashedPassword || !passwordToVerify) {
53
+ throw new Error(
54
+ "You must provide a hashed password and a plaintext password to verify with Scrypt",
55
+ );
56
+ }
57
+ return scryptVerify(hashedPassword, passwordToVerify);
58
+ }
59
+ }
@@ -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
  }