mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 09:07:40 +00:00
* refactor(remote): one paired E2EE handshake core for desktop, CLI, web and mobile clients Every paired client now builds its hello, checks the host's ready, seals its auth frame and opens host frames through src/shared/paired-e2ee-client-handshake. Platforms inject their own NaCl/base64 primitives. The v2 client session and its pure-JS key schedule (@noble/hashes 1.8.0, the version mobile pins) move to src/shared, and the per-host v2 latch policy is shared with an injected store. No wire change: frames match the captured legacy and v2 fixtures byte for byte, and a cross-version test drives the core against the released host and the released client against this host. The auth step is now async so a device-key signer can slot in later. * fix(remote): keep @noble/hashes out of the CLI's unbundled runtime The packaged CLI loads src/shared output from disk, so a bare @noble/hashes import failed the packaged-runtime check. The v2 key schedule is now a primitive: Node clients use the node:crypto schedule (moved to src/shared so the CLI can reach it), while the browser and phone keep the pure-JS one. * fix(mobile): re-check the v2 latch before sending a legacy auth frame The auth step is async, so another socket can latch the host to v2 while a legacy auth frame is being sealed. Refuse it at send time, as before. --------- Co-authored-by: m4air <m4air@Mac.localdomain>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { createRemoteRuntimeClientHandshake } from './remote-runtime-client-handshake'
|
|
import {
|
|
parseRemoteRuntimeRpcFrame,
|
|
remoteRuntimeAuthReplyError,
|
|
remoteRuntimeReadyError,
|
|
REMOTE_RUNTIME_JSON_STRUCTURE_LIMITS
|
|
} from './remote-runtime-request-frames'
|
|
|
|
const HOST_PUBLIC_KEY_B64 = Buffer.alloc(32, 9).toString('base64')
|
|
|
|
describe('remote runtime JSON frame admission', () => {
|
|
it('preserves valid handshake and RPC frames', () => {
|
|
const handshake = createRemoteRuntimeClientHandshake(HOST_PUBLIC_KEY_B64)
|
|
expect(remoteRuntimeReadyError(handshake.acceptReadyText('{"type":"e2ee_ready"}'))).toBeNull()
|
|
expect(
|
|
remoteRuntimeAuthReplyError(handshake.classifyAuthReply('{"type":"e2ee_authenticated"}'))
|
|
).toBeNull()
|
|
expect(parseRemoteRuntimeRpcFrame('{"_keepalive":true}')).toEqual({ type: 'keepalive' })
|
|
})
|
|
|
|
it('rejects excessive nesting before JSON.parse', () => {
|
|
const handshake = createRemoteRuntimeClientHandshake(HOST_PUBLIC_KEY_B64)
|
|
const parseSpy = vi.spyOn(JSON, 'parse')
|
|
try {
|
|
const depth = REMOTE_RUNTIME_JSON_STRUCTURE_LIMITS.nestingDepth + 1
|
|
const amplified = `${'['.repeat(depth)}0${']'.repeat(depth)}`
|
|
|
|
expect(remoteRuntimeReadyError(handshake.acceptReadyText(amplified))).toMatchObject({
|
|
code: 'invalid_runtime_response'
|
|
})
|
|
expect(parseSpy).not.toHaveBeenCalled()
|
|
} finally {
|
|
parseSpy.mockRestore()
|
|
}
|
|
})
|
|
})
|