Import packages/crypto/tests/crypto.test.ts
This commit is contained in:
parent
e359a57888
commit
c64d5c9604
|
|
@ -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}$/)
|
||||
})
|
||||
})
|
||||
Loading…
Reference in New Issue