mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 20:06:10 +00:00
* fix(runtime): a device removed on disk stops authenticating at the next check Auth checks (token validate, device-key lookup, per-request principal recheck) now stat orca-devices.json and, when it changed since this process last read it, re-read and merge it the same way a save does. An unchanged file costs one stat; an unreadable or corrupt one changes nothing. * fix(runtime): check the device file before handing out a pairing offer A pending offer an admin removed on disk is never shown as a QR. The auth-time re-read also skips while this process's own quarantine is the reason the file is missing.
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { randomBytes, randomUUID } from 'node:crypto'
|
|
import type { DeviceScope } from '../../shared/runtime-types'
|
|
import type { RuntimePairingReach } from '../../shared/runtime-pairing-reach'
|
|
import type { TokenDeviceEntry } from './device-entry'
|
|
import { validGrants } from './device-registry-row-validation'
|
|
import type { RuntimeDeviceGrant } from './rpc/rpc-method-permission'
|
|
|
|
export function mintDeviceCredential(): { deviceId: string; token: string } {
|
|
return { deviceId: randomUUID(), token: randomBytes(24).toString('hex') }
|
|
}
|
|
|
|
/** A never-seen token row; it authenticates only once the registry persists it. */
|
|
export function mintTokenDevice(
|
|
name: string,
|
|
scope: DeviceScope,
|
|
pairingReach: RuntimePairingReach,
|
|
grants: readonly RuntimeDeviceGrant[]
|
|
): TokenDeviceEntry {
|
|
const validatedGrants = validGrants(grants, scope)
|
|
return {
|
|
...mintDeviceCredential(),
|
|
name,
|
|
scope,
|
|
pairedAt: Date.now(),
|
|
lastSeenAt: 0,
|
|
pairingReach,
|
|
...(validatedGrants ? { grants: validatedGrants } : {})
|
|
}
|
|
}
|