Skip to content

Commit 162f4cc

Browse files
apply style to tests, change Date to string in emails
1 parent 3fff96c commit 162f4cc

14 files changed

Lines changed: 305 additions & 437 deletions

tests/core/ecc.test.ts

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,51 @@
1-
import { describe, expect, it } from "vitest";
2-
import { generateEccKeys, deriveEccBits } from "../../src/core/ecc";
3-
import { CURVE_NAME, ECC_ALGORITHM } from "../../src/utils/constants";
1+
import { describe, expect, it } from 'vitest';
2+
import { generateEccKeys, deriveEccBits } from '../../src/core/ecc';
3+
import { CURVE_NAME, ECC_ALGORITHM } from '../../src/utils/constants';
44

5-
describe("Test ecc functions", () => {
6-
it("should generate elliptic curves key pair", async () => {
5+
describe('Test ecc functions', () => {
6+
it('should generate elliptic curves key pair', async () => {
77
const keyPair = await generateEccKeys();
88

9-
expect(keyPair).toHaveProperty("publicKey");
10-
expect(keyPair).toHaveProperty("privateKey");
9+
expect(keyPair).toHaveProperty('publicKey');
10+
expect(keyPair).toHaveProperty('privateKey');
1111
expect(keyPair.publicKey).toBeInstanceOf(CryptoKey);
1212
expect(keyPair.privateKey).toBeInstanceOf(CryptoKey);
13-
expect(keyPair.publicKey.type).toBe("public");
14-
expect(keyPair.privateKey.type).toBe("private");
13+
expect(keyPair.publicKey.type).toBe('public');
14+
expect(keyPair.privateKey.type).toBe('private');
1515
expect(keyPair.privateKey.extractable).toBeFalsy();
16-
expect(keyPair.privateKey.usages).toContain("deriveBits");
16+
expect(keyPair.privateKey.usages).toContain('deriveBits');
1717

1818
const alg = keyPair.publicKey.algorithm as EcKeyAlgorithm;
1919
expect(alg.name).toBe(ECC_ALGORITHM);
2020
expect(alg.namedCurve).toBe(CURVE_NAME);
2121
});
2222

23-
it("should derive the same keys for Bob and Alice", async () => {
23+
it('should derive the same keys for Bob and Alice', async () => {
2424
const keysAlice = await generateEccKeys();
2525
const keysBob = await generateEccKeys();
2626

27-
const resultAlice = await deriveEccBits(
28-
keysBob.publicKey,
29-
keysAlice.privateKey,
30-
);
31-
const resultBob = await deriveEccBits(
32-
keysAlice.publicKey,
33-
keysBob.privateKey,
34-
);
27+
const resultAlice = await deriveEccBits(keysBob.publicKey, keysAlice.privateKey);
28+
const resultBob = await deriveEccBits(keysAlice.publicKey, keysBob.privateKey);
3529

3630
expect(resultAlice).toStrictEqual(resultBob);
3731
});
3832

39-
it("should derive different keys for Bob and Alice and Alice and Eve", async () => {
33+
it('should derive different keys for Bob and Alice and Alice and Eve', async () => {
4034
const keysAlice = await generateEccKeys();
4135
const keysBob = await generateEccKeys();
4236
const keysEve = await generateEccKeys();
4337

44-
const resultAliceEve = await deriveEccBits(
45-
keysEve.publicKey,
46-
keysAlice.privateKey,
47-
);
48-
const resultAliceBob = await deriveEccBits(
49-
keysBob.publicKey,
50-
keysAlice.privateKey,
51-
);
38+
const resultAliceEve = await deriveEccBits(keysEve.publicKey, keysAlice.privateKey);
39+
const resultAliceBob = await deriveEccBits(keysBob.publicKey, keysAlice.privateKey);
5240

5341
expect(resultAliceBob).not.toStrictEqual(resultAliceEve);
5442
});
5543

56-
it("should throw an error if cannot derive", async () => {
44+
it('should throw an error if cannot derive', async () => {
5745
const keysAlice = await generateEccKeys();
5846

59-
await expect(
60-
deriveEccBits(keysAlice.privateKey, keysAlice.privateKey),
61-
).rejects.toThrowError(/Failed to derive ECC bits:/);
47+
await expect(deriveEccBits(keysAlice.privateKey, keysAlice.privateKey)).rejects.toThrowError(
48+
/Failed to derive ECC bits:/,
49+
);
6250
});
6351
});

tests/core/hash.test.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
import { describe, expect, it } from "vitest";
2-
import { getHash } from "../../src/core/hash";
3-
import { Buffer } from "buffer";
1+
import { describe, expect, it } from 'vitest';
2+
import { getHash } from '../../src/core/hash';
3+
import { Buffer } from 'buffer';
44

5-
describe("Test getHash with blake3 test vectors", () => {
6-
it("extendSecret should pass test with input length 0 from blake3 team", async () => {
7-
const message = Buffer.from("");
5+
describe('Test getHash with blake3 test vectors', () => {
6+
it('extendSecret should pass test with input length 0 from blake3 team', async () => {
7+
const message = Buffer.from('');
88
const result = await getHash(1048, [message]);
99
const testResult = new Uint8Array(
1010
Buffer.from(
11-
"af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262e00f03e7b69af26b7faaf09fcd333050338ddfe085b8cc869ca98b206c08243a26f5487789e8f660afe6c99ef9e0c52b92e7393024a80459cf91f476f9ffdbda7001c22e159b402631f277ca96f2defdf1078282314e763699a31c5363165421cce14d",
12-
"hex",
11+
'af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262e00f03e7b69af26b7faaf09fcd333050338ddfe085b8cc869ca98b206c08243a26f5487789e8f660afe6c99ef9e0c52b92e7393024a80459cf91f476f9ffdbda7001c22e159b402631f277ca96f2defdf1078282314e763699a31c5363165421cce14d',
12+
'hex',
1313
),
1414
);
1515
expect(result).toStrictEqual(testResult);
1616
});
1717

18-
it("extendSecret should pass test with input length 1 from blake3 team", async () => {
18+
it('extendSecret should pass test with input length 1 from blake3 team', async () => {
1919
const message = Buffer.from([0]);
2020
const result = await getHash(1048, [message]);
2121
const testResult = new Uint8Array(
2222
Buffer.from(
23-
"2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213c3a6cb8bf623e20cdb535f8d1a5ffb86342d9c0b64aca3bce1d31f60adfa137b358ad4d79f97b47c3d5e79f179df87a3b9776ef8325f8329886ba42f07fb138bb502f4081cbcec3195c5871e6c23e2cc97d3c69a613eba131e5f1351f3f1da786545e5",
24-
"hex",
23+
'2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213c3a6cb8bf623e20cdb535f8d1a5ffb86342d9c0b64aca3bce1d31f60adfa137b358ad4d79f97b47c3d5e79f179df87a3b9776ef8325f8329886ba42f07fb138bb502f4081cbcec3195c5871e6c23e2cc97d3c69a613eba131e5f1351f3f1da786545e5',
24+
'hex',
2525
),
2626
);
2727
expect(result).toStrictEqual(testResult);
2828
});
2929

30-
it("extendSecret should pass test with input length 2 from blake3 team", async () => {
30+
it('extendSecret should pass test with input length 2 from blake3 team', async () => {
3131
const message = Buffer.from([0, 1]);
3232
const result = await getHash(1048, [message]);
3333
const testResult = new Uint8Array(
3434
Buffer.from(
35-
"7b7015bb92cf0b318037702a6cdd81dee41224f734684c2c122cd6359cb1ee63d8386b22e2ddc05836b7c1bb693d92af006deb5ffbc4c70fb44d0195d0c6f252faac61659ef86523aa16517f87cb5f1340e723756ab65efb2f91964e14391de2a432263a6faf1d146937b35a33621c12d00be8223a7f1919cec0acd12097ff3ab00ab1",
36-
"hex",
35+
'7b7015bb92cf0b318037702a6cdd81dee41224f734684c2c122cd6359cb1ee63d8386b22e2ddc05836b7c1bb693d92af006deb5ffbc4c70fb44d0195d0c6f252faac61659ef86523aa16517f87cb5f1340e723756ab65efb2f91964e14391de2a432263a6faf1d146937b35a33621c12d00be8223a7f1919cec0acd12097ff3ab00ab1',
36+
'hex',
3737
),
3838
);
3939
expect(result).toStrictEqual(testResult);
@@ -51,49 +51,49 @@ describe("Test getHash with blake3 test vectors", () => {
5151
}
5252
return Buffer.from(result);
5353
}
54-
it("extendSecret should pass test with input length 7 from blake3 team", async () => {
54+
it('extendSecret should pass test with input length 7 from blake3 team', async () => {
5555
const message = getBuffer(7);
5656
const result = await getHash(1048, [message]);
5757
const testResult = new Uint8Array(
5858
Buffer.from(
59-
"3f8770f387faad08faa9d8414e9f449ac68e6ff0417f673f602a646a891419fe66036ef6e6d1a8f54baa9fed1fc11c77cfb9cff65bae915045027046ebe0c01bf5a941f3bb0f73791d3fc0b84370f9f30af0cd5b0fc334dd61f70feb60dad785f070fef1f343ed933b49a5ca0d16a503f599a365a4296739248b28d1a20b0e2cc8975c",
60-
"hex",
59+
'3f8770f387faad08faa9d8414e9f449ac68e6ff0417f673f602a646a891419fe66036ef6e6d1a8f54baa9fed1fc11c77cfb9cff65bae915045027046ebe0c01bf5a941f3bb0f73791d3fc0b84370f9f30af0cd5b0fc334dd61f70feb60dad785f070fef1f343ed933b49a5ca0d16a503f599a365a4296739248b28d1a20b0e2cc8975c',
60+
'hex',
6161
),
6262
);
6363
expect(result).toStrictEqual(testResult);
6464
});
6565

66-
it("extendSecret should pass test with input length 63 from blake3 team", async () => {
66+
it('extendSecret should pass test with input length 63 from blake3 team', async () => {
6767
const message = getBuffer(63);
6868
const result = await getHash(1048, [message]);
6969
const testResult = new Uint8Array(
7070
Buffer.from(
71-
"e9bc37a594daad83be9470df7f7b3798297c3d834ce80ba85d6e207627b7db7b1197012b1e7d9af4d7cb7bdd1f3bb49a90a9b5dec3ea2bbc6eaebce77f4e470cbf4687093b5352f04e4a4570fba233164e6acc36900e35d185886a827f7ea9bdc1e5c3ce88b095a200e62c10c043b3e9bc6cb9b6ac4dfa51794b02ace9f98779040755",
72-
"hex",
71+
'e9bc37a594daad83be9470df7f7b3798297c3d834ce80ba85d6e207627b7db7b1197012b1e7d9af4d7cb7bdd1f3bb49a90a9b5dec3ea2bbc6eaebce77f4e470cbf4687093b5352f04e4a4570fba233164e6acc36900e35d185886a827f7ea9bdc1e5c3ce88b095a200e62c10c043b3e9bc6cb9b6ac4dfa51794b02ace9f98779040755',
72+
'hex',
7373
),
7474
);
7575
expect(result).toStrictEqual(testResult);
7676
});
7777

78-
it("extendSecret should pass test with input length 1023 from blake3 team", async () => {
78+
it('extendSecret should pass test with input length 1023 from blake3 team', async () => {
7979
const message = getBuffer(1023);
8080
const result = await getHash(1048, [message]);
8181
const testResult = new Uint8Array(
8282
Buffer.from(
83-
"10108970eeda3eb932baac1428c7a2163b0e924c9a9e25b35bba72b28f70bd11a182d27a591b05592b15607500e1e8dd56bc6c7fc063715b7a1d737df5bad3339c56778957d870eb9717b57ea3d9fb68d1b55127bba6a906a4a24bbd5acb2d123a37b28f9e9a81bbaae360d58f85e5fc9d75f7c370a0cc09b6522d9c8d822f2f28f485",
84-
"hex",
83+
'10108970eeda3eb932baac1428c7a2163b0e924c9a9e25b35bba72b28f70bd11a182d27a591b05592b15607500e1e8dd56bc6c7fc063715b7a1d737df5bad3339c56778957d870eb9717b57ea3d9fb68d1b55127bba6a906a4a24bbd5acb2d123a37b28f9e9a81bbaae360d58f85e5fc9d75f7c370a0cc09b6522d9c8d822f2f28f485',
84+
'hex',
8585
),
8686
);
8787
expect(result).toStrictEqual(testResult);
8888
});
8989

90-
it("extendSecret should pass test with input length 102400 from blake3 team", async () => {
90+
it('extendSecret should pass test with input length 102400 from blake3 team', async () => {
9191
const message = getBuffer(102400);
9292
const result = await getHash(1048, [message]);
9393
const testResult = new Uint8Array(
9494
Buffer.from(
95-
"bc3e3d41a1146b069abffad3c0d44860cf664390afce4d9661f7902e7943e085e01c59dab908c04c3342b816941a26d69c2605ebee5ec5291cc55e15b76146e6745f0601156c3596cb75065a9c57f35585a52e1ac70f69131c23d611ce11ee4ab1ec2c009012d236648e77be9295dd0426f29b764d65de58eb7d01dd42248204f45f8e",
96-
"hex",
95+
'bc3e3d41a1146b069abffad3c0d44860cf664390afce4d9661f7902e7943e085e01c59dab908c04c3342b816941a26d69c2605ebee5ec5291cc55e15b76146e6745f0601156c3596cb75065a9c57f35585a52e1ac70f69131c23d611ce11ee4ab1ec2c009012d236648e77be9295dd0426f29b764d65de58eb7d01dd42248204f45f8e',
96+
'hex',
9797
),
9898
);
9999
expect(result).toStrictEqual(testResult);

tests/core/keyWrapper.test.ts

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
1-
import { describe, expect, it } from "vitest";
2-
import {
3-
wrapKey,
4-
unwrapKey,
5-
deriveWrappingKey,
6-
importWrappingKey,
7-
} from "../../src/core/keyWrapper";
8-
import { generateSymmetricCryptoKey } from "../../src/core/symmetric";
9-
import {
10-
KEY_WRAPPING_ALGORITHM,
11-
AES_KEY_BIT_LENGTH,
12-
} from "../../src/utils/constants";
13-
import { generateEccKeys } from "../../src/core/ecc";
14-
15-
describe("Test key wrapping functions", () => {
16-
it("should scuessfully derive wrapping key", async () => {
1+
import { describe, expect, it } from 'vitest';
2+
import { wrapKey, unwrapKey, deriveWrappingKey, importWrappingKey } from '../../src/core/keyWrapper';
3+
import { generateSymmetricCryptoKey } from '../../src/core/symmetric';
4+
import { KEY_WRAPPING_ALGORITHM, AES_KEY_BIT_LENGTH } from '../../src/utils/constants';
5+
import { generateEccKeys } from '../../src/core/ecc';
6+
7+
describe('Test key wrapping functions', () => {
8+
it('should scuessfully derive wrapping key', async () => {
179
const secret1 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1810
const secret2 = new Uint8Array([11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
1911

2012
const result = await deriveWrappingKey(secret1, secret2);
2113

2214
expect(result).toBeInstanceOf(CryptoKey);
2315
expect(result.extractable).toBeFalsy();
24-
expect(result.type).toBe("secret");
25-
expect(result.usages).toContain("wrapKey");
26-
expect(result.usages).toContain("unwrapKey");
16+
expect(result.type).toBe('secret');
17+
expect(result.usages).toContain('wrapKey');
18+
expect(result.usages).toContain('unwrapKey');
2719

2820
const alg = result.algorithm as AesKeyAlgorithm;
2921
expect(alg.name).toBe(KEY_WRAPPING_ALGORITHM);
3022
expect(alg.length).toBe(AES_KEY_BIT_LENGTH);
3123
});
3224

33-
it("should scuessfully wrap and unwrap key", async () => {
25+
it('should scuessfully wrap and unwrap key', async () => {
3426
const secret1 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
3527
const secret2 = new Uint8Array([11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
3628

@@ -42,47 +34,39 @@ describe("Test key wrapping functions", () => {
4234

4335
expect(result).toStrictEqual(encryptionKey);
4436
});
45-
it("should scuessfully import the key", async () => {
37+
it('should scuessfully import the key', async () => {
4638
const key = new Uint8Array(16);
4739
window.crypto.getRandomValues(key);
4840

4941
await expect(importWrappingKey(key)).resolves.toBeInstanceOf(CryptoKey);
5042
});
5143

52-
it("should throw error if cannot import wrapping key", async () => {
44+
it('should throw error if cannot import wrapping key', async () => {
5345
const bad_key = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
5446

55-
await expect(importWrappingKey(bad_key)).rejects.toThrowError(
56-
/Failed to import wrapping key:/,
57-
);
47+
await expect(importWrappingKey(bad_key)).rejects.toThrowError(/Failed to import wrapping key:/);
5848
});
5949

60-
it("should throw error if cannot unwrapKey key", async () => {
50+
it('should throw error if cannot unwrapKey key', async () => {
6151
const key_pair = await generateEccKeys();
6252
const bad_key = key_pair.privateKey;
6353

6454
const encrypted = new Uint8Array(16);
6555
window.crypto.getRandomValues(encrypted);
6656

67-
await expect(unwrapKey(encrypted, bad_key)).rejects.toThrowError(
68-
/Failed to unwrap key:/,
69-
);
57+
await expect(unwrapKey(encrypted, bad_key)).rejects.toThrowError(/Failed to unwrap key:/);
7058
});
7159

72-
it("should throw error if cannot wrap key", async () => {
60+
it('should throw error if cannot wrap key', async () => {
7361
const key_pair = await generateEccKeys();
7462
const bad_key = key_pair.privateKey;
7563

76-
await expect(wrapKey(bad_key, bad_key)).rejects.toThrowError(
77-
/Failed to wrap key:/,
78-
);
64+
await expect(wrapKey(bad_key, bad_key)).rejects.toThrowError(/Failed to wrap key:/);
7965
});
8066

81-
it("should throw error if secrets are of different length", async () => {
67+
it('should throw error if secrets are of different length', async () => {
8268
const ecc = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
8369
const kyber = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]);
84-
await expect(deriveWrappingKey(ecc, kyber)).rejects.toThrowError(
85-
/Failed to derive wrapping key:/,
86-
);
70+
await expect(deriveWrappingKey(ecc, kyber)).rejects.toThrowError(/Failed to derive wrapping key:/);
8771
});
8872
});

tests/core/kyber.test.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
import { describe, expect, it } from "vitest";
2-
import {
3-
generateKyberKeys,
4-
encapsulateKyber,
5-
decapsulateKyber,
6-
} from "../../src/core/kyber";
7-
import {
8-
KYBER_PUBLIC_KEY_LENGTH,
9-
KYBER_SECRET_KEY_LENGTH,
10-
KYBER_SEED_LENGTH,
11-
} from "../../src/utils/constants";
12-
13-
describe("Test kyber functions", () => {
14-
it("should generate keys sucessfully", async () => {
1+
import { describe, expect, it } from 'vitest';
2+
import { generateKyberKeys, encapsulateKyber, decapsulateKyber } from '../../src/core/kyber';
3+
import { KYBER_PUBLIC_KEY_LENGTH, KYBER_SECRET_KEY_LENGTH, KYBER_SEED_LENGTH } from '../../src/utils/constants';
4+
5+
describe('Test kyber functions', () => {
6+
it('should generate keys sucessfully', async () => {
157
const keys = generateKyberKeys();
168

17-
expect(keys).toHaveProperty("publicKey");
18-
expect(keys).toHaveProperty("secretKey");
9+
expect(keys).toHaveProperty('publicKey');
10+
expect(keys).toHaveProperty('secretKey');
1911
expect(keys.publicKey.length).toBe(KYBER_PUBLIC_KEY_LENGTH);
2012
expect(keys.secretKey.length).toBe(KYBER_SECRET_KEY_LENGTH);
2113
});
2214

23-
it("should generate identical keys for identical seeds", async () => {
15+
it('should generate identical keys for identical seeds', async () => {
2416
const seed = new Uint8Array(KYBER_SEED_LENGTH);
2517
window.crypto.getRandomValues(seed);
2618
const keys1 = generateKyberKeys(seed);
2719
const keys2 = generateKyberKeys(seed);
2820

2921
expect(keys1).toStrictEqual(keys2);
3022
});
31-
it("should generate different keys for different seeds", async () => {
23+
it('should generate different keys for different seeds', async () => {
3224
const seed1 = new Uint8Array(KYBER_SEED_LENGTH);
3325
window.crypto.getRandomValues(seed1);
3426
const keys1 = generateKyberKeys(seed1);
@@ -40,7 +32,7 @@ describe("Test kyber functions", () => {
4032
expect(keys1).not.toStrictEqual(keys2);
4133
});
4234

43-
it("should sucessfully encapsulate and decapsulate", async () => {
35+
it('should sucessfully encapsulate and decapsulate', async () => {
4436
const keys = generateKyberKeys();
4537
const { cipherText, sharedSecret } = encapsulateKyber(keys.publicKey);
4638
const result = decapsulateKyber(cipherText, keys.secretKey);

0 commit comments

Comments
 (0)