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
@@ -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,
@@ -1,4 +1,4 @@
1
- import { RsaKeyPairResult } from "../../..";
1
+ import { CASRSAKeyPairResult } from "../../..";
2
2
  import { RSAWrapper } from "../../asymmetric";
3
3
  import { AESWrapper } from "../../symmetric";
4
4
 
@@ -6,8 +6,13 @@ export class AESRSAHybridInitializer {
6
6
  public aesType: number;
7
7
  public aesKey: Array<number>;
8
8
  public aesNonce: Array<number>;
9
- public rsaKeyPair: RsaKeyPairResult;
9
+ public rsaKeyPair: CASRSAKeyPairResult;
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");
package/src-ts/index.ts CHANGED
@@ -1,46 +1,8 @@
1
- import {
2
- Argon2Wrapper,
3
- BCryptWrapper,
4
- PasswordHasherFactory,
5
- PasswordHasherType,
6
- ScryptWrapper,
7
- } from "./password-hashers/index";
8
- import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
9
- import { X25519Wrapper } from "./key_exchange/index";
10
- import { AESWrapper } from "./symmetric/index";
11
- import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
12
- import {
13
- AesRsaHybridEncryptResult,
14
- AESRSAHybridInitializer,
15
- HybridEncryptionWrapper,
16
- } from "./hybrid/index";
17
- import {
18
- DigitalSignatureFactory,
19
- DigitalSignatureSHA256Wrapper,
20
- DigitalSignatureSHA512Wrapper,
21
- DigitalSignatureType,
22
- } from "./digital-signature";
23
- import { AsconWrapper } from "./sponges/index";
24
-
25
- export {
26
- AesRsaHybridEncryptResult,
27
- AESRSAHybridInitializer,
28
- AESWrapper,
29
- Argon2Wrapper,
30
- AsconWrapper,
31
- BCryptWrapper,
32
- DigitalSignatureFactory,
33
- DigitalSignatureSHA256Wrapper,
34
- DigitalSignatureSHA512Wrapper,
35
- DigitalSignatureType,
36
- HasherFactory,
37
- HasherType,
38
- HybridEncryptionWrapper,
39
- PasswordHasherFactory,
40
- PasswordHasherType,
41
- RsaKeyPairResult,
42
- RSAWrapper,
43
- ScryptWrapper,
44
- SHAWrapper,
45
- X25519Wrapper,
46
- };
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";
@@ -1,3 +1,4 @@
1
+ import { CASx25519SecretPublicKeyResult } from "../../index";
1
2
  import { X25519Wrapper } from "./x25519";
2
3
 
3
- export { X25519Wrapper };
4
+ export { X25519Wrapper, CASx25519SecretPublicKeyResult };
@@ -1,11 +1,23 @@
1
- import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey, X25519SecretPublicKeyResult } from "../../index"
1
+ import { CASx25519SecretPublicKeyResult, x25519DiffieHellman, x25519GenerateSecretAndPublicKey } from "../../index"
2
2
 
3
3
  export class X25519Wrapper {
4
- public generateSecretAndPublicKey(): X25519SecretPublicKeyResult {
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
+ */
9
+ public generateSecretAndPublicKey(): CASx25519SecretPublicKeyResult {
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>,
@@ -1,5 +1,5 @@
1
1
  import {
2
- AesKeyFromX25519SharedSecret,
2
+ CASAesKeyFromX25519SharedSecret,
3
3
  aes128Decrypt,
4
4
  aes128Encrypt,
5
5
  aes128Key,
@@ -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,31 +30,73 @@ 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
 
64
- public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
85
+ /**
86
+ * Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
87
+ * @param shared_secret
88
+ * @returns
89
+ */
90
+ public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret {
65
91
  return aes256KeyFromX25519SharedSecret(shared_secret);
66
92
  }
67
93
 
68
- public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
94
+ /**
95
+ * Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
96
+ * @param shared_secret
97
+ * @returns
98
+ */
99
+ public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret {
69
100
  return aes128KeyFromX25519SharedSecret(shared_secret);
70
101
  }
71
102
  }
@@ -1,3 +1,4 @@
1
+ import { CASAesKeyFromX25519SharedSecret } from "../../index";
1
2
  import { AESWrapper } from "./aes-wrapper";
2
3
 
3
- export { AESWrapper };
4
+ export { AESWrapper, CASAesKeyFromX25519SharedSecret };
@@ -1,11 +1,11 @@
1
1
  import { assert } from "chai";
2
- import { RSAWrapper, RsaKeyPairResult } from "..";
2
+ import { CASRSAKeyPairResult, RSAWrapper } from "..";
3
3
  import { areEqual } from "./helpers/array";
4
4
 
5
5
  describe("Asymmetric Tests", () => {
6
6
  it("RSA 4096 encrypt and decrypt equals", () => {
7
7
  const rsaWrapper: RSAWrapper = new RSAWrapper();
8
- const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
8
+ const keys: CASRSAKeyPairResult = rsaWrapper.generateKeys(4096);
9
9
  const tohashed: string = "This is my array to encrypt";
10
10
  const encoder = new TextEncoder();
11
11
  const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
@@ -17,7 +17,7 @@ describe("Asymmetric Tests", () => {
17
17
 
18
18
  it("RSA 2048 Sign and Verify", () => {
19
19
  const rsaWrapper = new RSAWrapper();
20
- const keys: RsaKeyPairResult = rsaWrapper.generateKeys(2048);
20
+ const keys: CASRSAKeyPairResult = rsaWrapper.generateKeys(2048);
21
21
  const tohashed: string = "This is my encrypt";
22
22
  const encoder = new TextEncoder();
23
23
  const toSignBytes: Array<number> = Array.from(encoder.encode(tohashed));
@@ -1,6 +1,6 @@
1
1
  import { assert } from "chai";
2
2
  import { DigitalSignatureFactory, DigitalSignatureType } from "../src-ts/digital-signature/digital-signature-factory";
3
- import { RSADigitalSignatureResult } from "../index";
3
+ import { CASRSADigitalSignatureResult } from "../index";
4
4
 
5
5
  describe("Digital Signature", () => {
6
6
  it("SHA 512 RSA pass", () => {
@@ -8,7 +8,7 @@ describe("Digital Signature", () => {
8
8
  const tohashed: string = "This is my array to encrypt";
9
9
  const encoder = new TextEncoder();
10
10
  const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
11
- const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
11
+ const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
12
12
  const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
13
13
  assert.equal(verify, true);
14
14
  });
@@ -20,7 +20,7 @@ describe("Digital Signature", () => {
20
20
  const encoder = new TextEncoder();
21
21
  const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
22
22
  const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
23
- const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
23
+ const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
24
24
  const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
25
25
  assert.equal(verify, false);
26
26
  });
@@ -30,7 +30,7 @@ describe("Digital Signature", () => {
30
30
  const tohashed: string = "This is my array to encrypt";
31
31
  const encoder = new TextEncoder();
32
32
  const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
33
- const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
33
+ const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
34
34
  const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
35
35
  assert.equal(verify, true);
36
36
  });
@@ -42,7 +42,7 @@ describe("Digital Signature", () => {
42
42
  const encoder = new TextEncoder();
43
43
  const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
44
44
  const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
45
- const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
45
+ const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
46
46
  const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
47
47
  assert.equal(verify, false);
48
48
  });
@@ -1,6 +1,6 @@
1
1
  import {AESWrapper} from "../src-ts/symmetric/index";
2
2
  import {X25519Wrapper} from "../src-ts/key_exchange/index";
3
- import {X25519SecretPublicKeyResult} from "../index";
3
+ import {CASx25519SecretPublicKeyResult} from "../index";
4
4
  import { areEqual } from "./helpers/array";
5
5
  import { assert } from "chai";
6
6
 
@@ -8,8 +8,8 @@ describe("Insecure Channel Tests", () => {
8
8
  it("AES256-GBC Diffie Hellman X25519", () => {
9
9
  const aesWrapper = new AESWrapper();
10
10
  const x25519Wrapper = new X25519Wrapper();
11
- const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
12
- const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
11
+ const alice_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
12
+ const bob_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
13
13
 
14
14
  const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
15
15
  const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
@@ -30,8 +30,8 @@ describe("Insecure Channel Tests", () => {
30
30
  it("AES128-GBC Diffie Hellman X25519", () => {
31
31
  const aesWrapper = new AESWrapper();
32
32
  const x25519Wrapper = new X25519Wrapper();
33
- const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
34
- const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
33
+ const alice_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
34
+ const bob_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
35
35
 
36
36
  const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
37
37
  const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
@@ -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,15 +0,0 @@
1
- use napi_derive::napi;
2
-
3
- #[napi(constructor)]
4
- pub struct RSAKeyPairResult {
5
- pub private_key: String,
6
- pub public_key: String,
7
- }
8
-
9
- pub trait CASRSAEncryption {
10
- fn generate_rsa_keys(key_size: u32) -> RSAKeyPairResult;
11
- fn encrypt_plaintext(public_key: String, plaintext: Vec<u8>) -> Vec<u8>;
12
- fn decrypt_ciphertext(private_key: String, ciphertext: Vec<u8>) -> Vec<u8>;
13
- fn sign(private_key: String, hash: Vec<u8>) -> Vec<u8>;
14
- fn verify(public_key: String, hash: Vec<u8>, signed_text: Vec<u8>) -> bool;
15
- }