2026-06-30 19:23:04 +02:00
|
|
|
// Persistent trusted-peer list ("Add device" flow) — separate from the
|
|
|
|
|
// ephemeral one-shot QR room pairing in pairing/ephemeral.ts.
|
|
|
|
|
|
|
|
|
|
export interface TrustedPeer {
|
|
|
|
|
id: string // hex Ed25519 pubkey
|
|
|
|
|
label: string
|
|
|
|
|
addedAt: number
|
2026-07-01 17:07:11 +02:00
|
|
|
autoAccept?: boolean
|
2026-06-30 19:23:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const KEY = 'flit_keyring'
|
|
|
|
|
|
|
|
|
|
export function listTrusted(): TrustedPeer[] {
|
|
|
|
|
try { return JSON.parse(localStorage.getItem(KEY) ?? '[]') } catch { return [] }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function addTrusted(id: string, label: string): void {
|
|
|
|
|
const peers = listTrusted().filter(p => p.id !== id)
|
|
|
|
|
peers.push({ id, label, addedAt: Date.now() })
|
|
|
|
|
localStorage.setItem(KEY, JSON.stringify(peers))
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-01 17:07:11 +02:00
|
|
|
export function setAutoAccept(id: string, value: boolean): void {
|
|
|
|
|
const peers = listTrusted().map(p => p.id === id ? { ...p, autoAccept: value } : p)
|
|
|
|
|
localStorage.setItem(KEY, JSON.stringify(peers))
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-30 19:23:04 +02:00
|
|
|
export function removeTrusted(id: string): void {
|
|
|
|
|
localStorage.setItem(KEY, JSON.stringify(listTrusted().filter(p => p.id !== id)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isTrusted(id: string): boolean {
|
|
|
|
|
return listTrusted().some(p => p.id === id)
|
|
|
|
|
}
|
2026-07-01 17:07:11 +02:00
|
|
|
|
|
|
|
|
export function shouldAutoAccept(id: string): boolean {
|
|
|
|
|
return listTrusted().some(p => p.id === id && p.autoAccept === true)
|
|
|
|
|
}
|