cas-typescript-sdk 1.0.47 → 1.0.49
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/index.d.ts +141 -0
- package/index.darwin-x64.node +0 -0
- package/index.js +631 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.linux-x64-musl.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/lib/asymmetric/index.d.ts +3 -0
- package/lib/asymmetric/index.js +5 -0
- package/lib/digital-signature/index.d.ts +6 -0
- package/lib/digital-signature/index.js +11 -0
- package/lib/hashers/index.d.ts +5 -0
- package/lib/hashers/index.js +11 -0
- package/lib/hybrid/index.d.ts +2 -0
- package/lib/hybrid/index.js +5 -0
- package/lib/index.d.ts +10 -0
- package/lib/key_exchange/index.d.ts +3 -0
- package/lib/key_exchange/index.js +5 -0
- package/lib/message/index.d.ts +2 -0
- package/lib/message/index.js +5 -0
- package/lib/password-hashers/index.d.ts +6 -0
- package/lib/password-hashers/index.js +13 -0
- package/lib/signature/index.d.ts +2 -0
- package/lib/signature/index.js +5 -0
- package/lib/sponges/index.d.ts +2 -0
- package/lib/sponges/index.js +5 -0
- package/lib/symmetric/index.d.ts +2 -0
- package/lib/symmetric/index.js +5 -0
- package/package.json +8 -1
- package/.github/workflows/main-pr-linux.yml +0 -28
- package/.github/workflows/main-pr-windows.yml +0 -28
- package/.github/workflows/main-publish.yml +0 -109
- package/Cargo.toml +0 -19
- package/build.rs +0 -5
- package/docs/EXAMPLES.md +0 -138
- package/src/asymmetric/cas_ed25519.rs +0 -35
- package/src/asymmetric/cas_rsa.rs +0 -32
- package/src/digital_signature/sha_256_rsa.rs +0 -40
- package/src/digital_signature/sha_512_rsa.rs +0 -40
- package/src/digital_signature/types.rs +0 -34
- package/src/hashers/blake2.rs +0 -60
- package/src/hashers/sha.rs +0 -68
- package/src/hybrid/hpke.rs +0 -63
- package/src/hybrid/types.rs +0 -15
- package/src/key_exchange/types.rs +0 -17
- package/src/key_exchange/x25519.rs +0 -25
- package/src/lib.rs +0 -47
- package/src/message/hmac.rs +0 -21
- package/src/password_hashers/argon2.rs +0 -37
- package/src/password_hashers/bcrypt.rs +0 -37
- package/src/password_hashers/scrypt.rs +0 -36
- package/src/sponges/ascon_aead.rs +0 -66
- package/src/symmetric/aes.rs +0 -71
- package/src-ts/asymmetric/RSAWrapper.ts +0 -59
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +0 -40
- package/src-ts/digital-signature/digital-signature-base.ts +0 -6
- package/src-ts/digital-signature/digital-signature-factory.ts +0 -25
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +0 -41
- package/src-ts/hashers/blake2-wrapper.ts +0 -43
- package/src-ts/hashers/hasher-base.ts +0 -6
- package/src-ts/hashers/hasher-factory.ts +0 -19
- package/src-ts/hashers/hasher-type.ts +0 -4
- package/src-ts/hashers/sha-wrapper.ts +0 -60
- package/src-ts/hybrid/hpke.ts +0 -44
- package/src-ts/key_exchange/x25519.ts +0 -23
- package/src-ts/message/hmac.ts +0 -26
- package/src-ts/password-hashers/argon2-wrapper.ts +0 -31
- package/src-ts/password-hashers/bcrypt-wrapper.ts +0 -35
- package/src-ts/password-hashers/password-hasher-base.ts +0 -4
- package/src-ts/password-hashers/password-hasher-factory.ts +0 -25
- package/src-ts/password-hashers/password-hasher-type.ts +0 -5
- package/src-ts/password-hashers/scrypt-wrapper.ts +0 -32
- package/src-ts/signature/ed25519-wrapper.ts +0 -36
- package/src-ts/sponges/ascon-wrapper.ts +0 -72
- package/src-ts/symmetric/aes-wrapper.ts +0 -101
- package/test-ts/asymmetric.test.spec.ts +0 -15
- package/test-ts/digital-signature.test.spec.ts +0 -70
- package/test-ts/hasher.test.spec.ts +0 -139
- package/test-ts/helpers/array.ts +0 -10
- package/test-ts/hmac.test.spec.ts +0 -16
- package/test-ts/hybrid.test.spec.ts +0 -23
- package/test-ts/insecure-channel.test.spec.ts +0 -55
- package/test-ts/key-exchange.test.spec.ts +0 -23
- package/test-ts/password-hasher.test.spec.ts +0 -104
- package/test-ts/sponges.test.spec.ts +0 -28
- package/test-ts/symmetric.test.spec.ts +0 -82
- package/tsconfig.json +0 -22
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { DigitalSignatureFactory, DigitalSignatureType } from "../src-ts/digital-signature/digital-signature-factory";
|
|
3
|
-
import { CASRSADigitalSignatureResult } from "../index";
|
|
4
|
-
import { Ed25519Wrapper } from "../src-ts/signature/ed25519-wrapper";
|
|
5
|
-
|
|
6
|
-
describe("Digital Signature", () => {
|
|
7
|
-
it("SHA 512 RSA pass", () => {
|
|
8
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
9
|
-
const tohashed: string = "This is my array to encrypt";
|
|
10
|
-
const encoder = new TextEncoder();
|
|
11
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
12
|
-
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
13
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
14
|
-
assert.equal(verify, true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("SHA 512 RSA fails", () => {
|
|
18
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
19
|
-
const tohashed: string = "This is my array to encrypt";
|
|
20
|
-
const notOriginal: string = "This is not a fun time";
|
|
21
|
-
const encoder = new TextEncoder();
|
|
22
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
23
|
-
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
24
|
-
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
25
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
26
|
-
assert.equal(verify, false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("SHA 256 RSA pass", () => {
|
|
30
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
31
|
-
const tohashed: string = "This is my array to encrypt";
|
|
32
|
-
const encoder = new TextEncoder();
|
|
33
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
34
|
-
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
35
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
36
|
-
assert.equal(verify, true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("SHA 256 RSA fails", () => {
|
|
40
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
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: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
47
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
48
|
-
assert.equal(verify, false);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
it("ED25519 Sign and Verify", () => {
|
|
53
|
-
const ed25519 = new Ed25519Wrapper();
|
|
54
|
-
const keyPair = ed25519.getKeyPair();
|
|
55
|
-
const message = Array.from(new TextEncoder().encode("This is a test message"));
|
|
56
|
-
const signature = ed25519.signMessage(keyPair.privateKey, message);
|
|
57
|
-
const isValid = ed25519.verifyMessage(keyPair.publicKey, message, signature);
|
|
58
|
-
assert.equal(isValid, true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("ED25519 Verify Fails with Wrong Message", () => {
|
|
62
|
-
const ed25519 = new Ed25519Wrapper();
|
|
63
|
-
const keyPair = ed25519.getKeyPair();
|
|
64
|
-
const message = Array.from(new TextEncoder().encode("This is a test message"));
|
|
65
|
-
const wrongMessage = Array.from(new TextEncoder().encode("This is a different message"));
|
|
66
|
-
const signature = ed25519.signMessage(keyPair.privateKey, message);
|
|
67
|
-
const isValid = ed25519.verifyMessage(keyPair.publicKey, wrongMessage, signature);
|
|
68
|
-
assert.equal(isValid, false);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { Blake2Wrapper, SHAWrapper } from "../src-ts/hashers/index";
|
|
3
|
-
|
|
4
|
-
describe("SHA512 Tests", () => {
|
|
5
|
-
it("hash", () => {
|
|
6
|
-
const wrapper = new SHAWrapper();
|
|
7
|
-
const tohashed: string = "This is my array to hash";
|
|
8
|
-
const encoder = new TextEncoder();
|
|
9
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
10
|
-
const hashed = wrapper.hash512(tohashBytes);
|
|
11
|
-
assert.notEqual(tohashBytes, hashed);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("verify pass", () => {
|
|
15
|
-
const wrapper = new SHAWrapper();
|
|
16
|
-
const tohashed: string = "This is my array to hash";
|
|
17
|
-
const encoder = new TextEncoder();
|
|
18
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
19
|
-
const hashed = wrapper.hash512(tohashBytes);
|
|
20
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
21
|
-
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
22
|
-
assert.equal(true, verified);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("verify fail", () => {
|
|
26
|
-
const wrapper = new SHAWrapper();
|
|
27
|
-
const tohashed: string = "This is my array to hash";
|
|
28
|
-
const encoder = new TextEncoder();
|
|
29
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
30
|
-
const hashed = wrapper.hash512(tohashBytes);
|
|
31
|
-
const toVerify = "This Is Not The Same";
|
|
32
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
33
|
-
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
34
|
-
assert.equal(false, verified);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
describe("SHA256 Tests", () => {
|
|
40
|
-
it("hash", () => {
|
|
41
|
-
const wrapper = new SHAWrapper();
|
|
42
|
-
const tohashed: string = "This is my array to hash";
|
|
43
|
-
const encoder = new TextEncoder();
|
|
44
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
-
const hashed = wrapper.hash256(tohashBytes);
|
|
46
|
-
assert.notEqual(tohashBytes, hashed);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("verify pass", () => {
|
|
50
|
-
const wrapper = new SHAWrapper();
|
|
51
|
-
const tohashed: string = "This is my array to hash";
|
|
52
|
-
const encoder = new TextEncoder();
|
|
53
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
54
|
-
const hashed = wrapper.hash256(tohashBytes);
|
|
55
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
56
|
-
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
57
|
-
assert.equal(true, verified);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("verify fail", () => {
|
|
61
|
-
const wrapper = new SHAWrapper();
|
|
62
|
-
const tohashed: string = "This is my array to hash";
|
|
63
|
-
const encoder = new TextEncoder();
|
|
64
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
65
|
-
const hashed = wrapper.hash256(tohashBytes);
|
|
66
|
-
const toVerify = "This Is Not The Same";
|
|
67
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
68
|
-
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
69
|
-
assert.equal(false, verified);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("Blake2 512", () => {
|
|
74
|
-
it("hash", () => {
|
|
75
|
-
const wrapper = new Blake2Wrapper();
|
|
76
|
-
const tohashed: string = "This is my array to hash";
|
|
77
|
-
const encoder = new TextEncoder();
|
|
78
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
79
|
-
const hashed = wrapper.hash512(tohashBytes);
|
|
80
|
-
assert.notEqual(tohashBytes, hashed);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("verify pass", () => {
|
|
84
|
-
const wrapper = new Blake2Wrapper();
|
|
85
|
-
const tohashed: string = "This is my array to hash";
|
|
86
|
-
const encoder = new TextEncoder();
|
|
87
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
88
|
-
const hashed = wrapper.hash512(tohashBytes);
|
|
89
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
90
|
-
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
91
|
-
assert.equal(true, verified);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("verify fail", () => {
|
|
95
|
-
const wrapper = new Blake2Wrapper();
|
|
96
|
-
const tohashed: string = "This is my array to hash";
|
|
97
|
-
const encoder = new TextEncoder();
|
|
98
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
99
|
-
const hashed = wrapper.hash512(tohashBytes);
|
|
100
|
-
const toVerify = "This Is Not The Same";
|
|
101
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
102
|
-
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
103
|
-
assert.equal(false, verified);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe("Blake2 256", () => {
|
|
107
|
-
it("hash", () => {
|
|
108
|
-
const wrapper = new Blake2Wrapper();
|
|
109
|
-
const tohashed: string = "This is my array to hash";
|
|
110
|
-
const encoder = new TextEncoder();
|
|
111
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
112
|
-
const hashed = wrapper.hash256(tohashBytes);
|
|
113
|
-
assert.notEqual(tohashBytes, hashed);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("verify pass", () => {
|
|
117
|
-
const wrapper = new Blake2Wrapper();
|
|
118
|
-
const tohashed: string = "This is my array to hash";
|
|
119
|
-
const encoder = new TextEncoder();
|
|
120
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
121
|
-
const hashed = wrapper.hash256(tohashBytes);
|
|
122
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
123
|
-
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
124
|
-
assert.equal(true, verified);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("verify fail", () => {
|
|
128
|
-
const wrapper = new Blake2Wrapper();
|
|
129
|
-
const tohashed: string = "This is my array to hash";
|
|
130
|
-
const encoder = new TextEncoder();
|
|
131
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
132
|
-
const hashed = wrapper.hash256(tohashBytes);
|
|
133
|
-
const toVerify = "This Is Not The Same";
|
|
134
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
135
|
-
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
136
|
-
assert.equal(false, verified);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
package/test-ts/helpers/array.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const areEqual = (a: any, b: any) => {
|
|
2
|
-
if (a === b) return true;
|
|
3
|
-
if (a == null || b == null) return false;
|
|
4
|
-
if (a.length !== b.length) return false;
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < a.length; ++i) {
|
|
7
|
-
if (a[i] !== b[i]) return false;
|
|
8
|
-
}
|
|
9
|
-
return true;
|
|
10
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { HmacWrapper } from "../src-ts/message/index";
|
|
3
|
-
|
|
4
|
-
describe("HMAC Tests", () => {
|
|
5
|
-
it("Sign and Verify", () => {
|
|
6
|
-
const wrapper = new HmacWrapper();
|
|
7
|
-
const key: string = "This is my array to hash";
|
|
8
|
-
const encoder = new TextEncoder();
|
|
9
|
-
const keyBytes: Array<number> = Array.from(encoder.encode(key));
|
|
10
|
-
const message: string = "This is my message";
|
|
11
|
-
const messageBytes = Array.from(encoder.encode(message));
|
|
12
|
-
const signature = wrapper.hmacSignBytes(keyBytes, messageBytes);
|
|
13
|
-
const result = wrapper.hmacVerifyBytes(keyBytes, messageBytes, signature);
|
|
14
|
-
assert.equal(true, result);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { HpkeWrapper } from "../src-ts/hybrid/hpke";
|
|
2
|
-
import { assert } from "chai";
|
|
3
|
-
|
|
4
|
-
describe("Hybrid Encryption", () => {
|
|
5
|
-
it("HPKE Encrypt and Decrypt", () => {
|
|
6
|
-
const hpkeWrapper = new HpkeWrapper();
|
|
7
|
-
const keyPair = hpkeWrapper.generateKeyPair();
|
|
8
|
-
const encoder = new TextEncoder();
|
|
9
|
-
const message = "This is a secret message";
|
|
10
|
-
const messageBytes: Array<number> = Array.from(encoder.encode(message));
|
|
11
|
-
const encrypted = hpkeWrapper.encrypt(messageBytes, keyPair.publicKey, keyPair.infoStr);
|
|
12
|
-
const decrypted = hpkeWrapper.decrypt(
|
|
13
|
-
encrypted.ciphertext,
|
|
14
|
-
keyPair.secretKey,
|
|
15
|
-
encrypted.encapsulatedKey,
|
|
16
|
-
encrypted.tag,
|
|
17
|
-
keyPair.infoStr
|
|
18
|
-
);
|
|
19
|
-
const decoder = new TextDecoder();
|
|
20
|
-
const decryptedMessage = decoder.decode(new Uint8Array(decrypted));
|
|
21
|
-
assert.equal(decryptedMessage, message);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {AESWrapper} from "../src-ts/symmetric/index";
|
|
2
|
-
import {X25519Wrapper} from "../src-ts/key_exchange/index";
|
|
3
|
-
import {CASx25519SecretPublicKeyResult} from "../index";
|
|
4
|
-
import { areEqual } from "./helpers/array";
|
|
5
|
-
import { assert } from "chai";
|
|
6
|
-
|
|
7
|
-
describe("Insecure Channel Tests", () => {
|
|
8
|
-
it("AES256-GBC Diffie Hellman X25519", () => {
|
|
9
|
-
const aesWrapper = new AESWrapper();
|
|
10
|
-
const x25519Wrapper = new X25519Wrapper();
|
|
11
|
-
const alice_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
12
|
-
const bob_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
13
|
-
|
|
14
|
-
const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
|
|
15
|
-
const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
|
|
16
|
-
|
|
17
|
-
const alice_aes_key = aesWrapper.aes256KeyNonceX25519DiffieHellman(alice_shared_secret);
|
|
18
|
-
const bob_aes_key = aesWrapper.aes256KeyNonceX25519DiffieHellman(bob_shared_secret);
|
|
19
|
-
|
|
20
|
-
const tohashed: string = "This is my encrypt text";
|
|
21
|
-
const encoder = new TextEncoder();
|
|
22
|
-
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
23
|
-
|
|
24
|
-
const nonce = aesWrapper.generateAESNonce();
|
|
25
|
-
|
|
26
|
-
const encrypted = aesWrapper.aes256Encrypt(alice_aes_key, nonce, toEncrypt);
|
|
27
|
-
const decrypted = aesWrapper.aes256Decrypt(bob_aes_key, nonce, encrypted);
|
|
28
|
-
let result = areEqual(decrypted, toEncrypt);
|
|
29
|
-
assert.isTrue(result);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("AES128-GBC Diffie Hellman X25519", () => {
|
|
33
|
-
const aesWrapper = new AESWrapper();
|
|
34
|
-
const x25519Wrapper = new X25519Wrapper();
|
|
35
|
-
const alice_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
36
|
-
const bob_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
37
|
-
|
|
38
|
-
const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
|
|
39
|
-
const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
|
|
40
|
-
|
|
41
|
-
const alice_aes_key = aesWrapper.aes128KeyNonceX25519DiffieHellman(alice_shared_secret);
|
|
42
|
-
const bob_aes_key = aesWrapper.aes128KeyNonceX25519DiffieHellman(bob_shared_secret);
|
|
43
|
-
|
|
44
|
-
const tohashed: string = "This is my encrypt text";
|
|
45
|
-
const encoder = new TextEncoder();
|
|
46
|
-
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
47
|
-
|
|
48
|
-
const nonce = aesWrapper.generateAESNonce();
|
|
49
|
-
|
|
50
|
-
const encrypted = aesWrapper.aes128Encrypt(alice_aes_key, nonce, toEncrypt);
|
|
51
|
-
const decrypted = aesWrapper.aes128Decrypt(bob_aes_key, nonce, encrypted);
|
|
52
|
-
let result = areEqual(decrypted, toEncrypt);
|
|
53
|
-
assert.isTrue(result);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { X25519Wrapper } from "../src-ts/index";
|
|
3
|
-
import { areEqual } from "./helpers/array";
|
|
4
|
-
|
|
5
|
-
describe("X25519 Key Exchange", () => {
|
|
6
|
-
it("Pass", () => {
|
|
7
|
-
const wrapper = new X25519Wrapper();
|
|
8
|
-
const alice = wrapper.generateSecretAndPublicKey();
|
|
9
|
-
const bob = wrapper.generateSecretAndPublicKey();
|
|
10
|
-
|
|
11
|
-
const alice_shared_secret = wrapper.generateSharedSecret(
|
|
12
|
-
alice.secretKey,
|
|
13
|
-
bob.publicKey,
|
|
14
|
-
);
|
|
15
|
-
const bob_shared_secret = wrapper.generateSharedSecret(
|
|
16
|
-
bob.secretKey,
|
|
17
|
-
alice.publicKey,
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
var result = areEqual(alice_shared_secret, bob_shared_secret);
|
|
21
|
-
assert.isTrue(result);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { assert, expect } from "chai";
|
|
2
|
-
import { Argon2Wrapper, 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
|
-
|
|
11
|
-
it("hash", () => {
|
|
12
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
13
|
-
const password: string = "ThisOneBadPassword!@";
|
|
14
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
15
|
-
assert.notEqual(hashedPassword, password);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("verify pass", () => {
|
|
19
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
20
|
-
const password: string = "NotThisPassword!@";
|
|
21
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
22
|
-
const isValid: boolean = hasher.verify(hashedPassword, password);
|
|
23
|
-
expect(isValid).to.equal(true);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("verify fail", () => {
|
|
27
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
28
|
-
const password: string = "NotThisPassword!@";
|
|
29
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
30
|
-
const isValid: boolean = hasher.verify(
|
|
31
|
-
hashedPassword,
|
|
32
|
-
"ThesePasswordsDoNotMatch",
|
|
33
|
-
);
|
|
34
|
-
expect(isValid).to.equal(false);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe("Scrypt Tests", () => {
|
|
39
|
-
it("hash with factory", () => {
|
|
40
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
41
|
-
PasswordHasherType.Scrypt,
|
|
42
|
-
);
|
|
43
|
-
const password: string = "ScryptRocks";
|
|
44
|
-
const hashed: string = hasher.hashPassword(password);
|
|
45
|
-
assert.notEqual(password, hashed);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("verify pass with factory", () => {
|
|
49
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
50
|
-
PasswordHasherType.Scrypt,
|
|
51
|
-
);
|
|
52
|
-
const password: string = "ScryptRocks1231231";
|
|
53
|
-
const hashed: string = hasher.hashPassword(password);
|
|
54
|
-
const verified: boolean = hasher.verify(hashed, password);
|
|
55
|
-
assert.isTrue(verified);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("verify fail with factory", () => {
|
|
59
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
60
|
-
PasswordHasherType.Scrypt,
|
|
61
|
-
);
|
|
62
|
-
const password: string = "ScryptRocksSomeGarbageText";
|
|
63
|
-
const hashed: string = hasher.hashPassword(password);
|
|
64
|
-
const verified: boolean = hasher.verify(
|
|
65
|
-
hashed,
|
|
66
|
-
"make this fail, its not the same",
|
|
67
|
-
);
|
|
68
|
-
assert.isNotTrue(verified);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("Argon2 Tests", () => {
|
|
73
|
-
it("hash with factory", () => {
|
|
74
|
-
const hasher: Argon2Wrapper = PasswordHasherFactory.getHasher(
|
|
75
|
-
PasswordHasherType.Argon2,
|
|
76
|
-
);
|
|
77
|
-
const password: string = "ScryptRocks";
|
|
78
|
-
const hashed: string = hasher.hashPassword(password);
|
|
79
|
-
assert.notEqual(password, hashed);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("verify pass with factory", () => {
|
|
83
|
-
const hasher: Argon2Wrapper = PasswordHasherFactory.getHasher(
|
|
84
|
-
PasswordHasherType.Argon2,
|
|
85
|
-
);
|
|
86
|
-
const password: string = "ScryptRocks1231231";
|
|
87
|
-
const hashed: string = hasher.hashPassword(password);
|
|
88
|
-
const verified: boolean = hasher.verify(hashed, password);
|
|
89
|
-
assert.isTrue(verified);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("verify fail with factory", () => {
|
|
93
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
94
|
-
PasswordHasherType.Argon2,
|
|
95
|
-
);
|
|
96
|
-
const password: string = "ScryptRocksSomeGarbageText";
|
|
97
|
-
const hashed: string = hasher.hashPassword(password);
|
|
98
|
-
const verified: boolean = hasher.verify(
|
|
99
|
-
hashed,
|
|
100
|
-
"make this fail, its not the same",
|
|
101
|
-
);
|
|
102
|
-
assert.isNotTrue(verified);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AsconWrapper } from "../src-ts/sponges/ascon-wrapper";
|
|
2
|
-
import { assert } from "chai";
|
|
3
|
-
import { areEqual } from "./helpers/array";
|
|
4
|
-
|
|
5
|
-
describe("Sponges Tests", () => {
|
|
6
|
-
it("Ascon 128 Encrypt", () => {
|
|
7
|
-
const wrapper: AsconWrapper = new AsconWrapper();
|
|
8
|
-
const key: Array<number> = wrapper.ascon128Key();
|
|
9
|
-
const nonce: Array<number> = wrapper.ascon128Nonce();
|
|
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 = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
|
|
14
|
-
assert.isNotTrue(areEqual(tohashBytes, ciphertext));
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it ("Ascon 128 Decrypt", () => {
|
|
18
|
-
const wrapper: AsconWrapper = new AsconWrapper();
|
|
19
|
-
const key: Array<number> = wrapper.ascon128Key();
|
|
20
|
-
const nonce: Array<number> = wrapper.ascon128Nonce();
|
|
21
|
-
const tohashed: string = "This is my array to encrypt";
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
24
|
-
const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
|
|
25
|
-
const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
|
|
26
|
-
assert.equal(areEqual(plaintext, tohashBytes), true);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { AESWrapper } from "../src-ts/symmetric/aes-wrapper";
|
|
3
|
-
import { X25519Wrapper } from '../src-ts/key_exchange/x25519';
|
|
4
|
-
import { areEqual } from "./helpers/array";
|
|
5
|
-
|
|
6
|
-
describe("Symmetric Tests", () => {
|
|
7
|
-
it("aes 128 encrypt and decrypt equals", () => {
|
|
8
|
-
const aesWrapper: AESWrapper = new AESWrapper();
|
|
9
|
-
const aesKey = aesWrapper.aes128Key();
|
|
10
|
-
const aesNonce = aesWrapper.generateAESNonce();
|
|
11
|
-
const tohashed: string = "This is my array to encrypt";
|
|
12
|
-
const encoder = new TextEncoder();
|
|
13
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
14
|
-
const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
|
|
15
|
-
const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
|
|
16
|
-
var result = areEqual(plaintxt, tohashBytes);
|
|
17
|
-
assert.isTrue(result);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("aes 256 encrypt and decrypt equals", () => {
|
|
21
|
-
const aesWrapper: AESWrapper = new AESWrapper();
|
|
22
|
-
const aesKey = aesWrapper.aes256Key();
|
|
23
|
-
const aesNonce = aesWrapper.generateAESNonce();
|
|
24
|
-
const tohashed: string = "This is my array to encrypt";
|
|
25
|
-
const encoder = new TextEncoder();
|
|
26
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
27
|
-
const ciphertext = aesWrapper.aes256Encrypt(aesKey, aesNonce, tohashBytes);
|
|
28
|
-
const plaintxt = aesWrapper.aes256Decrypt(aesKey, aesNonce, ciphertext);
|
|
29
|
-
var result = areEqual(plaintxt, tohashBytes);
|
|
30
|
-
assert.isTrue(result);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("ase 256 X25519 Diffie-Hellman encrypt and decrypt", () => {
|
|
34
|
-
const x25519 = new X25519Wrapper();
|
|
35
|
-
const alice= x25519.generateSecretAndPublicKey();
|
|
36
|
-
const bob = x25519.generateSecretAndPublicKey();
|
|
37
|
-
|
|
38
|
-
const aliceSharedSecret = x25519.generateSharedSecret(alice.secretKey, bob.publicKey);
|
|
39
|
-
const bobSharedSecret = x25519.generateSharedSecret(bob.secretKey, alice.publicKey);
|
|
40
|
-
|
|
41
|
-
const aesWrapper: AESWrapper = new AESWrapper();
|
|
42
|
-
const aliceAesKey = aesWrapper.aes256KeyNonceX25519DiffieHellman(aliceSharedSecret);
|
|
43
|
-
const bobAesKey = aesWrapper.aes256KeyNonceX25519DiffieHellman(bobSharedSecret);
|
|
44
|
-
|
|
45
|
-
const nonce = aesWrapper.generateAESNonce();
|
|
46
|
-
|
|
47
|
-
const tohashed: string = "This is my array to encrypt";
|
|
48
|
-
const encoder = new TextEncoder();
|
|
49
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
50
|
-
|
|
51
|
-
const aliceCiphertext = aesWrapper.aes256Encrypt(aliceAesKey, nonce, tohashBytes);
|
|
52
|
-
const bobPlaintext = aesWrapper.aes256Decrypt(bobAesKey, nonce, aliceCiphertext);
|
|
53
|
-
|
|
54
|
-
var result = areEqual(bobPlaintext, tohashBytes);
|
|
55
|
-
assert.isTrue(result);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("ase 128 X25519 Diffie-Hellman encrypt and decrypt", () => {
|
|
59
|
-
const x25519 = new X25519Wrapper();
|
|
60
|
-
const alice= x25519.generateSecretAndPublicKey();
|
|
61
|
-
const bob = x25519.generateSecretAndPublicKey();
|
|
62
|
-
|
|
63
|
-
const aliceSharedSecret = x25519.generateSharedSecret(alice.secretKey, bob.publicKey);
|
|
64
|
-
const bobSharedSecret = x25519.generateSharedSecret(bob.secretKey, alice.publicKey);
|
|
65
|
-
|
|
66
|
-
const aesWrapper: AESWrapper = new AESWrapper();
|
|
67
|
-
const aliceAesKey = aesWrapper.aes128KeyNonceX25519DiffieHellman(aliceSharedSecret);
|
|
68
|
-
const bobAesKey = aesWrapper.aes128KeyNonceX25519DiffieHellman(bobSharedSecret);
|
|
69
|
-
|
|
70
|
-
const tohashed: string = "This is my array to encrypt";
|
|
71
|
-
const encoder = new TextEncoder();
|
|
72
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
73
|
-
|
|
74
|
-
const nonce = aesWrapper.generateAESNonce();
|
|
75
|
-
|
|
76
|
-
const aliceCiphertext = aesWrapper.aes128Encrypt(aliceAesKey, nonce, tohashBytes);
|
|
77
|
-
const bobPlaintext = aesWrapper.aes128Decrypt(bobAesKey, nonce, aliceCiphertext);
|
|
78
|
-
|
|
79
|
-
var result = areEqual(bobPlaintext, tohashBytes);
|
|
80
|
-
assert.isTrue(result);
|
|
81
|
-
});
|
|
82
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
}
|