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:
parent
d36fd05741
commit
993f7b37ab
25 changed files with 597 additions and 33 deletions
|
|
@ -59,6 +59,21 @@ void main() {
|
|||
expect(await store.history('peer'), hasLength(2));
|
||||
});
|
||||
|
||||
test('per-identity scope isolates conversations (0 = legacy keys)', () async {
|
||||
final secret = InMemorySecretStore();
|
||||
final acct0 = MessageStore(secret); // legacy / account 0
|
||||
final acct1 = MessageStore(secret, accountScope: 'acct1');
|
||||
|
||||
await acct0.append('peer', msg('peer', 'for identity 0', 1000));
|
||||
await acct1.append('peer', msg('peer', 'for identity 1', 2000));
|
||||
|
||||
// Same peer, but each identity sees only its own conversation.
|
||||
expect((await acct0.history('peer')).single.text, 'for identity 0');
|
||||
expect((await acct1.history('peer')).single.text, 'for identity 1');
|
||||
expect((await acct0.conversations()).single.lastText, 'for identity 0');
|
||||
expect((await acct1.conversations()).single.lastText, 'for identity 1');
|
||||
});
|
||||
|
||||
test('history is capped to the most recent 200', () async {
|
||||
for (var i = 0; i < 210; i++) {
|
||||
await store.append('peer', msg('me', 'm$i', i));
|
||||
|
|
|
|||
44
apps/app_seeds/test/services/social_account_store_test.dart
Normal file
44
apps/app_seeds/test/services/social_account_store_test.dart
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/services/social_account_store.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
void main() {
|
||||
test('defaults to account 0 with no max created yet', () async {
|
||||
final store = SocialAccountStore(InMemorySecretStore());
|
||||
expect(await store.active(), 0);
|
||||
expect(await store.maxCreated(), 0);
|
||||
});
|
||||
|
||||
test('createNew increments the max and makes it active', () async {
|
||||
final store = SocialAccountStore(InMemorySecretStore());
|
||||
expect(await store.createNew(), 1);
|
||||
expect(await store.active(), 1);
|
||||
expect(await store.maxCreated(), 1);
|
||||
|
||||
expect(await store.createNew(), 2);
|
||||
expect(await store.active(), 2);
|
||||
expect(await store.maxCreated(), 2);
|
||||
});
|
||||
|
||||
test('setActive can switch back to an earlier identity, keeping the max',
|
||||
() async {
|
||||
final store = SocialAccountStore(InMemorySecretStore());
|
||||
await store.createNew(); // 1
|
||||
await store.createNew(); // 2
|
||||
await store.setActive(0); // back to the original
|
||||
expect(await store.active(), 0);
|
||||
expect(await store.maxCreated(), 2); // still remembers we made 3 identities
|
||||
});
|
||||
|
||||
test('a negative account is rejected', () async {
|
||||
final store = SocialAccountStore(InMemorySecretStore());
|
||||
expect(() => store.setActive(-1), throwsArgumentError);
|
||||
});
|
||||
|
||||
test('scope: account 0 uses legacy (empty) keys, others are namespaced', () {
|
||||
expect(socialAccountScope(0), '');
|
||||
expect(socialAccountScope(1), 'acct1');
|
||||
expect(socialAccountScope(2), 'acct2');
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue