Files
flit/pwa/src/pairing/keyring.ts
Fredrik Johansson 488431eaec Add per-peer auto-accept, disconnect, copy snip, and add-by-ID
- Auto-accept toggle per trusted peer (keyring.autoAccept); only
  activates when peer is cryptographically verified — unverified
  connections always prompt regardless of setting
- Disconnect button on connected screen returns to idle with full
  state reset
- Copy snip: copies own peer ID as a flit-peer:<base64> string for
  sharing out-of-band (no QR needed for initial pairing)
- Add peer by ID: paste a raw hex peer ID or flit-peer: snip in
  Invite new tab to add directly to keyring and connect without QR
- Own peer ID always visible at bottom of idle screen
- Restructured known-device row for mobile: secondary actions
  (Auto/Rename/Forget) on top line, Connect full-width below

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 17:07:11 +02:00

39 lines
1.2 KiB
TypeScript

// 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
autoAccept?: boolean
}
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))
}
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))
}
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)
}
export function shouldAutoAccept(id: string): boolean {
return listTrusted().some(p => p.id === id && p.autoAccept === true)
}