cas-typescript-sdk 1.0.19 → 1.0.21

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.
package/docs/EXAMPLES.md CHANGED
@@ -11,6 +11,105 @@ const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
11
11
  const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
12
12
  ```
13
13
 
14
+ ### Asymmetric
15
+ -RSA
16
+ ```typescript
17
+ const rsaWrapper: RSAWrapper = new RSAWrapper();
18
+ const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
19
+ const tohashed: string = "This is my array to encrypt";
20
+ const encoder = new TextEncoder();
21
+ const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
22
+ const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
23
+ const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
24
+ ```
25
+
26
+
27
+ ### Digital Signature
28
+ -ED25519 SHA
29
+ ```typescript
30
+ const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
31
+ const toHash: string = "This is my array to encrypt";
32
+ const encoder = new TextEncoder();
33
+ const toHashBytes: Array<number> = Array.from(encoder.encode(toHash));
34
+ const dsResult = shaDsWrapper.createED25519(toHashBytes);
35
+ const verify = shaDsWrapper.verifyED25519(dsResult.publicKey, toHashBytes, dsResult.signature);
36
+ ```
37
+
38
+ -RSA SHA
39
+ ```typescript
40
+ const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
41
+ const tohashed: string = "This is my array to encrypt";
42
+ const notOriginal: string = "This is not a fun time";
43
+ const encoder = new TextEncoder();
44
+ const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
45
+ const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
46
+ const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
47
+ const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
48
+ ```
49
+
50
+
51
+ ### Hashers
52
+ -SHA3 512
53
+ ```typescript
54
+ const wrapper = new SHAWrapper();
55
+ const tohashed: string = "This is my array to hash";
56
+ const encoder = new TextEncoder();
57
+ const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
58
+ const hashed = wrapper.hash512(tohashBytes);
59
+ ```
60
+
61
+ -SHA3 256
62
+ ```typescript
63
+ const wrapper = new SHAWrapper();
64
+ const tohashed: string = "This is my array to hash";
65
+ const encoder = new TextEncoder();
66
+ const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
67
+ const hashed = wrapper.hash256(tohashBytes);
68
+ ```
69
+
70
+ ### Hybrid Encryption
71
+ -AES/RSA Encryption
72
+ ```typescript
73
+ const hybridWrapper = new HybridEncryptionWrapper();
74
+ let initalizer = new AESRSAHybridInitializer(128, 4096);
75
+ const tohashed: string = "This is my encrypt text for rsa hybrid";
76
+ const encoder = new TextEncoder();
77
+ const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
78
+ let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
79
+ let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
80
+ ```
81
+
82
+ ### Key Exchange
83
+ -X25519
84
+ ```typescript
85
+ const wrapper = new X25519Wrapper();
86
+ const alice = wrapper.generateSecretAndPublicKey();
87
+ const bob = wrapper.generateSecretAndPublicKey();
88
+
89
+ const alice_shared_secret = wrapper.generateSharedSecret(
90
+ alice.secretKey,
91
+ bob.publicKey,
92
+ );
93
+ const bob_shared_secret = wrapper.generateSharedSecret(
94
+ bob.secretKey,
95
+ alice.publicKey,
96
+ );
97
+
98
+ var result = areEqual(alice_shared_secret, bob_shared_secret);
99
+ ```
100
+
101
+ ### Sponges
102
+ -Ascon 128
103
+ ```typescript
104
+ const wrapper: AsconWrapper = new AsconWrapper();
105
+ const key: Array<number> = wrapper.ascon128Key();
106
+ const nonce: Array<number> = wrapper.ascon128Nonce();
107
+ const tohashed: string = "This is my array to encrypt";
108
+ const encoder = new TextEncoder();
109
+ const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
110
+ const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
111
+ const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
112
+ ```
14
113
 
15
114
  ### Passwords
16
115
  - BCrypt
package/index.node CHANGED
Binary file
@@ -1,6 +1,26 @@
1
1
  import { AesKeyFromX25519SharedSecret } from "../../index";
2
+ /**
3
+ * @description A wrapper class that contains methods to construct keys, nonces, and methods to encrypt and decrypt with AES-128-GCM and AES-256-GCM
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const nonce = aesWrapper.generateAESNonce();
8
+ const key = aesWrapper.aes128Key();
9
+ const textEncoder = new TextEncoder();
10
+ const array = Array.from(textEncoder.encode("Hello World"));
11
+ const encrypted = aesWrapper.aes128Encrypt(key, nonce, array);
12
+ * ```
13
+ */
2
14
  export declare class AESWrapper {
15
+ /**
16
+ * @description Generates a 128 bit AES key
17
+ * @returns returns a 128 bit AES key
18
+ */
3
19
  aes128Key(): Array<number>;
20
+ /**
21
+ * @description Generates a 256 bit AES key
22
+ * @returns returns a 256 bit AES key
23
+ */
4
24
  aes256Key(): Array<number>;
5
25
  generateAESNonce(): Array<number>;
6
26
  aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
@@ -2,10 +2,30 @@
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
+ */
5
17
  class AESWrapper {
18
+ /**
19
+ * @description Generates a 128 bit AES key
20
+ * @returns returns a 128 bit AES key
21
+ */
6
22
  aes128Key() {
7
23
  return (0, index_1.aes128Key)();
8
24
  }
25
+ /**
26
+ * @description Generates a 256 bit AES key
27
+ * @returns returns a 256 bit AES key
28
+ */
9
29
  aes256Key() {
10
30
  return (0, index_1.aes256Key)();
11
31
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  {
3
3
  "name": "cas-typescript-sdk",
4
- "version": "1.0.19",
4
+ "version": "1.0.21",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -11,11 +11,32 @@ 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
  export class AESWrapper {
27
+
28
+ /**
29
+ * @description Generates a 128 bit AES key
30
+ * @returns returns a 128 bit AES key
31
+ */
15
32
  public aes128Key(): Array<number> {
16
33
  return aes128Key();
17
34
  }
18
35
 
36
+ /**
37
+ * @description Generates a 256 bit AES key
38
+ * @returns returns a 256 bit AES key
39
+ */
19
40
  public aes256Key(): Array<number> {
20
41
  return aes256Key();
21
42
  }