cas-typescript-sdk 1.0.15 → 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.
- package/.github/workflows/main-pr-linux.yml +28 -0
- package/.github/workflows/main-pr-windows.yml +28 -0
- package/.github/workflows/main-publish.yml +32 -0
- package/Cargo.toml +8 -1
- package/README.md +2 -0
- package/build.rs +5 -5
- package/docs/EXAMPLES.md +39 -0
- package/index.d.ts +19 -0
- package/index.node +0 -0
- package/lib/digital-signature/digital-siganture-sha-512.d.ts +6 -0
- package/lib/digital-signature/digital-siganture-sha-512.js +28 -0
- package/lib/digital-signature/digital-signature-base.d.ts +5 -0
- package/lib/digital-signature/digital-signature-base.js +2 -0
- package/lib/digital-signature/digital-signature-factory.d.ts +8 -0
- package/lib/digital-signature/digital-signature-factory.js +22 -0
- package/lib/digital-signature/digital-signaturte-sha-256.d.ts +6 -0
- package/lib/digital-signature/digital-signaturte-sha-256.js +28 -0
- package/lib/digital-signature/index.d.ts +4 -0
- package/lib/digital-signature/index.js +8 -0
- package/package.json +41 -41
- package/src/asymmetric/cas_asymmetric_encryption.rs +15 -15
- package/src/asymmetric/cas_rsa.rs +88 -80
- package/src/digital_signature/cas_digital_signature_rsa.rs +27 -0
- package/src/digital_signature/sha_256_rsa.rs +96 -0
- package/src/digital_signature/sha_512_ed25519.rs +75 -0
- package/src/digital_signature/sha_512_rsa.rs +93 -0
- package/src/hashers/blake2.rs +37 -39
- package/src/hashers/cas_hasher.rs +8 -8
- package/src/hashers/sha.rs +102 -103
- package/src/key_exchange/cas_key_exchange.rs +6 -6
- package/src/key_exchange/x25519.rs +57 -57
- package/src/lib.rs +34 -27
- package/src/password_hashers/argon2.rs +65 -64
- package/src/password_hashers/bcrypt.rs +50 -51
- package/src/password_hashers/cas_password_hasher.rs +4 -4
- package/src/password_hashers/scrypt.rs +61 -56
- package/src/symmetric/aes.rs +155 -151
- package/src/symmetric/cas_symmetric_encryption.rs +14 -14
- package/src-ts/asymmetric/RSAWrapper.ts +53 -53
- package/src-ts/asymmetric/index.ts +3 -3
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +28 -0
- package/src-ts/digital-signature/digital-signature-base.ts +6 -0
- package/src-ts/digital-signature/digital-signature-factory.ts +19 -0
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +28 -0
- package/src-ts/digital-signature/index.ts +4 -0
- package/src-ts/global.d.ts +1 -1
- package/src-ts/hashers/hasher-base.ts +5 -5
- package/src-ts/hashers/hasher-factory.ts +11 -11
- package/src-ts/hashers/hasher-type.ts +2 -2
- package/src-ts/hashers/index.ts +5 -5
- package/src-ts/hashers/sha-wrapper.ts +37 -37
- package/src-ts/helpers/nonce-generator.ts +8 -8
- package/src-ts/hybrid/hybrid-encryption-wrapper.ts +64 -64
- package/src-ts/hybrid/index.ts +9 -9
- package/src-ts/hybrid/types/aes-rsa-hybird-encrypt-result.ts +12 -12
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +23 -23
- package/src-ts/index.ts +34 -34
- package/src-ts/key_exchange/index.ts +3 -3
- package/src-ts/key_exchange/x25519.ts +10 -10
- package/src-ts/password-hashers/argon2-wrapper.ts +18 -18
- package/src-ts/password-hashers/bcrypt-wrapper.ts +23 -23
- package/src-ts/password-hashers/index.ts +14 -14
- package/src-ts/password-hashers/password-hasher-base.ts +3 -3
- package/src-ts/password-hashers/password-hasher-factory.ts +20 -20
- package/src-ts/password-hashers/password-hasher-type.ts +4 -4
- package/src-ts/password-hashers/scrypt-wrapper.ts +19 -19
- package/src-ts/symmetric/aes-wrapper.ts +50 -50
- package/src-ts/symmetric/index.ts +3 -3
- package/test-ts/asymmetric.test.spec.ts +27 -27
- package/test-ts/digital-signature.test.spec.ts +49 -0
- package/test-ts/hasher.test.spec.ts +70 -70
- package/test-ts/helpers/array.ts +9 -9
- package/test-ts/hybrid.test.spec.ts +33 -33
- package/test-ts/insecure-channel.test.spec.ts +50 -50
- package/test-ts/key-exchange-test.spec.ts +23 -23
- package/test-ts/password-hasher-test.spec.ts +102 -102
- package/test-ts/symmetric.test.spec.ts +31 -31
- package/tsconfig.json +21 -21
- package/build-node.sh +0 -2
|
@@ -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
|
}
|
package/build-node.sh
DELETED