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}$/) + }) +})