fix(mobile): offer linked identity import when only other backups exist (#9053)

A fresh phone signing into an account linked to identity A gets a
misleading identity-mismatch error when the account has only a backup
for identity B. The existing import option was offered only when the
entire backup list was empty.

Offer the same import option whenever the linked identity has no listed
backup. Import still rejects a different key, requires the existing
backup-consent step, and prohibits creating a replacement identity. This
fallback does not change account bindings or automatically recover a
private key that was never backed up.

Updated against main `6dbd159676908806109f23d1964159d96a35760a`,
preserving the consent flow added since the original PR.

Validation:
- Both focused files passed with public Builderlab onboarding enabled:
67 tests. The journey covers empty and unrelated backups, wrong-key
rejection, and matching-key import after “Back up and continue.”
- In an isolated source tree with separate Git metadata and build
output, restoring the old production condition failed the
unrelated-backup journey (`blocked` instead of `setupIdentity`).
Restoring the fix passed all 42 journeys; restored source hashes match
the PR.
- Wes exercised the original preview's transition to the import screen
on November 4. This conflict repair preserves that production change; no
new device run was performed. That native evidence covers the screen
transition, not a completed real-account key import.
- Required pre-push checks passed, including mobile formatting/analysis,
the hook's mobile and crypto test suites, and file-size checks. [GitHub
CI passed](https://github.com/block/buzz/actions/runs/45211217031) on
`14e45a26e9873e75846e9a052f70bffd13139f6d`, including public-build tests
and the Android build. The conflict/consent review finding is addressed
in this revision.

Existing-user backup enrollment and automatic fresh-device recovery are
separate from this narrowly scoped fallback fix.

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz>
This commit is contained in:
Wes
2026-11-23 09:50:12 -07:00
committed by GitHub
parent 2e3bebe9b6
commit 0d4fd74ad6
3 changed files with 54 additions and 41 deletions

View File

@@ -206,7 +206,9 @@ class HostedIdentityService {
return _result(saved, bound, subject);
}
}
if (statusKeys.isEmpty && bound != null && !matchingDevice) {
// Backups for other identities cannot recover the account-bound key.
// Offer the same explicit import as an account with no backups.
if (bound != null && !statusKeys.contains(bound) && !matchingDevice) {
return HostedIdentityResult(
HostedIdentityState.needsSetup,
pubkey: bound,

View File

@@ -347,44 +347,53 @@ void main() {
});
}
journey('linked account without backup imports its key without replacing it', (
tester,
f,
) async {
await f.initialize(localIdentity: false);
f.offerProfile = false;
await f.mount(tester);
// Account restoration may resume independently of the Add choices.
await f.flow.signInAccount();
await f.settle(tester);
expect(f.flow.stage, HostedFlowStage.setupIdentity);
expect(f.probes, isEmpty);
expect(find.text('Create my Buzz identity'), findsNothing);
expect(find.text('Import existing identity'), findsOneWidget);
await f.tap(tester, 'Import existing identity');
await tester.enterText(
find.byType(TextField).hitTestable(),
f.secondKeys.nsec,
for (final hasUnrelatedBackup in [false, true]) {
journey(
'linked account imports its missing key (unrelated backup: $hasUnrelatedBackup)',
(tester, f) async {
await f.initialize(localIdentity: false);
f.offerProfile = false;
if (hasUnrelatedBackup) f.cloudKeys.add(f.secondKeys);
await f.mount(tester);
// Account restoration may resume independently of the Add choices.
await f.flow.signInAccount();
await f.settle(tester);
expect(f.flow.stage, HostedFlowStage.setupIdentity);
expect(f.probes, isEmpty);
expect(find.text('Create my Buzz identity'), findsNothing);
expect(find.text('Import existing identity'), findsOneWidget);
await f.tap(tester, 'Import existing identity');
await tester.enterText(
find.byType(TextField).hitTestable(),
f.secondKeys.nsec,
);
await f.tap(tester, 'Preview identity');
await f.tap(tester, 'Import this identity');
expect(
find.text(
'This key doesn’t match the identity linked to your Builderlab account.',
),
findsOneWidget,
);
expect(await f.store.read(), isNull);
expect(f.bound, f.keys.public);
await tester.enterText(
find.byType(TextField).hitTestable(),
f.keys.nsec,
);
await f.tap(tester, 'Preview identity');
await f.tap(tester, 'Import this identity');
expect(await f.store.read(), isNull);
await f.tap(tester, 'Back up and continue');
expect((await f.store.read())!.pubkey, f.keys.public);
expect((await f.store.read())!.backup, isNotNull);
expect(
f.requests.where((r) => r.url.path.endsWith('/recovery')),
isEmpty,
);
},
);
await f.tap(tester, 'Preview identity');
await f.tap(tester, 'Import this identity');
expect(
find.text(
'This key doesn’t match the identity linked to your Builderlab account.',
),
findsOneWidget,
);
expect(await f.store.read(), isNull);
expect(f.bound, f.keys.public);
await tester.enterText(find.byType(TextField).hitTestable(), f.keys.nsec);
await f.tap(tester, 'Preview identity');
await f.tap(tester, 'Import this identity');
expect(await f.store.read(), isNull);
await f.tap(tester, 'Back up and continue');
expect((await f.store.read())!.pubkey, f.keys.public);
expect((await f.store.read())!.backup, isNotNull);
expect(f.requests.where((r) => r.url.path.endsWith('/recovery')), isEmpty);
});
}
journey('system Back leaves community link entry', (tester, f) async {
await f.initialize();

View File

@@ -252,10 +252,12 @@ void main() {
test('missing bound backup never accepts a different selected key', () async {
bound = keys[2].public;
expect(
(await (await service()).resolve(selectedPubkey: keys[0].public)).state,
HostedIdentityState.mismatch,
final result = await (await service()).resolve(
selectedPubkey: keys[0].public,
);
expect(result.state, HostedIdentityState.needsSetup);
expect(result.pubkey, bound);
expect(result.canCreate, isFalse);
expect(await store.read(), isNull);
});