mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
## Why Buzz mobile now checks who signed each edit before deciding what to show in a channel or thread. That includes edits to the first message of a thread loaded from local storage. Mobile also preserves the information needed to verify edits after an offline restart and retries missing profile lookups when the app reconnects. The companion relay change is #9886. ## Mechanism Mobile uses the first valid message reference on an edit and shows the newest edit that passes its checks. It accepts edits from the original message’s signer. If the relay signed the original, mobile also accepts edits from the author named by the relay. A verified agent owner can edit the agent’s chat messages (kinds 9 and 40002) and diff messages (kind 40008) in the same channel. **Agent owners.** Mobile verifies the owner named in the agent’s signed profile. The app reads permission when a user opens the channel or thread message menu or the image actions. The native photo viewer also reads permission when it opens and checks again before deleting. These paths and the timeline use the same signed profile to verify the owner. When an agent’s signed profile names an owner, mobile saves the signed event once and reads fields such as the name and avatar from it on restart. If that entry exceeds the 16 KiB limit, mobile saves the display fields alone if they fit. Mobile needs the signed profile to verify the owner. When the app connects, it asks for profiles needed to check edits in the current timeline and retries unresolved lookups on reconnect. The cache skips profiles it has already checked with the relay and public keys the relay recently reported as having no profile. Once mobile loads a newer profile from the relay that no longer names the owner, it stops applying that person’s edits. The next time that person opens the message menu, Edit is absent. In the device test, both changes took effect after restarting the app. **Relay signing key.** While connected, mobile looks up the key if the timeline contains an edit whose signer differs from the original message’s signer and the original has a public key in an `actor` or `p` tag. A mention in a `p` tag can also trigger the lookup. Mobile uses that tagged author only after confirming that the relay signed the original message. Mobile keeps the last key during reconnects and can read it from the saved-message store after an offline restart. If the timeline still needs the key when mobile reconnects, mobile refreshes it so a rotated key can take effect during the same session. A failed request or a response without a key leaves the previous key available. Thread summaries read the key available when they refresh and start no key lookup. ## What changed - Start with `edit_authority.dart` for the profile and key lookups and the permission check that runs when actions open. See `timeline_message.dart` for edit selection and `thread_detail_helpers.dart` for the first message of a thread loaded from local storage. - See `verified_profile_owner.dart` for ownership verification, `profile_snapshot.dart` for storage and restore, `user_cache_provider.dart` for profile refreshes, and `SavedMessageStore.relayAuthor` for the saved relay key. - Tests cover edit selection, owner edits to chat and diff messages, and edits to a saved thread’s first message after replies load. They also cover opening message and image actions, restored profiles without a signed copy and profiles signed by the wrong key, reconnect retries, offline reopening with a large signed profile, and a newly fetched relay key replacing a saved key. Tests also verify that the native photo viewer blocks deletion if permission is withdrawn while it is open, that opening message actions requests a fresh profile when the saved profile names the viewer as owner but lacks a signed copy, and that a tampered saved profile cannot verify ownership. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Stephen Edwards <sedwards@squareup.com>
60 lines
1.9 KiB
Dart
60 lines
1.9 KiB
Dart
import 'dart:isolate';
|
|
|
|
import '../crypto/nip_oa.dart';
|
|
import '../relay/nostr_models.dart';
|
|
import 'user_profile.dart';
|
|
|
|
/// A verified profile together with its NIP-01 replacement order.
|
|
typedef ParsedProfileEvent = ({
|
|
UserProfile profile,
|
|
int createdAt,
|
|
String eventId,
|
|
});
|
|
|
|
/// Parses and verifies profile history without blocking the UI isolate.
|
|
///
|
|
/// Capture only the event batch here, never a provider or its surrounding
|
|
/// context. NIP-OA verification performs synchronous elliptic-curve work.
|
|
Future<List<ParsedProfileEvent>> parseProfileEventBatch(
|
|
List<NostrEvent> events,
|
|
) => Isolate.run(() => _parseBatch(events));
|
|
|
|
List<ParsedProfileEvent> _parseBatch(List<NostrEvent> events) {
|
|
final latest = <String, NostrEvent>{};
|
|
for (final event in events) {
|
|
if (event.kind != 0) continue;
|
|
final pubkey = event.pubkey.toLowerCase();
|
|
final current = latest[pubkey];
|
|
if (current == null ||
|
|
event.createdAt > current.createdAt ||
|
|
(event.createdAt == current.createdAt &&
|
|
event.id.compareTo(current.id) < 0)) {
|
|
latest[pubkey] = event;
|
|
}
|
|
}
|
|
return [for (final event in latest.values) parseProfileEvent(event)];
|
|
}
|
|
|
|
/// Parses a single live profile, including its verified owner attribution.
|
|
ParsedProfileEvent parseProfileEvent(NostrEvent event) {
|
|
final data = ProfileData.fromEvent(event);
|
|
return (
|
|
profile: UserProfile(
|
|
pubkey: data.pubkey.toLowerCase(),
|
|
displayName: data.displayName,
|
|
avatarUrl: data.avatarUrl,
|
|
about: data.about,
|
|
nip05Handle: data.nip05,
|
|
ownerPubkey: verifiedOaOwnerPubkey(event.tags, event.pubkey),
|
|
ownerEvidence: carriesOwnerAttestation(event) ? event : null,
|
|
),
|
|
createdAt: event.createdAt,
|
|
eventId: event.id,
|
|
);
|
|
}
|
|
|
|
/// Whether [event] has an `auth` tag, so it is kept as owner evidence.
|
|
bool carriesOwnerAttestation(NostrEvent event) =>
|
|
event.kind == 0 &&
|
|
event.tags.any((tag) => tag.isNotEmpty && tag[0] == 'auth');
|