cas-typescript-sdk 1.0.14 → 1.0.16

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 (95) hide show
  1. package/.github/workflows/main-pr-linux.yml +28 -0
  2. package/.github/workflows/main-pr-windows.yml +28 -0
  3. package/.github/workflows/main-publish.yml +32 -0
  4. package/Cargo.toml +8 -1
  5. package/README.md +3 -1
  6. package/build.rs +5 -5
  7. package/docs/EXAMPLES.md +39 -0
  8. package/index.d.ts +19 -0
  9. package/index.node +0 -0
  10. package/lib/digital-signature/digital-siganture-sha-512.d.ts +6 -0
  11. package/lib/digital-signature/digital-siganture-sha-512.js +28 -0
  12. package/lib/digital-signature/digital-signature-base.d.ts +5 -0
  13. package/lib/digital-signature/digital-signature-factory.d.ts +8 -0
  14. package/lib/digital-signature/digital-signature-factory.js +22 -0
  15. package/lib/digital-signature/digital-signaturte-sha-256.d.ts +6 -0
  16. package/lib/digital-signature/digital-signaturte-sha-256.js +28 -0
  17. package/lib/digital-signature/index.d.ts +4 -0
  18. package/lib/digital-signature/index.js +8 -0
  19. package/lib/hybrid/hybrid-encryption-wrapper.d.ts +9 -0
  20. package/lib/hybrid/hybrid-encryption-wrapper.js +30 -0
  21. package/lib/hybrid/index.d.ts +4 -0
  22. package/lib/hybrid/index.js +9 -0
  23. package/lib/hybrid/types/aes-rsa-hybird-encrypt-result.d.ts +7 -0
  24. package/lib/hybrid/types/aes-rsa-hybird-encrypt-result.js +16 -0
  25. package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +8 -0
  26. package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +25 -0
  27. package/lib/index.d.ts +3 -2
  28. package/lib/index.js +8 -4
  29. package/package.json +41 -39
  30. package/src/asymmetric/cas_asymmetric_encryption.rs +15 -15
  31. package/src/asymmetric/cas_rsa.rs +88 -80
  32. package/src/digital_signature/cas_digital_signature_rsa.rs +27 -0
  33. package/src/digital_signature/sha_256_rsa.rs +96 -0
  34. package/src/digital_signature/sha_512_ed25519.rs +75 -0
  35. package/src/digital_signature/sha_512_rsa.rs +93 -0
  36. package/src/hashers/blake2.rs +37 -39
  37. package/src/hashers/cas_hasher.rs +8 -8
  38. package/src/hashers/sha.rs +102 -103
  39. package/src/key_exchange/cas_key_exchange.rs +6 -6
  40. package/src/key_exchange/x25519.rs +57 -57
  41. package/src/lib.rs +34 -27
  42. package/src/password_hashers/argon2.rs +65 -64
  43. package/src/password_hashers/bcrypt.rs +50 -51
  44. package/src/password_hashers/cas_password_hasher.rs +4 -4
  45. package/src/password_hashers/scrypt.rs +61 -56
  46. package/src/symmetric/aes.rs +155 -151
  47. package/src/symmetric/cas_symmetric_encryption.rs +14 -14
  48. package/src-ts/asymmetric/RSAWrapper.ts +53 -53
  49. package/src-ts/asymmetric/index.ts +3 -3
  50. package/src-ts/digital-signature/digital-siganture-sha-512.ts +28 -0
  51. package/src-ts/digital-signature/digital-signature-base.ts +6 -0
  52. package/src-ts/digital-signature/digital-signature-factory.ts +19 -0
  53. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +28 -0
  54. package/src-ts/digital-signature/index.ts +4 -0
  55. package/src-ts/global.d.ts +1 -1
  56. package/src-ts/hashers/hasher-base.ts +5 -5
  57. package/src-ts/hashers/hasher-factory.ts +11 -11
  58. package/src-ts/hashers/hasher-type.ts +2 -2
  59. package/src-ts/hashers/index.ts +5 -5
  60. package/src-ts/hashers/sha-wrapper.ts +37 -37
  61. package/src-ts/helpers/nonce-generator.ts +8 -8
  62. package/src-ts/hybrid/hybrid-encryption-wrapper.ts +64 -0
  63. package/src-ts/hybrid/index.ts +9 -0
  64. package/src-ts/hybrid/types/aes-rsa-hybird-encrypt-result.ts +13 -0
  65. package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +24 -0
  66. package/src-ts/index.ts +34 -26
  67. package/src-ts/key_exchange/index.ts +3 -3
  68. package/src-ts/key_exchange/x25519.ts +10 -10
  69. package/src-ts/password-hashers/argon2-wrapper.ts +18 -18
  70. package/src-ts/password-hashers/bcrypt-wrapper.ts +23 -23
  71. package/src-ts/password-hashers/index.ts +14 -14
  72. package/src-ts/password-hashers/password-hasher-base.ts +3 -3
  73. package/src-ts/password-hashers/password-hasher-factory.ts +20 -20
  74. package/src-ts/password-hashers/password-hasher-type.ts +4 -4
  75. package/src-ts/password-hashers/scrypt-wrapper.ts +19 -19
  76. package/src-ts/symmetric/aes-wrapper.ts +50 -50
  77. package/src-ts/symmetric/index.ts +3 -3
  78. package/test-ts/asymmetric.test.spec.ts +27 -27
  79. package/test-ts/digital-signature.test.spec.ts +49 -0
  80. package/test-ts/hasher.test.spec.ts +70 -70
  81. package/test-ts/helpers/array.ts +9 -9
  82. package/test-ts/hybrid.test.spec.ts +33 -0
  83. package/test-ts/insecure-channel.test.spec.ts +50 -50
  84. package/test-ts/key-exchange-test.spec.ts +23 -23
  85. package/test-ts/password-hasher-test.spec.ts +102 -102
  86. package/test-ts/symmetric.test.spec.ts +31 -31
  87. package/tsconfig.json +21 -21
  88. package/lib/cas_core_lib.dll +0 -0
  89. package/lib/hashers/IHasherBase.d.ts +0 -6
  90. package/lib/hashers/SHAWrapper.d.ts +0 -7
  91. package/lib/hashers/SHAWrapper.js +0 -37
  92. package/lib/libcas_core_lib.so +0 -0
  93. package/lib/password-hashers/types/argon2-hash-thread-result.d.ts +0 -3
  94. package/lib/password-hashers/types/argon2-hash-thread-result.js +0 -11
  95. /package/lib/{hashers/IHasherBase.js → digital-signature/digital-signature-base.js} +0 -0
@@ -0,0 +1,28 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Linux Build / Test
5
+
6
+ on:
7
+ pull_request:
8
+ branches: [ "main" ]
9
+
10
+ jobs:
11
+ build:
12
+
13
+ runs-on: ubuntu-latest
14
+
15
+ strategy:
16
+ matrix:
17
+ node-version: [20.x]
18
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
+
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Use Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v3
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ cache: 'npm'
27
+ - run: npm ci
28
+ - run: npm test
@@ -0,0 +1,28 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Windows Build / Test
5
+
6
+ on:
7
+ pull_request:
8
+ branches: [ "main" ]
9
+
10
+ jobs:
11
+ build:
12
+
13
+ runs-on: windows-latest
14
+
15
+ strategy:
16
+ matrix:
17
+ node-version: [20.x]
18
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
+
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Use Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v3
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ cache: 'npm'
27
+ - run: npm ci
28
+ - run: npm test
@@ -0,0 +1,32 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+
10
+ jobs:
11
+ build:
12
+
13
+ runs-on: ubuntu-latest
14
+
15
+ strategy:
16
+ matrix:
17
+ node-version: [20.x]
18
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
+
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Use Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v3
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ registry-url: 'https://registry.npmjs.org'
27
+ cache: 'npm'
28
+ - run: npm ci
29
+ - run: npm test
30
+ - run: npm publish
31
+ env:
32
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/Cargo.toml CHANGED
@@ -19,7 +19,14 @@ rand_chacha = "0.3.1"
19
19
  rsa = "0.9.6"
20
20
  scrypt = "0.11.0"
21
21
  sha3 = "0.10.8"
22
- x25519-dalek = {version = "2.0.0", features = ["static_secrets"] }
22
+ x25519-dalek = {version = "2.0.0", features = ["static_secrets"]}
23
+ rand_07 = { package = "rand", version = "0.7.0" }
24
+
25
+ [profile.dev.package.num-bigint-dig]
26
+ opt-level = 3
27
+
28
+ [dependencies.ed25519-dalek]
29
+ version = "1"
23
30
 
24
31
  [build-dependencies]
25
32
  napi-build = "1"
package/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # eas-typescript-sdk
1
+ # cas-typescript-sdk
2
2
 
3
3
  Ever wanted all of your most useful cryptograpihc operations in one module and not have to surf documentation for various packages?
4
4
  CAS is here to provide a unified development experience as an abstract layer to the RustCrypto and Dalek-Cryptography suite of algorithms.
5
5
  The official NPM page can be found [here](https://www.npmjs.com/package/cas-typescript-sdk).
6
6
 
7
+ ## [Examples](./docs/EXAMPLES.md)
8
+
7
9
  ## Consuming Library Documentation
8
10
  **Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
9
11
 
package/build.rs CHANGED
@@ -1,5 +1,5 @@
1
- extern crate napi_build;
2
-
3
- fn main() {
4
- napi_build::setup();
5
- }
1
+ extern crate napi_build;
2
+
3
+ fn main() {
4
+ napi_build::setup();
5
+ }
@@ -0,0 +1,39 @@
1
+ ### Symmetric
2
+ - AES 256
3
+ ```typescript
4
+ const aesWrapper: AESWrapper = new AESWrapper();
5
+ const aesKey = aesWrapper.aes128Key();
6
+ const aesNonce = aesWrapper.aesNonce();
7
+ const toEncrypt: string = "This is my array to encrypt";
8
+ const encoder = new TextEncoder();
9
+ const tohashBytes: Array<number> = Array.from(encoder.encode(toEncrypt));
10
+ const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
11
+ const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
12
+ ```
13
+
14
+
15
+ ### Passwords
16
+ - BCrypt
17
+ ```typescript
18
+ const hasher: BCryptWrapper = new BCryptWrapper();
19
+ const password: string = "ThisOneBadPassword!@";
20
+ const hashedPassword: string = hasher.hashPassword(password);
21
+ ```
22
+
23
+ - SCrypt
24
+ ```typescript
25
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
26
+ PasswordHasherType.Scrypt,
27
+ );
28
+ const password: string = "ScryptRocks";
29
+ const hashed: string = hasher.hashPassword(password);
30
+ ```
31
+
32
+ - Argon2
33
+ ```typescript
34
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
35
+ PasswordHasherType.Argon2,
36
+ );
37
+ const password: string = "ScryptRocks";
38
+ const hashed: string = hasher.hashPassword(password);
39
+ ```
package/index.d.ts CHANGED
@@ -29,6 +29,12 @@ export function encryptPlaintextRsa(publicKey: string, plaintext: Array<number>)
29
29
  export function decryptCiphertextRsa(privateKey: string, ciphertext: Array<number>): Array<number>
30
30
  export function signRsa(privateKey: string, hash: Array<number>): Array<number>
31
31
  export function verifyRsa(publicKey: string, hash: Array<number>, signature: Array<number>): boolean
32
+ export function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CasrsaDigitalSignatureResult
33
+ export function sha512RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
34
+ export function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CasrsaDigitalSignatureResult
35
+ export function sha256RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
36
+ export function sha512Ed25519DigitalSignature(dataToSign: Array<number>): Casshaed25519DalekDigitalSignatureResult
37
+ export function sha512Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
32
38
  export type x25519SecretPublicKeyResult = X25519SecretPublicKeyResult
33
39
  export class X25519SecretPublicKeyResult {
34
40
  publicKey: Array<number>
@@ -46,3 +52,16 @@ export class RsaKeyPairResult {
46
52
  publicKey: string
47
53
  constructor(privateKey: string, publicKey: string)
48
54
  }
55
+ export type CASRSADigitalSignatureResult = CasrsaDigitalSignatureResult
56
+ export class CasrsaDigitalSignatureResult {
57
+ publicKey: string
58
+ privateKey: string
59
+ signature: Array<number>
60
+ constructor(publicKey: string, privateKey: string, signature: Array<number>)
61
+ }
62
+ export type CASSHAED25519DalekDigitalSignatureResult = Casshaed25519DalekDigitalSignatureResult
63
+ export class Casshaed25519DalekDigitalSignatureResult {
64
+ publicKey: Array<number>
65
+ signature: Array<number>
66
+ constructor(publicKey: Array<number>, signature: Array<number>)
67
+ }
package/index.node CHANGED
Binary file
@@ -0,0 +1,6 @@
1
+ import { CasrsaDigitalSignatureResult } from "../../index";
2
+ import { IDigitalSignature } from "./digital-signature-base";
3
+ export declare class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
4
+ createRsa(rsa_key_size: number, data_to_sign: number[]): CasrsaDigitalSignatureResult;
5
+ verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
6
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitalSignatureSHA512Wrapper = void 0;
4
+ const index_1 = require("../../index");
5
+ class DigitalSignatureSHA512Wrapper {
6
+ createRsa(rsa_key_size, data_to_sign) {
7
+ if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
8
+ throw new Error("You need to provide an appropriate RSA key size.");
9
+ }
10
+ if (data_to_sign?.length === 0) {
11
+ throw new Error("Must provide allocated data to sign");
12
+ }
13
+ return (0, index_1.sha512RsaDigitalSignature)(rsa_key_size, data_to_sign);
14
+ }
15
+ verifyRSa(public_key, data_to_verify, signature) {
16
+ if (!public_key) {
17
+ throw new Error("Must provide a public key");
18
+ }
19
+ if (data_to_verify?.length === 0) {
20
+ throw new Error("Must provide an allocated data to verify");
21
+ }
22
+ if (signature?.length === 0) {
23
+ throw new Error("Must provide an allocated signature");
24
+ }
25
+ return (0, index_1.sha512RsaVerifyDigitalSignature)(public_key, data_to_verify, signature);
26
+ }
27
+ }
28
+ exports.DigitalSignatureSHA512Wrapper = DigitalSignatureSHA512Wrapper;
@@ -0,0 +1,5 @@
1
+ import { CASRSADigitalSignatureResult } from "../../index";
2
+ export interface IDigitalSignature {
3
+ createRsa(rsa_key_size: number, data_to_sign: Array<number>): CASRSADigitalSignatureResult;
4
+ verifyRSa(public_key: string, data_to_verify: Array<number>, signature: Array<number>): boolean;
5
+ }
@@ -0,0 +1,8 @@
1
+ import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
2
+ export declare enum DigitalSignatureType {
3
+ SHA512 = 1,
4
+ SHA256 = 2
5
+ }
6
+ export declare class DigitalSignatureFactory {
7
+ static get(type: DigitalSignatureType): DigitalSignatureSHA512Wrapper;
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitalSignatureFactory = exports.DigitalSignatureType = void 0;
4
+ const digital_siganture_sha_512_1 = require("./digital-siganture-sha-512");
5
+ const digital_signaturte_sha_256_1 = require("./digital-signaturte-sha-256");
6
+ var DigitalSignatureType;
7
+ (function (DigitalSignatureType) {
8
+ DigitalSignatureType[DigitalSignatureType["SHA512"] = 1] = "SHA512";
9
+ DigitalSignatureType[DigitalSignatureType["SHA256"] = 2] = "SHA256";
10
+ })(DigitalSignatureType || (exports.DigitalSignatureType = DigitalSignatureType = {}));
11
+ class DigitalSignatureFactory {
12
+ static get(type) {
13
+ let ds = new digital_siganture_sha_512_1.DigitalSignatureSHA512Wrapper();
14
+ switch (type) {
15
+ case DigitalSignatureType.SHA256:
16
+ ds = new digital_signaturte_sha_256_1.DigitalSignatureSHA256Wrapper();
17
+ break;
18
+ }
19
+ return ds;
20
+ }
21
+ }
22
+ exports.DigitalSignatureFactory = DigitalSignatureFactory;
@@ -0,0 +1,6 @@
1
+ import { CasrsaDigitalSignatureResult } from "../../index";
2
+ import { IDigitalSignature } from "./digital-signature-base";
3
+ export declare class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
4
+ createRsa(rsa_key_size: number, data_to_sign: number[]): CasrsaDigitalSignatureResult;
5
+ verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
6
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitalSignatureSHA256Wrapper = void 0;
4
+ const index_1 = require("../../index");
5
+ class DigitalSignatureSHA256Wrapper {
6
+ createRsa(rsa_key_size, data_to_sign) {
7
+ if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
8
+ throw new Error("You need to provide an appropriate RSA key size.");
9
+ }
10
+ if (data_to_sign?.length === 0) {
11
+ throw new Error("Must provide allocated data to sign");
12
+ }
13
+ return (0, index_1.sha256RsaDigitalSignature)(rsa_key_size, data_to_sign);
14
+ }
15
+ verifyRSa(public_key, data_to_verify, signature) {
16
+ if (!public_key) {
17
+ throw new Error("Must provide a public key");
18
+ }
19
+ if (data_to_verify?.length === 0) {
20
+ throw new Error("Must provide an allocated data to verify");
21
+ }
22
+ if (signature?.length === 0) {
23
+ throw new Error("Must provide an allocated signature");
24
+ }
25
+ return (0, index_1.sha256RsaVerifyDigitalSignature)(public_key, data_to_verify, signature);
26
+ }
27
+ }
28
+ exports.DigitalSignatureSHA256Wrapper = DigitalSignatureSHA256Wrapper;
@@ -0,0 +1,4 @@
1
+ export declare enum DigitalSignatureType {
2
+ SHA512 = 1,
3
+ SHA256 = 2
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitalSignatureType = void 0;
4
+ var DigitalSignatureType;
5
+ (function (DigitalSignatureType) {
6
+ DigitalSignatureType[DigitalSignatureType["SHA512"] = 1] = "SHA512";
7
+ DigitalSignatureType[DigitalSignatureType["SHA256"] = 2] = "SHA256";
8
+ })(DigitalSignatureType || (exports.DigitalSignatureType = DigitalSignatureType = {}));
@@ -0,0 +1,9 @@
1
+ import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
2
+ import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
3
+ export declare class HybridEncryptionWrapper {
4
+ private aesWrapper;
5
+ private rsaWrapper;
6
+ constructor();
7
+ encrypt(dataToEncrypt: Array<number>, initalizer: AESRSAHybridInitializer): AesRsaHybridEncryptResult;
8
+ decrypt(privateKey: string, encryptResult: AesRsaHybridEncryptResult): Array<number>;
9
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HybridEncryptionWrapper = void 0;
4
+ const asymmetric_1 = require("../asymmetric");
5
+ const symmetric_1 = require("../symmetric");
6
+ const aes_rsa_hybird_encrypt_result_1 = require("./types/aes-rsa-hybird-encrypt-result");
7
+ class HybridEncryptionWrapper {
8
+ aesWrapper;
9
+ rsaWrapper;
10
+ constructor() {
11
+ this.aesWrapper = new symmetric_1.AESWrapper();
12
+ this.rsaWrapper = new asymmetric_1.RSAWrapper();
13
+ }
14
+ encrypt(dataToEncrypt, initalizer) {
15
+ let encryptedData = (initalizer.aesType === 128)
16
+ ? this.aesWrapper.aes128Encrypt(initalizer.aesKey, initalizer.aesNonce, dataToEncrypt)
17
+ : this.aesWrapper.aes256Encrypt(initalizer.aesKey, initalizer.aesNonce, dataToEncrypt);
18
+ let encryptedAesKey = this.rsaWrapper.encrypt(initalizer.rsaKeyPair.publicKey, initalizer.aesKey);
19
+ let result = new aes_rsa_hybird_encrypt_result_1.AesRsaHybridEncryptResult(encryptedData, encryptedAesKey, initalizer.aesType, initalizer.aesNonce);
20
+ return result;
21
+ }
22
+ decrypt(privateKey, encryptResult) {
23
+ let plaintextAesKey = this.rsaWrapper.decrypt(privateKey, encryptResult.encryptedAesKey);
24
+ let plaintext = (encryptResult.aesType === 128)
25
+ ? this.aesWrapper.aes128Decrypt(plaintextAesKey, encryptResult.aesNonce, encryptResult.ciphertext)
26
+ : this.aesWrapper.aes256Decrypt(plaintextAesKey, encryptResult.aesNonce, encryptResult.ciphertext);
27
+ return plaintext;
28
+ }
29
+ }
30
+ exports.HybridEncryptionWrapper = HybridEncryptionWrapper;
@@ -0,0 +1,4 @@
1
+ import { HybridEncryptionWrapper } from "./hybrid-encryption-wrapper";
2
+ import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
3
+ import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
4
+ export { AesRsaHybridEncryptResult, AESRSAHybridInitializer, HybridEncryptionWrapper, };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HybridEncryptionWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
4
+ const hybrid_encryption_wrapper_1 = require("./hybrid-encryption-wrapper");
5
+ Object.defineProperty(exports, "HybridEncryptionWrapper", { enumerable: true, get: function () { return hybrid_encryption_wrapper_1.HybridEncryptionWrapper; } });
6
+ const aes_rsa_hybird_encrypt_result_1 = require("./types/aes-rsa-hybird-encrypt-result");
7
+ Object.defineProperty(exports, "AesRsaHybridEncryptResult", { enumerable: true, get: function () { return aes_rsa_hybird_encrypt_result_1.AesRsaHybridEncryptResult; } });
8
+ const aes_rsa_hybrid_initializer_1 = require("./types/aes-rsa-hybrid-initializer");
9
+ Object.defineProperty(exports, "AESRSAHybridInitializer", { enumerable: true, get: function () { return aes_rsa_hybrid_initializer_1.AESRSAHybridInitializer; } });
@@ -0,0 +1,7 @@
1
+ export declare class AesRsaHybridEncryptResult {
2
+ ciphertext: Array<number>;
3
+ encryptedAesKey: Array<number>;
4
+ aesType: number;
5
+ aesNonce: Array<number>;
6
+ constructor(cipherText: Array<number>, encryptAesKey: Array<number>, aesType: number, aesNonce: Array<number>);
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AesRsaHybridEncryptResult = void 0;
4
+ class AesRsaHybridEncryptResult {
5
+ ciphertext;
6
+ encryptedAesKey;
7
+ aesType;
8
+ aesNonce;
9
+ constructor(cipherText, encryptAesKey, aesType, aesNonce) {
10
+ this.ciphertext = cipherText;
11
+ this.encryptedAesKey = encryptAesKey;
12
+ this.aesType = aesType;
13
+ this.aesNonce = aesNonce;
14
+ }
15
+ }
16
+ exports.AesRsaHybridEncryptResult = AesRsaHybridEncryptResult;
@@ -0,0 +1,8 @@
1
+ import { RsaKeyPairResult } from "../../..";
2
+ export declare class AESRSAHybridInitializer {
3
+ aesType: number;
4
+ aesKey: Array<number>;
5
+ aesNonce: Array<number>;
6
+ rsaKeyPair: RsaKeyPairResult;
7
+ constructor(aesType: number, rsaSize: number);
8
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AESRSAHybridInitializer = void 0;
4
+ const asymmetric_1 = require("../../asymmetric");
5
+ const symmetric_1 = require("../../symmetric");
6
+ class AESRSAHybridInitializer {
7
+ aesType;
8
+ aesKey;
9
+ aesNonce;
10
+ rsaKeyPair;
11
+ constructor(aesType, rsaSize) {
12
+ if (aesType !== 128 && aesType !== 256) {
13
+ throw new Error("Need an appropriate AES size to generate a hybrid initalizer");
14
+ }
15
+ this.aesType = aesType;
16
+ let aesWrapper = new symmetric_1.AESWrapper();
17
+ this.aesKey = (aesType === 128) ? aesWrapper.aes128Key() : aesWrapper.aes256Key();
18
+ this.aesNonce = aesWrapper.aesNonce();
19
+ if (rsaSize !== 1028 && rsaSize !== 2048 && rsaSize !== 4096) {
20
+ throw new Error("You must provide an appropriate RSA Key pair size to generate a hybrid initalizer");
21
+ }
22
+ this.rsaKeyPair = new asymmetric_1.RSAWrapper().generateKeys(rsaSize);
23
+ }
24
+ }
25
+ exports.AESRSAHybridInitializer = AESRSAHybridInitializer;
package/lib/index.d.ts CHANGED
@@ -2,5 +2,6 @@ import { Argon2Wrapper, BCryptWrapper, PasswordHasherFactory, PasswordHasherType
2
2
  import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
3
3
  import { X25519Wrapper } from "./key_exchange/index";
4
4
  import { AESWrapper } from "./symmetric/index";
5
- import { RSAWrapper, RsaKeyPairResult } from "./asymmetric";
6
- export { Argon2Wrapper, BCryptWrapper, HasherFactory, HasherType, PasswordHasherFactory, PasswordHasherType, ScryptWrapper, SHAWrapper, X25519Wrapper, AESWrapper, RSAWrapper, RsaKeyPairResult };
5
+ import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
6
+ import { AesRsaHybridEncryptResult, AESRSAHybridInitializer, HybridEncryptionWrapper } from "./hybrid/index";
7
+ export { AesRsaHybridEncryptResult, AESRSAHybridInitializer, AESWrapper, Argon2Wrapper, BCryptWrapper, HasherFactory, HasherType, HybridEncryptionWrapper, PasswordHasherFactory, PasswordHasherType, RsaKeyPairResult, RSAWrapper, ScryptWrapper, SHAWrapper, X25519Wrapper, };
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RsaKeyPairResult = exports.RSAWrapper = exports.AESWrapper = exports.X25519Wrapper = exports.SHAWrapper = exports.ScryptWrapper = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.HasherType = exports.HasherFactory = exports.BCryptWrapper = exports.Argon2Wrapper = void 0;
3
+ exports.X25519Wrapper = exports.SHAWrapper = exports.ScryptWrapper = exports.RSAWrapper = exports.RsaKeyPairResult = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.HybridEncryptionWrapper = exports.HasherType = exports.HasherFactory = exports.BCryptWrapper = exports.Argon2Wrapper = exports.AESWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
4
4
  const index_1 = require("./password-hashers/index");
5
5
  Object.defineProperty(exports, "Argon2Wrapper", { enumerable: true, get: function () { return index_1.Argon2Wrapper; } });
6
6
  Object.defineProperty(exports, "BCryptWrapper", { enumerable: true, get: function () { return index_1.BCryptWrapper; } });
@@ -15,6 +15,10 @@ const index_3 = require("./key_exchange/index");
15
15
  Object.defineProperty(exports, "X25519Wrapper", { enumerable: true, get: function () { return index_3.X25519Wrapper; } });
16
16
  const index_4 = require("./symmetric/index");
17
17
  Object.defineProperty(exports, "AESWrapper", { enumerable: true, get: function () { return index_4.AESWrapper; } });
18
- const asymmetric_1 = require("./asymmetric");
19
- Object.defineProperty(exports, "RSAWrapper", { enumerable: true, get: function () { return asymmetric_1.RSAWrapper; } });
20
- Object.defineProperty(exports, "RsaKeyPairResult", { enumerable: true, get: function () { return asymmetric_1.RsaKeyPairResult; } });
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; } });
package/package.json CHANGED
@@ -1,39 +1,41 @@
1
- {
2
- "name": "cas-typescript-sdk",
3
- "version": "1.0.14",
4
- "description": "",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "scripts": {
8
- "test": "cargo test && npm run build && mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
9
- "node:test": "mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
10
- "rust:test": "cargo test",
11
- "build": "napi build --release && tsc",
12
- "prepare": "npm run build"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/Cryptographic-API-Services/cas-typescript-sdk"
17
- },
18
- "keywords": [],
19
- "author": "Mike Mulchrone <mikemulchrone987@gmail.com>",
20
- "license": "Apache 2.0",
21
- "bugs": {
22
- "url": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk/issues"
23
- },
24
- "homepage": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk#readme",
25
- "publishConfig": {
26
- "access": "public",
27
- "registry": "https://registry.npmjs.org/"
28
- },
29
- "devDependencies": {
30
- "@napi-rs/cli": "^2.17.0",
31
- "@types/chai": "^4.3.11",
32
- "@types/mocha": "^10.0.6",
33
- "@types/node-fetch": "^2.6.3",
34
- "chai": "^4.4.1",
35
- "mocha": "^10.2.0",
36
- "ts-node": "^10.9.1",
37
- "typescript": "^5.0.3"
38
- }
39
- }
1
+
2
+ {
3
+ "name": "cas-typescript-sdk",
4
+ "version": "1.0.16",
5
+ "description": "",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "scripts": {
9
+ "test": "cargo test && npm run build && mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
10
+ "node:test": "mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
11
+ "rust:test": "cargo test",
12
+ "build": "npm run build:rust && rm -rf lib && tsc",
13
+ "build:rust": "napi build --release",
14
+ "prepare": "npm run build"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Cryptographic-API-Services/cas-typescript-sdk"
19
+ },
20
+ "keywords": [],
21
+ "author": "Mike Mulchrone <mikemulchrone987@gmail.com>",
22
+ "license": "Apache 2.0",
23
+ "bugs": {
24
+ "url": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk/issues"
25
+ },
26
+ "homepage": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk#readme",
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "registry": "https://registry.npmjs.org/"
30
+ },
31
+ "devDependencies": {
32
+ "@napi-rs/cli": "^2.17.0",
33
+ "@types/chai": "^4.3.11",
34
+ "@types/mocha": "^10.0.6",
35
+ "@types/node-fetch": "^2.6.3",
36
+ "chai": "^4.4.1",
37
+ "mocha": "^10.2.0",
38
+ "ts-node": "^10.9.1",
39
+ "typescript": "^5.0.3"
40
+ }
41
+ }
@@ -1,15 +1,15 @@
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
- }
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
+ }