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
@@ -1,103 +1,103 @@
1
- import { assert, expect } from "chai";
2
- import { BCryptWrapper } from "../src-ts/password-hashers/index";
3
- import { ScryptWrapper } from "../src-ts/password-hashers/index";
4
- import {
5
- PasswordHasherFactory,
6
- PasswordHasherType,
7
- } from "../src-ts/password-hashers/";
8
-
9
- describe("Bcrypt Tests", () => {
10
- it("hash", () => {
11
- const hasher: BCryptWrapper = new BCryptWrapper();
12
- const password: string = "ThisOneBadPassword!@";
13
- const hashedPassword: string = hasher.hashPassword(password);
14
- assert.notEqual(hashedPassword, password);
15
- });
16
-
17
- it("verify pass", () => {
18
- const hasher: BCryptWrapper = new BCryptWrapper();
19
- const password: string = "NotThisPassword!@";
20
- const hashedPassword: string = hasher.hashPassword(password);
21
- const isValid: boolean = hasher.verifyPassword(hashedPassword, password);
22
- expect(isValid).to.equal(true);
23
- });
24
-
25
- it("verify fail", () => {
26
- const hasher: BCryptWrapper = new BCryptWrapper();
27
- const password: string = "NotThisPassword!@";
28
- const hashedPassword: string = hasher.hashPassword(password);
29
- const isValid: boolean = hasher.verifyPassword(
30
- hashedPassword,
31
- "ThesePasswordsDoNotMatch",
32
- );
33
- expect(isValid).to.equal(false);
34
- });
35
- });
36
-
37
- describe("Scrypt Tests", () => {
38
- it("hash with factory", () => {
39
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
40
- PasswordHasherType.Scrypt,
41
- );
42
- const password: string = "ScryptRocks";
43
- const hashed: string = hasher.hashPassword(password);
44
- assert.notEqual(password, hashed);
45
- });
46
-
47
- it("verify pass with factory", () => {
48
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
49
- PasswordHasherType.Scrypt,
50
- );
51
- const password: string = "ScryptRocks1231231";
52
- const hashed: string = hasher.hashPassword(password);
53
- const verified: boolean = hasher.verifyPassword(hashed, password);
54
- assert.isTrue(verified);
55
- });
56
-
57
- it("verify fail with factory", () => {
58
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
59
- PasswordHasherType.Scrypt,
60
- );
61
- const password: string = "ScryptRocksSomeGarbageText";
62
- const hashed: string = hasher.hashPassword(password);
63
- const verified: boolean = hasher.verifyPassword(
64
- hashed,
65
- "make this fail, its not the same",
66
- );
67
- assert.isNotTrue(verified);
68
- });
69
- });
70
-
71
- describe("Argon2 Tests", () => {
72
- it("hash with factory", () => {
73
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
74
- PasswordHasherType.Argon2,
75
- );
76
- const password: string = "ScryptRocks";
77
- const hashed: string = hasher.hashPassword(password);
78
- assert.notEqual(password, hashed);
79
- });
80
-
81
- it("verify pass with factory", () => {
82
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
83
- PasswordHasherType.Argon2,
84
- );
85
- const password: string = "ScryptRocks1231231";
86
- const hashed: string = hasher.hashPassword(password);
87
- const verified: boolean = hasher.verifyPassword(hashed, password);
88
- assert.isTrue(verified);
89
- });
90
-
91
- it("verify fail with factory", () => {
92
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
93
- PasswordHasherType.Argon2,
94
- );
95
- const password: string = "ScryptRocksSomeGarbageText";
96
- const hashed: string = hasher.hashPassword(password);
97
- const verified: boolean = hasher.verifyPassword(
98
- hashed,
99
- "make this fail, its not the same",
100
- );
101
- assert.isNotTrue(verified);
102
- });
1
+ import { assert, expect } from "chai";
2
+ import { BCryptWrapper } from "../src-ts/password-hashers/index";
3
+ import { ScryptWrapper } from "../src-ts/password-hashers/index";
4
+ import {
5
+ PasswordHasherFactory,
6
+ PasswordHasherType,
7
+ } from "../src-ts/password-hashers/";
8
+
9
+ describe("Bcrypt Tests", () => {
10
+ it("hash", () => {
11
+ const hasher: BCryptWrapper = new BCryptWrapper();
12
+ const password: string = "ThisOneBadPassword!@";
13
+ const hashedPassword: string = hasher.hashPassword(password);
14
+ assert.notEqual(hashedPassword, password);
15
+ });
16
+
17
+ it("verify pass", () => {
18
+ const hasher: BCryptWrapper = new BCryptWrapper();
19
+ const password: string = "NotThisPassword!@";
20
+ const hashedPassword: string = hasher.hashPassword(password);
21
+ const isValid: boolean = hasher.verifyPassword(hashedPassword, password);
22
+ expect(isValid).to.equal(true);
23
+ });
24
+
25
+ it("verify fail", () => {
26
+ const hasher: BCryptWrapper = new BCryptWrapper();
27
+ const password: string = "NotThisPassword!@";
28
+ const hashedPassword: string = hasher.hashPassword(password);
29
+ const isValid: boolean = hasher.verifyPassword(
30
+ hashedPassword,
31
+ "ThesePasswordsDoNotMatch",
32
+ );
33
+ expect(isValid).to.equal(false);
34
+ });
35
+ });
36
+
37
+ describe("Scrypt Tests", () => {
38
+ it("hash with factory", () => {
39
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
40
+ PasswordHasherType.Scrypt,
41
+ );
42
+ const password: string = "ScryptRocks";
43
+ const hashed: string = hasher.hashPassword(password);
44
+ assert.notEqual(password, hashed);
45
+ });
46
+
47
+ it("verify pass with factory", () => {
48
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
49
+ PasswordHasherType.Scrypt,
50
+ );
51
+ const password: string = "ScryptRocks1231231";
52
+ const hashed: string = hasher.hashPassword(password);
53
+ const verified: boolean = hasher.verifyPassword(hashed, password);
54
+ assert.isTrue(verified);
55
+ });
56
+
57
+ it("verify fail with factory", () => {
58
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
59
+ PasswordHasherType.Scrypt,
60
+ );
61
+ const password: string = "ScryptRocksSomeGarbageText";
62
+ const hashed: string = hasher.hashPassword(password);
63
+ const verified: boolean = hasher.verifyPassword(
64
+ hashed,
65
+ "make this fail, its not the same",
66
+ );
67
+ assert.isNotTrue(verified);
68
+ });
69
+ });
70
+
71
+ describe("Argon2 Tests", () => {
72
+ it("hash with factory", () => {
73
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
74
+ PasswordHasherType.Argon2,
75
+ );
76
+ const password: string = "ScryptRocks";
77
+ const hashed: string = hasher.hashPassword(password);
78
+ assert.notEqual(password, hashed);
79
+ });
80
+
81
+ it("verify pass with factory", () => {
82
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
83
+ PasswordHasherType.Argon2,
84
+ );
85
+ const password: string = "ScryptRocks1231231";
86
+ const hashed: string = hasher.hashPassword(password);
87
+ const verified: boolean = hasher.verifyPassword(hashed, password);
88
+ assert.isTrue(verified);
89
+ });
90
+
91
+ it("verify fail with factory", () => {
92
+ const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
93
+ PasswordHasherType.Argon2,
94
+ );
95
+ const password: string = "ScryptRocksSomeGarbageText";
96
+ const hashed: string = hasher.hashPassword(password);
97
+ const verified: boolean = hasher.verifyPassword(
98
+ hashed,
99
+ "make this fail, its not the same",
100
+ );
101
+ assert.isNotTrue(verified);
102
+ });
103
103
  });
@@ -1,31 +1,31 @@
1
- import { assert } from "chai";
2
- import { AESWrapper } from "../src-ts/symmetric/aes-wrapper";
3
- import { areEqual } from "./helpers/array";
4
-
5
- describe("Symmetric Tests", () => {
6
- it("aes 128 encrypt and decrypt equals", () => {
7
- const aesWrapper: AESWrapper = new AESWrapper();
8
- const aesKey = aesWrapper.aes128Key();
9
- const aesNonce = aesWrapper.aesNonce();
10
- const tohashed: string = "This is my array to encrypt";
11
- const encoder = new TextEncoder();
12
- const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
13
- const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
14
- const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
15
- var result = areEqual(plaintxt, tohashBytes);
16
- assert.isTrue(result);
17
- });
18
-
19
- it("aes 256 encrypt and decrypt equals", () => {
20
- const aesWrapper: AESWrapper = new AESWrapper();
21
- const aesKey = aesWrapper.aes256Key();
22
- const aesNonce = aesWrapper.aesNonce();
23
- const tohashed: string = "This is my array to encrypt";
24
- const encoder = new TextEncoder();
25
- const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
26
- const ciphertext = aesWrapper.aes256Encrypt(aesKey, aesNonce, tohashBytes);
27
- const plaintxt = aesWrapper.aes256Decrypt(aesKey, aesNonce, ciphertext);
28
- var result = areEqual(plaintxt, tohashBytes);
29
- assert.isTrue(result);
30
- });
31
- });
1
+ import { assert } from "chai";
2
+ import { AESWrapper } from "../src-ts/symmetric/aes-wrapper";
3
+ import { areEqual } from "./helpers/array";
4
+
5
+ describe("Symmetric Tests", () => {
6
+ it("aes 128 encrypt and decrypt equals", () => {
7
+ const aesWrapper: AESWrapper = new AESWrapper();
8
+ const aesKey = aesWrapper.aes128Key();
9
+ const aesNonce = aesWrapper.aesNonce();
10
+ const tohashed: string = "This is my array to encrypt";
11
+ const encoder = new TextEncoder();
12
+ const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
13
+ const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
14
+ const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
15
+ var result = areEqual(plaintxt, tohashBytes);
16
+ assert.isTrue(result);
17
+ });
18
+
19
+ it("aes 256 encrypt and decrypt equals", () => {
20
+ const aesWrapper: AESWrapper = new AESWrapper();
21
+ const aesKey = aesWrapper.aes256Key();
22
+ const aesNonce = aesWrapper.aesNonce();
23
+ const tohashed: string = "This is my array to encrypt";
24
+ const encoder = new TextEncoder();
25
+ const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
26
+ const ciphertext = aesWrapper.aes256Encrypt(aesKey, aesNonce, tohashBytes);
27
+ const plaintxt = aesWrapper.aes256Decrypt(aesKey, aesNonce, ciphertext);
28
+ var result = areEqual(plaintxt, tohashBytes);
29
+ assert.isTrue(result);
30
+ });
31
+ });
package/tsconfig.json CHANGED
@@ -1,22 +1,22 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "display": "Node 18",
4
-
5
- "compilerOptions": {
6
- "lib": ["es2022"],
7
- "module": "commonjs",
8
- "target": "es2022",
9
-
10
- "strict": true,
11
- "esModuleInterop": true,
12
- "skipLibCheck": true,
13
- "forceConsistentCasingInFileNames": true,
14
-
15
- "outDir": "lib",
16
- "declaration": true
17
- },
18
-
19
- "include": [
20
- "src-ts/**/*"
21
- ]
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "display": "Node 18",
4
+
5
+ "compilerOptions": {
6
+ "lib": ["es2022"],
7
+ "module": "commonjs",
8
+ "target": "es2022",
9
+
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+
15
+ "outDir": "lib",
16
+ "declaration": true
17
+ },
18
+
19
+ "include": [
20
+ "src-ts/**/*"
21
+ ]
22
22
  }
Binary file
@@ -1,6 +0,0 @@
1
- export interface IHasherBase {
2
- hash_512(dataToHash: number[]): number[];
3
- verify_512(dataToHash: number[], dataToVerify: number[]): boolean;
4
- hash_256(dataToHash: number[]): number[];
5
- verify_256(dataToHash: number[], dataToVerify: number[]): boolean;
6
- }
@@ -1,7 +0,0 @@
1
- import { IHasherBase } from "./IHasherBase";
2
- export declare class SHAWrapper implements IHasherBase {
3
- hash_512(dataToHash: number[]): number[];
4
- verify_512(dataToHash: number[], dataToVerify: number[]): boolean;
5
- hash_256(dataToHash: number[]): number[];
6
- verify_256(dataToHash: number[], dataToVerify: number[]): boolean;
7
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SHAWrapper = void 0;
4
- const index_1 = require("../../index");
5
- class SHAWrapper {
6
- hash_512(dataToHash) {
7
- if (!dataToHash || dataToHash.length === 0) {
8
- throw new Error("You must provide an allocated array of data");
9
- }
10
- return (0, index_1.sha512)(dataToHash);
11
- }
12
- verify_512(dataToHash, dataToVerify) {
13
- if (!dataToHash || dataToHash.length === 0) {
14
- throw new Error("You must provide an allocated array of data");
15
- }
16
- if (!dataToVerify || dataToVerify.length === 0) {
17
- throw new Error("You must provide an allocated array of data to verify");
18
- }
19
- return (0, index_1.sha512Verify)(dataToHash, dataToVerify);
20
- }
21
- hash_256(dataToHash) {
22
- if (!dataToHash || dataToHash.length === 0) {
23
- throw new Error("You must provide an allocated array of data");
24
- }
25
- return (0, index_1.sha256)(dataToHash);
26
- }
27
- verify_256(dataToHash, dataToVerify) {
28
- if (!dataToHash || dataToHash.length === 0) {
29
- throw new Error("You must provide an allocated array of data");
30
- }
31
- if (!dataToVerify || dataToVerify.length === 0) {
32
- throw new Error("You must provide an allocated array of data to verify");
33
- }
34
- return (0, index_1.sha256Verify)(dataToHash, dataToVerify);
35
- }
36
- }
37
- exports.SHAWrapper = SHAWrapper;
Binary file
@@ -1,3 +0,0 @@
1
- import koffi from "koffi";
2
- declare const Argon2HashThreadResult: koffi.IKoffiCType;
3
- export default Argon2HashThreadResult;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const koffi_1 = __importDefault(require("koffi"));
7
- const Argon2HashThreadResult = koffi_1.default.struct("Argon2HashThreadResult", {
8
- passwords: 'char *',
9
- length: 'int'
10
- });
11
- exports.default = Argon2HashThreadResult;