cas-typescript-sdk 1.0.47 → 1.0.48
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.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,72 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ascon128Decrypt,
|
|
3
|
-
ascon128Encrypt,
|
|
4
|
-
ascon128KeyGenerate,
|
|
5
|
-
ascon128NonceGenerate,
|
|
6
|
-
} from "../../index";
|
|
7
|
-
|
|
8
|
-
export class AsconWrapper {
|
|
9
|
-
/**
|
|
10
|
-
* Generates an Ascon 128 key
|
|
11
|
-
* @returns Array<number>
|
|
12
|
-
*/
|
|
13
|
-
ascon128Key(): Array<number> {
|
|
14
|
-
return ascon128KeyGenerate();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Generates and Ascon 128 nonce.
|
|
19
|
-
* @returns Array<number>
|
|
20
|
-
*/
|
|
21
|
-
ascon128Nonce(): Array<number> {
|
|
22
|
-
return ascon128NonceGenerate();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Encrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
27
|
-
* @param key
|
|
28
|
-
* @param nonce
|
|
29
|
-
* @param plaintext
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
ascon128Encrypt(
|
|
33
|
-
key: Array<number>,
|
|
34
|
-
nonce: Array<number>,
|
|
35
|
-
plaintext: Array<number>,
|
|
36
|
-
): Array<number> {
|
|
37
|
-
if (!key || key.length === 0) {
|
|
38
|
-
throw new Error("Key is required");
|
|
39
|
-
}
|
|
40
|
-
if (!nonce || nonce.length === 0) {
|
|
41
|
-
throw new Error("Nonce is required");
|
|
42
|
-
}
|
|
43
|
-
if (!plaintext || plaintext.length === 0) {
|
|
44
|
-
throw new Error("Plaintext is required");
|
|
45
|
-
}
|
|
46
|
-
return ascon128Encrypt(key, nonce, plaintext);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Decrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
51
|
-
* @param key
|
|
52
|
-
* @param nonce
|
|
53
|
-
* @param ciphertext
|
|
54
|
-
* @returns Array<number>
|
|
55
|
-
*/
|
|
56
|
-
ascon128Decrypt(
|
|
57
|
-
key: Array<number>,
|
|
58
|
-
nonce: Array<number>,
|
|
59
|
-
ciphertext: Array<number>,
|
|
60
|
-
): Array<number> {
|
|
61
|
-
if (!key || key.length === 0) {
|
|
62
|
-
throw new Error("Key is required");
|
|
63
|
-
}
|
|
64
|
-
if (!nonce || nonce.length === 0) {
|
|
65
|
-
throw new Error("Nonce is required");
|
|
66
|
-
}
|
|
67
|
-
if (!ciphertext || ciphertext.length === 0) {
|
|
68
|
-
throw new Error("Ciphertext is required");
|
|
69
|
-
}
|
|
70
|
-
return ascon128Decrypt(key, nonce, ciphertext);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
aes128Decrypt,
|
|
3
|
-
aes128Encrypt,
|
|
4
|
-
aes128Key,
|
|
5
|
-
aes128KeyFromX25519SharedSecret,
|
|
6
|
-
aes256Decrypt,
|
|
7
|
-
aes256Encrypt,
|
|
8
|
-
aes256Key,
|
|
9
|
-
aes256KeyFromX25519SharedSecret,
|
|
10
|
-
aesNonce,
|
|
11
|
-
} from "../../index";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export class AESWrapper {
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @description Generates a 128 bit AES key
|
|
18
|
-
* @returns returns a 128 bit AES key
|
|
19
|
-
*/
|
|
20
|
-
public aes128Key(): Array<number> {
|
|
21
|
-
return aes128Key();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @description Generates a 256 bit AES key
|
|
26
|
-
* @returns returns a 256 bit AES key
|
|
27
|
-
*/
|
|
28
|
-
public aes256Key(): Array<number> {
|
|
29
|
-
return aes256Key();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Generates an 96 bit AES nonce
|
|
34
|
-
* @returns Array<number>
|
|
35
|
-
*/
|
|
36
|
-
public generateAESNonce(): Array<number> {
|
|
37
|
-
return aesNonce();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Encrypts with AES 128.
|
|
42
|
-
* @param aesKey
|
|
43
|
-
* @param nonce
|
|
44
|
-
* @param plaintext
|
|
45
|
-
* @returns Array<number>
|
|
46
|
-
*/
|
|
47
|
-
public aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
48
|
-
return aes128Encrypt(aesKey, nonce, plaintext);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Decrypts with AES 128
|
|
53
|
-
* @param aesKey
|
|
54
|
-
* @param nonce
|
|
55
|
-
* @param ciphertext
|
|
56
|
-
* @returns Array<number>
|
|
57
|
-
*/
|
|
58
|
-
public aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
59
|
-
return aes128Decrypt(aesKey, nonce, ciphertext);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Encrypts with AES-256
|
|
64
|
-
* @param aesKey
|
|
65
|
-
* @param nonce
|
|
66
|
-
* @param plaintext
|
|
67
|
-
* @returns
|
|
68
|
-
*/
|
|
69
|
-
public aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
70
|
-
return aes256Encrypt(aesKey, nonce, plaintext);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Decrypts with AES 256
|
|
75
|
-
* @param aesKey
|
|
76
|
-
* @param nonce
|
|
77
|
-
* @param ciphertext
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
public aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
81
|
-
return aes256Decrypt(aesKey, nonce, ciphertext);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
|
|
86
|
-
* @param shared_secret
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): number[] {
|
|
90
|
-
return aes256KeyFromX25519SharedSecret(shared_secret);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
|
|
95
|
-
* @param shared_secret
|
|
96
|
-
* @returns
|
|
97
|
-
*/
|
|
98
|
-
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): number[] {
|
|
99
|
-
return aes128KeyFromX25519SharedSecret(shared_secret);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { CASRSAKeyPairResult, RSAWrapper } from "..";
|
|
3
|
-
|
|
4
|
-
describe("Asymmetric Tests", () => {
|
|
5
|
-
it("RSA 2048 Sign and Verify", () => {
|
|
6
|
-
const rsaWrapper = new RSAWrapper();
|
|
7
|
-
const keys: CASRSAKeyPairResult = rsaWrapper.generateKeys(2048);
|
|
8
|
-
const tohashed: string = "This is my encrypt";
|
|
9
|
-
const encoder = new TextEncoder();
|
|
10
|
-
const toSignBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
11
|
-
const signature: Array<number> = rsaWrapper.sign(keys.privateKey, toSignBytes);
|
|
12
|
-
const verified = rsaWrapper.verify(keys.publicKey, toSignBytes, signature);
|
|
13
|
-
assert.isTrue(verified);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -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
|
-
});
|