feat(ext/sw): device management — devices.ts + router handlers
Adds readDevices, addDevice, revokeDevice helpers that read/write .relicario/devices.json. Router handlers: list_devices, add_device, revoke_device. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import type { GitHost } from '../git-host';
|
||||
import { createGitHost, base64ToUint8Array } from '../git-host';
|
||||
import * as vault from '../vault';
|
||||
import * as session from '../session';
|
||||
import * as devices from '../devices';
|
||||
|
||||
// --- Shared ambient state owned by the SW module ---
|
||||
//
|
||||
@@ -291,10 +292,30 @@ export async function handle(
|
||||
}
|
||||
}
|
||||
|
||||
// Handlers for these cases are added in Tasks 3–5.
|
||||
case 'list_devices':
|
||||
case 'add_device':
|
||||
case 'revoke_device':
|
||||
case 'list_devices': {
|
||||
if (!state.gitHost) return { ok: false, error: 'vault_locked' };
|
||||
const list = await devices.readDevices(state.gitHost);
|
||||
return { ok: true, data: { devices: list } };
|
||||
}
|
||||
|
||||
case 'add_device': {
|
||||
if (!state.gitHost) return { ok: false, error: 'vault_locked' };
|
||||
const device = {
|
||||
name: msg.name,
|
||||
public_key: msg.public_key,
|
||||
added_at: Math.floor(Date.now() / 1000),
|
||||
};
|
||||
await devices.addDevice(state.gitHost, device);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
case 'revoke_device': {
|
||||
if (!state.gitHost) return { ok: false, error: 'vault_locked' };
|
||||
await devices.revokeDevice(state.gitHost, msg.name);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
// Handlers for these cases are added in Tasks 4–5.
|
||||
case 'list_trashed':
|
||||
case 'restore_item':
|
||||
case 'purge_item':
|
||||
|
||||
Reference in New Issue
Block a user