From c64d5c9604eb9e008bd97702e1641791cd22f746 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:45:12 +0800 Subject: [PATCH] Import packages/crypto/tests/crypto.test.ts --- packages/crypto/tests/crypto.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/crypto/tests/crypto.test.ts diff --git a/packages/crypto/tests/crypto.test.ts b/packages/crypto/tests/crypto.test.ts new file mode 100644 index 0000000..b93203c --- /dev/null +++ b/packages/crypto/tests/crypto.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from 'vitest' +import { decryptFrame, deriveSharedKey, encryptFrame, generateKeyPair, identityFingerprint } from '../src/index.js' + +describe('secure channel primitives', () => { + it('derives matching shared keys and decrypts a frame', () => { + const host = generateKeyPair() + const client = generateKeyPair() + const hostKey = deriveSharedKey(host.privateKey, client.publicKey) + const clientKey = deriveSharedKey(client.privateKey, host.publicKey) + expect(Buffer.from(hostKey).equals(Buffer.from(clientKey))).toBe(true) + + const plaintext = new TextEncoder().encode('hello remote') + const frame = encryptFrame(hostKey, plaintext) + expect(new TextDecoder().decode(decryptFrame(clientKey, frame))).toBe('hello remote') + expect(identityFingerprint(host.publicKey)).toMatch(/^[A-F0-9]{12}$/) + }) +})