feat(identity): switch social identity, all from the one backup

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).
This commit is contained in:
vjrj 2026-07-10 20:20:04 +02:00
parent d36fd05741
commit 993f7b37ab
25 changed files with 597 additions and 33 deletions

View file

@ -16,6 +16,7 @@ import 'services/offer_outbox.dart';
import 'services/onboarding_store.dart';
import 'services/profile_cache.dart';
import 'services/profile_store.dart';
import 'services/social_account_store.dart';
import 'services/social_service.dart';
import 'services/social_settings.dart';
import 'state/inventory_cubit.dart';
@ -50,6 +51,7 @@ class TaneApp extends StatelessWidget {
this.messageStore,
this.profileStore,
this.profileCache,
this.socialAccounts,
this.inbox,
this.showIntro = false,
this.autoBackup,
@ -65,6 +67,7 @@ class TaneApp extends StatelessWidget {
messageStore,
profileStore,
profileCache,
socialAccounts,
inbox,
);
@ -92,6 +95,9 @@ class TaneApp extends StatelessWidget {
/// Optional cache of peers' published display names.
final ProfileCache? profileCache;
/// Optional store of the active social identity, for the profile switcher.
final SocialAccountStore? socialAccounts;
/// App-wide inbox listener; drives the messages list's live refresh.
final InboxService? inbox;
final bool showIntro;
@ -112,6 +118,7 @@ class TaneApp extends StatelessWidget {
MessageStore? messageStore,
ProfileStore? profileStore,
ProfileCache? profileCache,
SocialAccountStore? socialAccounts,
InboxService? inbox,
) {
return GoRouter(
@ -157,13 +164,17 @@ class TaneApp extends StatelessWidget {
inbox: inbox,
),
),
if (social != null && socialSettings != null && profileStore != null)
if (social != null &&
socialSettings != null &&
profileStore != null &&
socialAccounts != null)
GoRoute(
path: '/profile',
builder: (context, state) => ProfileScreen(
social: social,
settings: socialSettings,
profileStore: profileStore,
accounts: socialAccounts,
),
),
if (social != null && socialSettings != null)