mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
Existing mobile identities entering the Builderlab hosted flow now require confirmation before the app reserves the account’s identity slot, binds the identity, or uploads its secret key. Cancelling leaves saved community keys usable and allows another identity to be selected, including after restart. Imported keys remain tentative until approval; paired keys remain safely retained outside the account slot. The confirmation shows the receiving account’s verified email and public key, explains that Builderlab can decrypt the backup and signed-in account users can recover it, and discloses that the app cannot change the linked identity later. **Cancel setup** stops future work without claiming to undo earlier binding or an upload whose acknowledgement was lost. The user can sign out; missing account identification blocks confirmation. Browser-initiated binding uses **Link and continue**, with explicit bind-only wording and no upload. Fresh keys generated in the current hosted attempt use ordinary onboarding without an extra backup prompt. Interrupted attempts without a confirmed backup ask again; approval is deliberately not persisted or carried across retries, cancellation, restart, account changes, or a replaced flow. Confirmed matching backup receipts skip the backup prompt. Cloud recovery and organization-managed backup are separate flows and are not changed here; this PR does not resolve server-side consent or recovery-authorization policy. Updated against main through `ce42853982` (#9418). Integration commit `dfb29fe5e7` includes the landed Hickory security fix and the shared workflow-test/runner repair. The consent implementation is unchanged from Carl’s reviewed `e11025ebed`; the CI merge preserves its configured public consent journeys. Validation at `e11025ebed`: 96 focused tests across eight files passed with public hosted domains configured; Flutter analysis passed. In an isolated source/Git/build copy, removing pre-adoption consent, bypassing the upload gate, and removing stale-confirmation checks each failed the consent journeys; restoring the code passed. Carl’s independent source review found no blockers. Mandatory hooks and hosted mobile CI passed, including both consent journeys in the configured public lane. Integration validation at `dfb29fe5e7`: 99 focused tests passed; one additional fullscreen-onboarding test failed its background community-admission assertion. An isolated clean-main control at `ce42853982` reproduces the same failure with the same expected/actual values. All consent journeys passed. Required commit and push hooks passed, including mobile analysis and the broader default mobile suite. Hosted CI is green at `dfb29fe5e7` ([run 43320753801](https://github.com/block/buzz/actions/runs/43320753801)). Security and the previously failing Rust/workflow gates now pass. The Mobile Checks log confirms both consent journeys executed successfully; that run has no pending checks. Review follow-up `ac9ac9be35`, integrated with main `279a31daac` at current head `1acfd2dff6`, is test-only: the browser journey now restores a saved account key without a receipt, cancels without binding, restarts and requires explicit approval before `/verify`. Both consent journeys passed again after integration using the updated CI settings. Disabling only the production bind gate in an isolated source/Git/build copy now fails the added step; restoring it passes. Mandatory commit/push hooks passed. Hosted CI is green at `1acfd2dff6` ([run 43343333843](https://github.com/block/buzz/actions/runs/43343333843)); no failing or pending checks remain. The Mobile Checks log confirms both consent journeys executed successfully, including the extended browser-binding journey. Carl’s latest review on `dfb29fe5e7` found no production blockers; its recommended test gap is addressed by this follow-up. Native-device and human acceptance have not been recorded here; the author’s ready-for-review setting is preserved. Try it: with two saved self-hosted keys, connect to Builderlab, select A, cancel, restart, then select B. Check the receiving account and key before approval. Repeat with an imported/paired key and a browser bind link; cancel must not reserve or bind the new selection. After an interrupted upload, cancellation must describe that earlier effects may remain. Confirm that ordinary brand-new onboarding has no extra backup step. --------- Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz>
363 lines
15 KiB
Dart
363 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||
|
||
import '../../shared/hosted/hosted_flow.dart';
|
||
import '../../shared/hosted/hosted_environment.dart';
|
||
import '../../shared/widgets/onboarding_step_page.dart';
|
||
import '../../shared/widgets/bee_loading_mark.dart';
|
||
import '../../shared/widgets/onboarding_loading_page.dart';
|
||
import '../../shared/identity_transfer/nsec_import_sheet.dart';
|
||
import '../../shared/hosted/hosted_flow_problem_message.dart';
|
||
import '../../shared/utils/string_utils.dart';
|
||
import '../../shared/theme/grid.dart';
|
||
import '../../shared/theme/theme_extensions.dart';
|
||
import 'hosted_community_selection.dart';
|
||
import 'hosted_join_policy_view.dart';
|
||
import 'hosted_profile_setup.dart';
|
||
|
||
/// Presents the app-scoped real flow without retaining credentials or keys.
|
||
class HostedConnectSheet extends HookConsumerWidget {
|
||
const HostedConnectSheet({
|
||
super.key,
|
||
required this.flow,
|
||
this.onAddCommunity,
|
||
this.fullScreen = false,
|
||
this.onBack,
|
||
this.presentedStage,
|
||
});
|
||
final HostedFlow flow;
|
||
final VoidCallback? onAddCommunity;
|
||
final bool fullScreen;
|
||
final VoidCallback? onBack;
|
||
final HostedFlowStage? presentedStage;
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
useListenable(flow);
|
||
final stage = presentedStage ?? flow.stage;
|
||
final showLinkedIdentity = useState(false);
|
||
Future<void> importIdentity() async {
|
||
Future<void>? pendingImport;
|
||
Future<void> save(String nsec) =>
|
||
pendingImport = flow.importIdentity(nsec);
|
||
const mismatch =
|
||
'This key doesn’t match the identity linked to your Builderlab account.';
|
||
if (fullScreen) {
|
||
await Navigator.of(context).push<bool>(
|
||
CupertinoPageRoute(
|
||
builder: (_) => NsecImportSheet(
|
||
onImport: save,
|
||
mismatchMessage: mismatch,
|
||
fullScreen: true,
|
||
),
|
||
),
|
||
);
|
||
} else {
|
||
await showNsecImportSheet(
|
||
context,
|
||
mismatchMessage: mismatch,
|
||
onImport: save,
|
||
);
|
||
}
|
||
// Dismissing the sheet does not cancel a secure-store write in flight.
|
||
// Finish that operation before resuming, even when the modal returned null.
|
||
if (pendingImport == null) return;
|
||
try {
|
||
await pendingImport;
|
||
} catch (_) {
|
||
return; // The sheet already presented the import failure.
|
||
}
|
||
if (context.mounted && flow.stage == HostedFlowStage.setupIdentity) {
|
||
await flow.retry();
|
||
}
|
||
}
|
||
|
||
final actionStyle = FilledButton.styleFrom(
|
||
minimumSize: const Size.fromHeight(52),
|
||
shape: const StadiumBorder(),
|
||
);
|
||
final working = stage == HostedFlowStage.working;
|
||
final message = switch (stage) {
|
||
HostedFlowStage.idle => 'Continue connecting your account.',
|
||
HostedFlowStage.working =>
|
||
flow.addingCommunityName == null
|
||
? 'Securing your account and finding communities…'
|
||
: 'Adding ${flow.addingCommunityName}…',
|
||
HostedFlowStage.setupIdentity =>
|
||
flow.requiredIdentityPubkey == null
|
||
? flow.canCreateIdentity
|
||
? 'Create a new Buzz identity, or import the identity you already use.'
|
||
: 'Bring your existing Buzz identity from your other device.'
|
||
: 'Your identity hasn’t been backed up yet. Bring it from your other device to keep using the same Buzz account.',
|
||
HostedFlowStage.confirmBackup =>
|
||
flow.bindingOnly
|
||
? 'Link this identity to the receiving Builderlab account? '
|
||
'This app cannot change the linked identity later. '
|
||
'No backup is uploaded by this browser handoff. '
|
||
'Cancelling stops setup; it does not undo any earlier linking.'
|
||
: 'Allow Builderlab to link this identity to your account and upload '
|
||
'an encrypted copy of your secret key (nsec) to '
|
||
'${HostedEnvironment.origin.host}? Builderlab can decrypt this backup. '
|
||
'Anyone signed in to this account can recover the key and use your '
|
||
'identity, including on self-hosted relays. '
|
||
'This app cannot change the linked identity later. '
|
||
'Joining requires a backup. Cancelling stops setup; it does not undo '
|
||
'any earlier linking or upload, including an upload whose confirmation was lost.',
|
||
HostedFlowStage.chooseCommunities => 'Select a community',
|
||
HostedFlowStage.communityConflict =>
|
||
'${flow.addingCommunityName} is already saved with a different identity. '
|
||
'Keep that identity and skip this addition, or return to your choices?',
|
||
HostedFlowStage.chooseIdentity =>
|
||
flow.identityChoices.where((choice) => choice.fromCloud).length > 1
|
||
? 'Choose a backed-up identity to connect to Builderlab. Your other backups and saved community keys will be kept. This app cannot change the selected Builderlab identity later.'
|
||
: flow.identityChoices.any((choice) => choice.fromCloud)
|
||
? 'Use your Builderlab identity on this device? It differs from your saved community identities. Those keys and your cloud backups will be kept. This app cannot change the selected Builderlab identity later.'
|
||
: 'Choose the identity to connect to Builderlab${flow.canCreateIdentity ? ', or create a new one' : ''}. It will be bound to your account and backed up. Existing keys will be kept. This app cannot change the selected Builderlab identity later.',
|
||
HostedFlowStage.profile =>
|
||
'What should people in this community call you? You can add a photo in Settings.',
|
||
HostedFlowStage.acceptPolicy =>
|
||
'Review this community’s terms and privacy policy before joining.',
|
||
HostedFlowStage.signIn => 'Complete sign-in in your browser.',
|
||
HostedFlowStage.browserReturned =>
|
||
'Continue setup in your browser. Open your community in Buzz when it is ready.',
|
||
HostedFlowStage.complete => 'Your community is ready.',
|
||
HostedFlowStage.blocked => hostedFlowProblemMessage(flow.problem),
|
||
};
|
||
if (fullScreen && stage == HostedFlowStage.chooseCommunities) {
|
||
return HostedCommunitySelection(
|
||
flow: flow,
|
||
fullScreen: true,
|
||
onAddCommunity: onAddCommunity,
|
||
onBack: onBack,
|
||
);
|
||
}
|
||
if (fullScreen &&
|
||
stage == HostedFlowStage.acceptPolicy &&
|
||
flow.joinPolicy != null) {
|
||
return HostedJoinPolicyView(
|
||
key: ValueKey(flow.joinPolicy!.version),
|
||
policy: flow.joinPolicy!,
|
||
onAccept: flow.acceptJoinPolicy,
|
||
fullScreen: true,
|
||
onBack: onBack,
|
||
);
|
||
}
|
||
final children = <Widget>[
|
||
if (!fullScreen && stage == HostedFlowStage.setupIdentity) ...[
|
||
Text(
|
||
flow.requiredIdentityPubkey == null
|
||
? flow.canCreateIdentity
|
||
? 'Create or import a Buzz identity'
|
||
: 'Import your Buzz identity'
|
||
: 'Bring your identity with you',
|
||
style: context.textTheme.titleLarge?.copyWith(
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
),
|
||
const SizedBox(height: Grid.twelve),
|
||
],
|
||
if (!fullScreen) Text(message, style: context.textTheme.bodyLarge),
|
||
const SizedBox(height: Grid.sm),
|
||
if (stage == HostedFlowStage.confirmBackup) ...[
|
||
Text(
|
||
flow.backupAccountEmail == null
|
||
? 'We couldn’t identify the receiving account. Sign out and sign in again before continuing.'
|
||
: 'Receiving account: ${flow.backupAccountEmail}',
|
||
style: context.textTheme.bodyLarge,
|
||
),
|
||
const SizedBox(height: Grid.twelve),
|
||
SelectableText(
|
||
fullNpub(flow.backupPubkey ?? '') ?? '',
|
||
style: context.textTheme.bodySmall,
|
||
),
|
||
const SizedBox(height: Grid.twelve),
|
||
FilledButton(
|
||
style: actionStyle,
|
||
onPressed: flow.confirmBackup,
|
||
child: Text(
|
||
flow.bindingOnly ? 'Link and continue' : 'Back up and continue',
|
||
),
|
||
),
|
||
TextButton(
|
||
style: actionStyle,
|
||
onPressed: () => flow.leave(),
|
||
child: const Text('Cancel setup'),
|
||
),
|
||
TextButton(
|
||
style: actionStyle,
|
||
onPressed: flow.signOutAccount,
|
||
child: const Text('Sign out'),
|
||
),
|
||
],
|
||
for (final choice in flow.identityChoices)
|
||
Padding(
|
||
padding: const EdgeInsets.only(bottom: Grid.sm),
|
||
child: OutlinedButton(
|
||
onPressed: () => flow.chooseIdentity(choice.pubkey),
|
||
child: Padding(
|
||
padding: const EdgeInsets.all(Grid.sm),
|
||
child: Column(
|
||
children: [
|
||
Text(choice.label),
|
||
Text(fullNpub(choice.pubkey) ?? choice.pubkey),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
if (stage == HostedFlowStage.chooseIdentity && flow.canCreateIdentity)
|
||
FilledButton(
|
||
style: actionStyle,
|
||
onPressed: flow.createIdentity,
|
||
child: const Text('Create a new identity'),
|
||
),
|
||
if (stage == HostedFlowStage.setupIdentity) ...[
|
||
if (flow.canCreateIdentity) ...[
|
||
FilledButton(
|
||
style: actionStyle,
|
||
onPressed: flow.createIdentity,
|
||
child: const Text('Create my Buzz identity'),
|
||
),
|
||
const SizedBox(height: Grid.xxs),
|
||
],
|
||
FilledButton(
|
||
style: actionStyle.copyWith(
|
||
backgroundColor: WidgetStatePropertyAll(context.colors.primary),
|
||
foregroundColor: WidgetStatePropertyAll(context.colors.onPrimary),
|
||
),
|
||
onPressed: importIdentity,
|
||
child: const Text('Import existing identity'),
|
||
),
|
||
const SizedBox(height: Grid.twelve),
|
||
Text(
|
||
flow.bindingOnly
|
||
? 'This links the identity to your Builderlab account. This app cannot change it later. No backup is uploaded by this browser handoff.'
|
||
: 'New identities are linked to your Builderlab account and backed up automatically. This app cannot change the linked identity later. Existing keys require confirmation before backup.',
|
||
textAlign: TextAlign.center,
|
||
style: context.textTheme.bodySmall,
|
||
),
|
||
if (flow.requiredIdentityPubkey != null) ...[
|
||
const SizedBox(height: Grid.xxs),
|
||
TextButton(
|
||
onPressed: () =>
|
||
showLinkedIdentity.value = !showLinkedIdentity.value,
|
||
child: Text(
|
||
showLinkedIdentity.value
|
||
? 'Hide linked identity'
|
||
: 'View linked identity',
|
||
),
|
||
),
|
||
if (showLinkedIdentity.value)
|
||
SelectableText(
|
||
fullNpub(flow.requiredIdentityPubkey!) ??
|
||
flow.requiredIdentityPubkey!,
|
||
style: context.textTheme.bodySmall,
|
||
),
|
||
],
|
||
],
|
||
if (stage == HostedFlowStage.profile && flow.saveProfile != null)
|
||
HostedProfileSetup(save: flow.saveProfile!, skip: flow.finishProfile),
|
||
if (stage == HostedFlowStage.acceptPolicy && flow.joinPolicy != null)
|
||
HostedJoinPolicyView(
|
||
key: ValueKey(flow.joinPolicy!.version),
|
||
policy: flow.joinPolicy!,
|
||
onAccept: flow.acceptJoinPolicy,
|
||
),
|
||
if (stage == HostedFlowStage.chooseCommunities)
|
||
HostedCommunitySelection(flow: flow, onAddCommunity: onAddCommunity),
|
||
if (stage == HostedFlowStage.communityConflict)
|
||
FilledButton(
|
||
onPressed: flow.skipConflictingCommunity,
|
||
child: const Text('Keep saved identity and skip'),
|
||
),
|
||
if (flow.canChooseDifferentIdentity)
|
||
FilledButton(
|
||
onPressed: flow.chooseDifferentIdentity,
|
||
child: const Text('Choose a different identity'),
|
||
),
|
||
if (flow.canSkipFailedCommunity)
|
||
TextButton(
|
||
onPressed: flow.skipFailedCommunity,
|
||
child: const Text('Skip this community'),
|
||
),
|
||
if (flow.canChangeCommunities)
|
||
TextButton(
|
||
onPressed: flow.backToCommunityChoices,
|
||
child: const Text('Back to choices'),
|
||
),
|
||
if ((stage == HostedFlowStage.blocked ||
|
||
stage == HostedFlowStage.communityConflict) &&
|
||
flow.addedCommunityCount > 0)
|
||
Text(
|
||
'${flow.addedCommunityCount} '
|
||
'${flow.addedCommunityCount == 1 ? "community" : "communities"} added and kept.'
|
||
'${flow.canRetry && stage == HostedFlowStage.blocked ? " Retry continues the remaining additions." : ""}',
|
||
),
|
||
if (working && !fullScreen) const Center(child: BeeLoadingMark()),
|
||
if (!working &&
|
||
stage != HostedFlowStage.profile &&
|
||
stage != HostedFlowStage.acceptPolicy &&
|
||
stage != HostedFlowStage.chooseIdentity &&
|
||
stage != HostedFlowStage.setupIdentity &&
|
||
stage != HostedFlowStage.confirmBackup &&
|
||
stage != HostedFlowStage.chooseCommunities &&
|
||
stage != HostedFlowStage.communityConflict &&
|
||
stage != HostedFlowStage.complete &&
|
||
stage != HostedFlowStage.browserReturned &&
|
||
flow.canRetry)
|
||
FilledButton(
|
||
onPressed: flow.retry,
|
||
child: Text(
|
||
stage == HostedFlowStage.signIn ? 'Start login again' : 'Try again',
|
||
),
|
||
),
|
||
];
|
||
if (!fullScreen) {
|
||
return SingleChildScrollView(
|
||
padding: const EdgeInsets.all(Grid.gutter),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: children,
|
||
),
|
||
);
|
||
}
|
||
final title = switch (stage) {
|
||
HostedFlowStage.setupIdentity =>
|
||
flow.requiredIdentityPubkey == null
|
||
? flow.canCreateIdentity
|
||
? 'Create or import a Buzz identity'
|
||
: 'Import your Buzz identity'
|
||
: 'Bring your identity with you',
|
||
HostedFlowStage.confirmBackup =>
|
||
flow.bindingOnly ? 'Link your identity?' : 'Back up your secret key?',
|
||
HostedFlowStage.chooseIdentity => 'Choose your identity',
|
||
HostedFlowStage.working =>
|
||
flow.addingCommunityName == null
|
||
? 'Getting ready…'
|
||
: 'Joining your community',
|
||
HostedFlowStage.blocked =>
|
||
flow.failedCommunityName == null
|
||
? 'Let’s try that again'
|
||
: 'Couldn’t open ${flow.failedCommunityName}',
|
||
HostedFlowStage.communityConflict => 'Keep your saved identity',
|
||
HostedFlowStage.browserReturned => 'Continue in your browser',
|
||
_ => 'Connect to Builderlab',
|
||
};
|
||
if (working) return OnboardingLoadingPage(title: title, onCancel: onBack);
|
||
bool isAction(Widget widget) => widget is ButtonStyleButton;
|
||
return OnboardingStepPage(
|
||
title: title,
|
||
subtitle: message,
|
||
onBack: onBack ?? () {},
|
||
content: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: children.where((widget) => !isAction(widget)).toList(),
|
||
),
|
||
actions: children.where(isAction).toList(),
|
||
);
|
||
}
|
||
}
|