WIP V improve UX [snapshot task 2]

Add the connections workspace (sidebar, editable slots, per-slot activity,
removal dialog with focus wrapping), remove the downloadable local HTML and
unreleased identity backup/restore, and start the 0.0.5 draft changelog.
Restore the released 0.0.3/0.0.4 changelog entries. Enable focus emulation
in browser checks so background tabs receive focus/blur events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-17 13:44:08 +02:00
1 parent 58c3e2af86
commit 5f8c6a1916
21 files changed
+879 -306

No files matched your search

+4 -33
View File
@@ -20,9 +20,9 @@ export function parseHello(value: unknown): IdentityHello {
return { key: value.key as string, nonce: value.nonce as string };
}
export async function createIdentity(): Promise<Identity> {
// Extractable for explicit password-encrypted backups. Stored as a CryptoKey,
// never plaintext JSON. Same-origin JavaScript can still use/export this key.
const pair = await crypto.subtle.generateKey(curve, true, ['sign', 'verify']);
// Store the private key as a non-extractable CryptoKey. Same-origin JavaScript
// can still use it to sign, so the app code must remain trusted.
const pair = await crypto.subtle.generateKey(curve, false, ['sign', 'verify']);
return { publicKey: hex(await crypto.subtle.exportKey('raw', pair.publicKey)), privateKey: pair.privateKey };
}
export function hello(identity: Identity): IdentityHello {
@@ -75,7 +75,7 @@ export async function loadIdentityState(): Promise<IdentityState> {
validateContacts(state.contacts);
if (state.identity) {
unhex(state.identity.publicKey, 65);
if (!(state.identity.privateKey instanceof CryptoKey) || state.identity.privateKey.type !== 'private') throw new Error('Stored identity is invalid. Reset it or restore a backup.');
if (!(state.identity.privateKey instanceof CryptoKey) || state.identity.privateKey.type !== 'private') throw new Error('Stored identity is invalid. Clear device storage and create a new identity.');
}
return state;
} finally { db.close(); }
@@ -110,32 +110,3 @@ export async function clearIdentityStorage() {
});
} finally { db.close(); }
}
const iterations = 600000;
async function backupKey(password: string, salt: Uint8Array<ArrayBuffer>) {
if (password.length < 12 || password.length > 1024) throw new Error('Use a backup password between 12 and 1024 characters.');
const material = await crypto.subtle.importKey('raw', bytes(password), 'PBKDF2', false, ['deriveKey']);
return crypto.subtle.deriveKey({ name: 'PBKDF2', hash: 'SHA-256', salt, iterations }, material, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
}
export async function exportBackup(state: IdentityState, password: string) {
if (!state.identity) throw new Error('Create a device identity first.');
const salt = crypto.getRandomValues(new Uint8Array(16)), iv = crypto.getRandomValues(new Uint8Array(12));
const data = bytes(JSON.stringify({ key: await crypto.subtle.exportKey('jwk', state.identity.privateKey), publicKey: state.identity.publicKey, contacts: validateContacts(state.contacts) }));
const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv, additionalData: bytes('HellCon backup v1') }, await backupKey(password, salt), data);
return JSON.stringify({ format: 'hellcon-identity', version: 1, iterations, salt: hex(salt), iv: hex(iv), data: hex(encrypted) });
}
export async function importBackup(text: string, password: string): Promise<IdentityState> {
if (text.length > 100000) throw new Error('Backup is too large.');
try {
const value: unknown = JSON.parse(text);
if (!isRecord(value) || value.format !== 'hellcon-identity' || value.version !== 1 || value.iterations !== iterations || typeof value.data !== 'string' || value.data.length < 32) throw new Error();
const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: unhex(value.iv, 12), additionalData: bytes('HellCon backup v1') }, await backupKey(password, unhex(value.salt, 16)), unhex(value.data, value.data.length / 2));
const payload: unknown = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(decrypted));
if (!isRecord(payload) || !isRecord(payload.key)) throw new Error();
const publicKey = payload.publicKey as string;
const pub = await crypto.subtle.importKey('raw', unhex(publicKey, 65), curve, false, ['verify']);
const privateKey = await crypto.subtle.importKey('jwk', payload.key, curve, true, ['sign']);
const challenge = crypto.getRandomValues(new Uint8Array(32));
if (!await crypto.subtle.verify(signing, pub, await crypto.subtle.sign(signing, privateKey, challenge), challenge)) throw new Error();
return { identity: { publicKey, privateKey }, contacts: validateContacts(payload.contacts) };
} catch { throw new Error('Could not restore backup. Check the password and backup file.'); }
}