Adds pseudonymous, switchable social identities derived from the SAME root seed via an account index (NostrKeyDerivation.deriveFromSeed(seed, account)). HKDF is one-way so accounts are unlinkable to the Ğ1 key; account 0 is the original identity, byte-for-byte unchanged (no rotation for current users), and every account regenerates from the single seed — so switching adds nothing to back up. - SocialAccountStore: keystore-backed active account + max created. - Per-identity stores (chats, profile, name cache) namespaced by account scope (account 0 = legacy keys, no migration) so identities never mix. - switchSocialAccount() re-derives the identity, re-scopes the stores and restarts the inbox listener; RestartWidget rebuilds the tree to pick up the new social singletons. DB/inventory untouched. - Profile 'Your identities' switcher: list, create, switch (with a note that messages/contacts are kept separate per identity). i18n en/es/pt/ast. Tests: account-indexed derivation (legacy 0 unchanged, accounts distinct yet deterministic, negatives rejected); SocialAccountStore; per-identity store scope isolation. Resolves the flagged 'change identity' decision (open-decisions §B). Known: switching resets navigation to home (full tree rebuild).
30 lines
1.2 KiB
Dart
30 lines
1.2 KiB
Dart
import '../security/secret_store.dart';
|
|
|
|
/// Remembers the display names peers have published (their NIP-01 kind:0
|
|
/// `name`), so the inbox and chat show a human name instead of a raw key —
|
|
/// even offline. Keystore-backed (no plaintext at rest).
|
|
class ProfileCache {
|
|
/// [accountScope] namespaces the keys per social identity (empty = the
|
|
/// original identity's legacy keys). See [socialAccountScope].
|
|
ProfileCache(this._store, {String accountScope = ''})
|
|
: _prefix = accountScope.isEmpty
|
|
? 'tane.social.name.'
|
|
: 'tane.social.$accountScope.name.';
|
|
|
|
final SecretStore _store;
|
|
final String _prefix;
|
|
|
|
/// The cached name for [pubkeyHex], or null if none is known.
|
|
Future<String?> name(String pubkeyHex) async {
|
|
final value = await _store.read('$_prefix$pubkeyHex');
|
|
return (value == null || value.isEmpty) ? null : value;
|
|
}
|
|
|
|
Future<void> setName(String pubkeyHex, String name) =>
|
|
_store.write('$_prefix$pubkeyHex', name.trim());
|
|
}
|
|
|
|
/// A compact, human-ish rendering of a public key when no name is known yet.
|
|
String shortPubkey(String pubkeyHex) => pubkeyHex.length <= 12
|
|
? pubkeyHex
|
|
: '${pubkeyHex.substring(0, 6)}…${pubkeyHex.substring(pubkeyHex.length - 4)}';
|