@thenewlabs/entangle-crypto 1.0.0 → 2.0.1
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/dist/index.d.ts +50 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +79 -7
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -167
- package/dist/index.test.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,15 @@ export interface DerivedKeys {
|
|
|
2
2
|
K_enc: Uint8Array;
|
|
3
3
|
K_auth: Uint8Array;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* AEAD direction discriminator. Bound into the AAD of every frame so a
|
|
7
|
+
* ciphertext produced for one direction can never be reflected back and
|
|
8
|
+
* accepted in the other direction (both peers share the same K_enc).
|
|
9
|
+
*/
|
|
10
|
+
export declare enum AeadDir {
|
|
11
|
+
ServerToClient = 1,// agent -> invoker
|
|
12
|
+
ClientToServer = 2
|
|
13
|
+
}
|
|
5
14
|
export declare function initCrypto(): Promise<void>;
|
|
6
15
|
export declare function extractSaltFromCapId(capId: string): Uint8Array;
|
|
7
16
|
export declare function generateCapId(): {
|
|
@@ -9,16 +18,55 @@ export declare function generateCapId(): {
|
|
|
9
18
|
saltCap: Uint8Array;
|
|
10
19
|
};
|
|
11
20
|
export declare function generateSecret(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Derive the root key material from the capability secret. This is the
|
|
23
|
+
* expensive Argon2id step; callers should run it once per connection and
|
|
24
|
+
* reuse the returned `K_raw` for both bootstrap and session key derivation.
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveKeyMaterial(S: Uint8Array | string, saltCap: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
/**
|
|
28
|
+
* Bootstrap keys — derived purely from the capability secret, identical for
|
|
29
|
+
* every session. Used ONLY to authenticate AUTH1 and to protect the AUTH2
|
|
30
|
+
* handshake message that carries the fresh session nonces. Never used for
|
|
31
|
+
* command data.
|
|
32
|
+
*/
|
|
33
|
+
export declare function deriveBootstrapKeys(K_raw: Uint8Array): DerivedKeys;
|
|
34
|
+
/**
|
|
35
|
+
* Per-session keys — bound to the fresh handshake nonces (nonceB from the
|
|
36
|
+
* client, nonceC from the agent). Because both nonces are random per
|
|
37
|
+
* connection, every session gets distinct K_enc/K_auth, so ciphertext
|
|
38
|
+
* captured from one session cannot be replayed into another (each side's
|
|
39
|
+
* counters also reset per session). This is what actually defeats the
|
|
40
|
+
* cross-session replay / stale-output-injection attack.
|
|
41
|
+
*/
|
|
42
|
+
export declare function deriveSessionKeys(K_raw: Uint8Array, nonceB: string, nonceC: string): DerivedKeys;
|
|
43
|
+
/**
|
|
44
|
+
* Convenience: bootstrap keys directly from the secret. Kept for callers that
|
|
45
|
+
* only need the capability-static keys (e.g. AUTH1 HMAC before nonces exist).
|
|
46
|
+
*/
|
|
12
47
|
export declare function deriveKeys(S: Uint8Array | string, saltCap: Uint8Array): Promise<DerivedKeys>;
|
|
13
48
|
export interface AeadEncResult {
|
|
14
49
|
nonce: Uint8Array;
|
|
15
50
|
cipher: Uint8Array;
|
|
16
51
|
}
|
|
17
|
-
|
|
18
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Canonical AAD for a frame: binds both the frame type and the direction so
|
|
54
|
+
* a peer can never accept its own ciphertext reflected back.
|
|
55
|
+
*/
|
|
56
|
+
export declare function frameAad(type: number, dir: AeadDir): Uint8Array;
|
|
57
|
+
export declare function aeadEncrypt(K_enc: Uint8Array, type: number, ctr: number, plaintext: any, dir: AeadDir): AeadEncResult;
|
|
58
|
+
export declare function aeadDecrypt(K_enc: Uint8Array, type: number, nonce: Uint8Array, cipher: Uint8Array, dir: AeadDir): {
|
|
19
59
|
ctr: number;
|
|
20
60
|
msg: any;
|
|
21
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Password hashing for the optional second-factor. Uses Argon2id with a
|
|
64
|
+
* random salt (via libsodium's crypto_pwhash_str), so the stored value is not
|
|
65
|
+
* a password-equivalent secret and cracking a leaked value is expensive.
|
|
66
|
+
*/
|
|
67
|
+
export declare function hashPassword(password: string): Promise<string>;
|
|
68
|
+
/** Constant-time verification of a password against a stored Argon2id hash. */
|
|
69
|
+
export declare function verifyPassword(storedHash: string, password: string): Promise<boolean>;
|
|
22
70
|
export declare function computeHmac(K_auth: Uint8Array, data: Uint8Array): Uint8Array;
|
|
23
71
|
export declare function verifyHmac(K_auth: Uint8Array, data: Uint8Array, mac: Uint8Array): boolean;
|
|
24
72
|
export declare function sha256Hex(text: string): string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;CACpB;AAID,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAKhD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAY9D;AAED,wBAAgB,aAAa,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,CAUtE;AAED,wBAAgB,cAAc,IAAI,MAAM,CAGvC;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED;;;;GAIG;AACH,oBAAY,OAAO;IACjB,cAAc,IAAI,CAAE,mBAAmB;IACvC,cAAc,IA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;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,CAa3B;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOpE;AAED,+EAA+E;AAC/E,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO3F;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAE5E;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAGzF;AAGD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAUxD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAcvD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,CAI9C;AAED,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,16 @@ import { sha256 } from '@noble/hashes/sha256';
|
|
|
4
4
|
import { hmac } from '@noble/hashes/hmac';
|
|
5
5
|
import { encode, decode } from 'cborg';
|
|
6
6
|
import { CRYPTO_PARAMS } from '@thenewlabs/entangle-protocol';
|
|
7
|
+
/**
|
|
8
|
+
* AEAD direction discriminator. Bound into the AAD of every frame so a
|
|
9
|
+
* ciphertext produced for one direction can never be reflected back and
|
|
10
|
+
* accepted in the other direction (both peers share the same K_enc).
|
|
11
|
+
*/
|
|
12
|
+
export var AeadDir;
|
|
13
|
+
(function (AeadDir) {
|
|
14
|
+
AeadDir[AeadDir["ServerToClient"] = 1] = "ServerToClient";
|
|
15
|
+
AeadDir[AeadDir["ClientToServer"] = 2] = "ClientToServer";
|
|
16
|
+
})(AeadDir || (AeadDir = {}));
|
|
7
17
|
let sodiumReady = false;
|
|
8
18
|
export async function initCrypto() {
|
|
9
19
|
if (!sodiumReady) {
|
|
@@ -39,29 +49,91 @@ export function generateSecret() {
|
|
|
39
49
|
const secret = sodium.randombytes_buf(32);
|
|
40
50
|
return base64UrlEncode(secret);
|
|
41
51
|
}
|
|
42
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Derive the root key material from the capability secret. This is the
|
|
54
|
+
* expensive Argon2id step; callers should run it once per connection and
|
|
55
|
+
* reuse the returned `K_raw` for both bootstrap and session key derivation.
|
|
56
|
+
*/
|
|
57
|
+
export async function deriveKeyMaterial(S, saltCap) {
|
|
43
58
|
await initCrypto();
|
|
44
59
|
const secretBytes = typeof S === 'string' ? base64UrlDecode(S) : S;
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
return sodium.crypto_pwhash(32, secretBytes, saltCap, sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE, sodium.crypto_pwhash_ALG_ARGON2ID13);
|
|
61
|
+
}
|
|
62
|
+
function hkdfKeys(K_raw, salt, info) {
|
|
63
|
+
const derived = hkdf(sha256, K_raw, salt, new TextEncoder().encode(info), 64);
|
|
47
64
|
return {
|
|
48
65
|
K_enc: derived.slice(0, 32),
|
|
49
66
|
K_auth: derived.slice(32, 64),
|
|
50
67
|
};
|
|
51
68
|
}
|
|
52
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Bootstrap keys — derived purely from the capability secret, identical for
|
|
71
|
+
* every session. Used ONLY to authenticate AUTH1 and to protect the AUTH2
|
|
72
|
+
* handshake message that carries the fresh session nonces. Never used for
|
|
73
|
+
* command data.
|
|
74
|
+
*/
|
|
75
|
+
export function deriveBootstrapKeys(K_raw) {
|
|
76
|
+
return hkdfKeys(K_raw, new Uint8Array(0), 'entangle-capability');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Per-session keys — bound to the fresh handshake nonces (nonceB from the
|
|
80
|
+
* client, nonceC from the agent). Because both nonces are random per
|
|
81
|
+
* connection, every session gets distinct K_enc/K_auth, so ciphertext
|
|
82
|
+
* captured from one session cannot be replayed into another (each side's
|
|
83
|
+
* counters also reset per session). This is what actually defeats the
|
|
84
|
+
* cross-session replay / stale-output-injection attack.
|
|
85
|
+
*/
|
|
86
|
+
export function deriveSessionKeys(K_raw, nonceB, nonceC) {
|
|
87
|
+
const salt = new TextEncoder().encode(`${nonceB}|${nonceC}`);
|
|
88
|
+
return hkdfKeys(K_raw, salt, 'entangle-session-v2');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Convenience: bootstrap keys directly from the secret. Kept for callers that
|
|
92
|
+
* only need the capability-static keys (e.g. AUTH1 HMAC before nonces exist).
|
|
93
|
+
*/
|
|
94
|
+
export async function deriveKeys(S, saltCap) {
|
|
95
|
+
const K_raw = await deriveKeyMaterial(S, saltCap);
|
|
96
|
+
return deriveBootstrapKeys(K_raw);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Canonical AAD for a frame: binds both the frame type and the direction so
|
|
100
|
+
* a peer can never accept its own ciphertext reflected back.
|
|
101
|
+
*/
|
|
102
|
+
export function frameAad(type, dir) {
|
|
103
|
+
return encode({ type, dir });
|
|
104
|
+
}
|
|
105
|
+
export function aeadEncrypt(K_enc, type, ctr, plaintext, dir) {
|
|
53
106
|
const nonce = sodium.randombytes_buf(CRYPTO_PARAMS.NONCE_BYTES);
|
|
54
|
-
const aad =
|
|
107
|
+
const aad = frameAad(type, dir);
|
|
55
108
|
const pt = encode({ ctr, msg: plaintext });
|
|
56
109
|
const cipher = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(pt, aad, null, nonce, K_enc);
|
|
57
110
|
return { nonce, cipher };
|
|
58
111
|
}
|
|
59
|
-
export function aeadDecrypt(K_enc, type, nonce, cipher) {
|
|
60
|
-
const aad =
|
|
112
|
+
export function aeadDecrypt(K_enc, type, nonce, cipher, dir) {
|
|
113
|
+
const aad = frameAad(type, dir);
|
|
61
114
|
const pt = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(null, cipher, aad, nonce, K_enc);
|
|
62
115
|
const decoded = decode(pt);
|
|
63
116
|
return decoded;
|
|
64
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Password hashing for the optional second-factor. Uses Argon2id with a
|
|
120
|
+
* random salt (via libsodium's crypto_pwhash_str), so the stored value is not
|
|
121
|
+
* a password-equivalent secret and cracking a leaked value is expensive.
|
|
122
|
+
*/
|
|
123
|
+
export async function hashPassword(password) {
|
|
124
|
+
await initCrypto();
|
|
125
|
+
return sodium.crypto_pwhash_str(password, sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE);
|
|
126
|
+
}
|
|
127
|
+
/** Constant-time verification of a password against a stored Argon2id hash. */
|
|
128
|
+
export async function verifyPassword(storedHash, password) {
|
|
129
|
+
await initCrypto();
|
|
130
|
+
try {
|
|
131
|
+
return sodium.crypto_pwhash_str_verify(storedHash, password);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
65
137
|
export function computeHmac(K_auth, data) {
|
|
66
138
|
return hmac(sha256, K_auth, data);
|
|
67
139
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,O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
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"clean": "rm -rf dist",
|
|
9
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
10
10
|
"prepublishOnly": "npm run build"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@noble/hashes": "^1.8.0",
|
|
14
|
-
"@thenewlabs/entangle-protocol": "^
|
|
14
|
+
"@thenewlabs/entangle-protocol": "^2.0.1",
|
|
15
15
|
"cborg": "^4.5.8",
|
|
16
16
|
"libsodium-wrappers-sumo": "^0.8.4"
|
|
17
17
|
},
|
package/dist/index.test.d.ts
DELETED
package/dist/index.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
package/dist/index.test.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll } from 'vitest';
|
|
2
|
-
import { initCrypto, generateCapId, generateSecret, extractSaltFromCapId, deriveKeys, aeadEncrypt, aeadDecrypt, computeHmac, verifyHmac, base64UrlEncode, base64UrlDecode, hashPolicy, } from './index.js';
|
|
3
|
-
describe('Crypto Package', () => {
|
|
4
|
-
beforeAll(async () => {
|
|
5
|
-
await initCrypto();
|
|
6
|
-
});
|
|
7
|
-
describe('CapId generation', () => {
|
|
8
|
-
it('should generate valid capId with embedded salt', () => {
|
|
9
|
-
const { capId, saltCap } = generateCapId();
|
|
10
|
-
expect(capId).toBeTruthy();
|
|
11
|
-
expect(saltCap).toHaveLength(16);
|
|
12
|
-
const extracted = extractSaltFromCapId(capId);
|
|
13
|
-
expect(extracted).toEqual(saltCap);
|
|
14
|
-
});
|
|
15
|
-
it('should generate unique capIds', () => {
|
|
16
|
-
const cap1 = generateCapId();
|
|
17
|
-
const cap2 = generateCapId();
|
|
18
|
-
expect(cap1.capId).not.toEqual(cap2.capId);
|
|
19
|
-
expect(cap1.saltCap).not.toEqual(cap2.saltCap);
|
|
20
|
-
});
|
|
21
|
-
it('should fail on invalid capId length', () => {
|
|
22
|
-
expect(() => extractSaltFromCapId('short')).toThrow('Invalid capId length');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe('Secret generation', () => {
|
|
26
|
-
it('should generate base64url encoded secrets', () => {
|
|
27
|
-
const secret = generateSecret();
|
|
28
|
-
expect(secret).toBeTruthy();
|
|
29
|
-
expect(secret).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
30
|
-
const decoded = base64UrlDecode(secret);
|
|
31
|
-
expect(decoded).toHaveLength(32);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe('Key derivation', () => {
|
|
35
|
-
it('should derive consistent keys from same inputs', async () => {
|
|
36
|
-
const secret = generateSecret();
|
|
37
|
-
const { saltCap } = generateCapId();
|
|
38
|
-
const keys1 = await deriveKeys(secret, saltCap);
|
|
39
|
-
const keys2 = await deriveKeys(secret, saltCap);
|
|
40
|
-
expect(keys1.K_enc).toEqual(keys2.K_enc);
|
|
41
|
-
expect(keys1.K_auth).toEqual(keys2.K_auth);
|
|
42
|
-
});
|
|
43
|
-
it('should derive different keys from different secrets', async () => {
|
|
44
|
-
const secret1 = generateSecret();
|
|
45
|
-
const secret2 = generateSecret();
|
|
46
|
-
const { saltCap } = generateCapId();
|
|
47
|
-
const keys1 = await deriveKeys(secret1, saltCap);
|
|
48
|
-
const keys2 = await deriveKeys(secret2, saltCap);
|
|
49
|
-
expect(keys1.K_enc).not.toEqual(keys2.K_enc);
|
|
50
|
-
expect(keys1.K_auth).not.toEqual(keys2.K_auth);
|
|
51
|
-
});
|
|
52
|
-
it('should derive different keys from different salts', async () => {
|
|
53
|
-
const secret = generateSecret();
|
|
54
|
-
const { saltCap: salt1 } = generateCapId();
|
|
55
|
-
const { saltCap: salt2 } = generateCapId();
|
|
56
|
-
const keys1 = await deriveKeys(secret, salt1);
|
|
57
|
-
const keys2 = await deriveKeys(secret, salt2);
|
|
58
|
-
expect(keys1.K_enc).not.toEqual(keys2.K_enc);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe('AEAD encryption', () => {
|
|
62
|
-
it('should encrypt and decrypt successfully', async () => {
|
|
63
|
-
const secret = generateSecret();
|
|
64
|
-
const { saltCap } = generateCapId();
|
|
65
|
-
const keys = await deriveKeys(secret, saltCap);
|
|
66
|
-
const plaintext = { test: 'data', number: 42 };
|
|
67
|
-
const type = 0x10;
|
|
68
|
-
const ctr = 1;
|
|
69
|
-
const { nonce, cipher } = aeadEncrypt(keys.K_enc, type, ctr, plaintext);
|
|
70
|
-
expect(nonce).toHaveLength(24);
|
|
71
|
-
expect(cipher).toBeTruthy();
|
|
72
|
-
const decrypted = aeadDecrypt(keys.K_enc, type, nonce, cipher);
|
|
73
|
-
expect(decrypted.ctr).toEqual(ctr);
|
|
74
|
-
expect(decrypted.msg).toEqual(plaintext);
|
|
75
|
-
});
|
|
76
|
-
it('should fail decryption with wrong key', async () => {
|
|
77
|
-
const secret1 = generateSecret();
|
|
78
|
-
const secret2 = generateSecret();
|
|
79
|
-
const { saltCap } = generateCapId();
|
|
80
|
-
const keys1 = await deriveKeys(secret1, saltCap);
|
|
81
|
-
const keys2 = await deriveKeys(secret2, saltCap);
|
|
82
|
-
const plaintext = { test: 'data' };
|
|
83
|
-
const { nonce, cipher } = aeadEncrypt(keys1.K_enc, 0x10, 1, plaintext);
|
|
84
|
-
expect(() => aeadDecrypt(keys2.K_enc, 0x10, nonce, cipher)).toThrow();
|
|
85
|
-
});
|
|
86
|
-
it('should fail decryption with wrong type', async () => {
|
|
87
|
-
const secret = generateSecret();
|
|
88
|
-
const { saltCap } = generateCapId();
|
|
89
|
-
const keys = await deriveKeys(secret, saltCap);
|
|
90
|
-
const plaintext = { test: 'data' };
|
|
91
|
-
const { nonce, cipher } = aeadEncrypt(keys.K_enc, 0x10, 1, plaintext);
|
|
92
|
-
expect(() => aeadDecrypt(keys.K_enc, 0x11, nonce, cipher)).toThrow();
|
|
93
|
-
});
|
|
94
|
-
it('should fail decryption with tampered cipher', async () => {
|
|
95
|
-
const secret = generateSecret();
|
|
96
|
-
const { saltCap } = generateCapId();
|
|
97
|
-
const keys = await deriveKeys(secret, saltCap);
|
|
98
|
-
const plaintext = { test: 'data' };
|
|
99
|
-
const { nonce, cipher } = aeadEncrypt(keys.K_enc, 0x10, 1, plaintext);
|
|
100
|
-
cipher[0] ^= 0xFF; // Tamper with first byte
|
|
101
|
-
expect(() => aeadDecrypt(keys.K_enc, 0x10, nonce, cipher)).toThrow();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
describe('HMAC', () => {
|
|
105
|
-
it('should compute and verify HMAC', async () => {
|
|
106
|
-
const secret = generateSecret();
|
|
107
|
-
const { saltCap } = generateCapId();
|
|
108
|
-
const keys = await deriveKeys(secret, saltCap);
|
|
109
|
-
const data = new TextEncoder().encode('test message');
|
|
110
|
-
const mac = computeHmac(keys.K_auth, data);
|
|
111
|
-
expect(mac).toHaveLength(32);
|
|
112
|
-
expect(verifyHmac(keys.K_auth, data, mac)).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
it('should fail verification with wrong key', async () => {
|
|
115
|
-
const secret1 = generateSecret();
|
|
116
|
-
const secret2 = generateSecret();
|
|
117
|
-
const { saltCap } = generateCapId();
|
|
118
|
-
const keys1 = await deriveKeys(secret1, saltCap);
|
|
119
|
-
const keys2 = await deriveKeys(secret2, saltCap);
|
|
120
|
-
const data = new TextEncoder().encode('test message');
|
|
121
|
-
const mac = computeHmac(keys1.K_auth, data);
|
|
122
|
-
expect(verifyHmac(keys2.K_auth, data, mac)).toBe(false);
|
|
123
|
-
});
|
|
124
|
-
it('should fail verification with tampered data', async () => {
|
|
125
|
-
const secret = generateSecret();
|
|
126
|
-
const { saltCap } = generateCapId();
|
|
127
|
-
const keys = await deriveKeys(secret, saltCap);
|
|
128
|
-
const data1 = new TextEncoder().encode('test message');
|
|
129
|
-
const data2 = new TextEncoder().encode('test message!');
|
|
130
|
-
const mac = computeHmac(keys.K_auth, data1);
|
|
131
|
-
expect(verifyHmac(keys.K_auth, data2, mac)).toBe(false);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe('Base64URL encoding', () => {
|
|
135
|
-
it('should encode and decode correctly', () => {
|
|
136
|
-
const data = new Uint8Array([1, 2, 3, 255, 0, 128]);
|
|
137
|
-
const encoded = base64UrlEncode(data);
|
|
138
|
-
expect(encoded).not.toContain('+');
|
|
139
|
-
expect(encoded).not.toContain('/');
|
|
140
|
-
expect(encoded).not.toContain('=');
|
|
141
|
-
const decoded = base64UrlDecode(encoded);
|
|
142
|
-
expect(decoded).toEqual(data);
|
|
143
|
-
});
|
|
144
|
-
it('should handle empty data', () => {
|
|
145
|
-
const data = new Uint8Array(0);
|
|
146
|
-
const encoded = base64UrlEncode(data);
|
|
147
|
-
const decoded = base64UrlDecode(encoded);
|
|
148
|
-
expect(decoded).toEqual(data);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
describe('Policy hashing', () => {
|
|
152
|
-
it('should hash policy consistently', () => {
|
|
153
|
-
const policy = { singleRun: true };
|
|
154
|
-
const hash1 = hashPolicy(policy);
|
|
155
|
-
const hash2 = hashPolicy(policy);
|
|
156
|
-
expect(hash1).toEqual(hash2);
|
|
157
|
-
});
|
|
158
|
-
it('should produce different hashes for different policies', () => {
|
|
159
|
-
const policy1 = { singleRun: true };
|
|
160
|
-
const policy2 = { singleRun: false };
|
|
161
|
-
const hash1 = hashPolicy(policy1);
|
|
162
|
-
const hash2 = hashPolicy(policy2);
|
|
163
|
-
expect(hash1).not.toEqual(hash2);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
//# sourceMappingURL=index.test.js.map
|
package/dist/index.test.js.map
DELETED
|
@@ -1 +0,0 @@
|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