mirror of
https://github.com/block/buzz.git
synced 2026-11-25 02:31:36 +00:00
## Summary Ticket 7 of the [Android push plan](https://github.com/block/buzz/blob/main/PLANS/ANDROID_PUSH.md). Android phones can now enroll with the push gateway and publish a relay lease, through the same shared push layer iOS uses. The wake handling side is ticket 6, [#9804 Android push wake handling](https://github.com/block/buzz/pull/9804). - The phone gets an FCM token, then generates a sign-only P-256 Keystore key whose attestation challenge is the SHA-256 of the enrollment transcript. The chain goes to the gateway at enrollment. Every later installation call (delegate, rotate endpoint, revoke delegation, revoke installation) is signed with that key over the transcript bytes the gateway builds. - A rotated FCM token rotates the endpoint. Signing out revokes the delegation and the installation. The first enrollment waits a short random time. - Android 13+ asks for the notification permission at the same point iOS does. Declining keeps the app working. - A phone that cannot attest (no hardware attestation, unlocked bootloader, unlisted boot key) keeps working, and Settings says push is unavailable on this phone. - The relay lease keeps the fixed `transport` value iOS sends. - Firebase config is the same build-time setting [#9804 Android push wake handling](https://github.com/block/buzz/pull/9804) adds: four `BUZZ_FIREBASE_*` environment variables become the string resources Firebase reads. Nothing is committed, and builds without them still work (push reports unavailable). The Gradle hunks (permission, config block, `firebase-messaging` dependency) are copied from that PR verbatim so the two merge cleanly, including its `lifecycle-process` line, which this PR does not use. - The token and permission calls use their own `buzz/push_registration` channel, because Android's notification-open handler from that PR already owns `buzz/push` and a channel has one native handler. - The gateway gets an `enroll_android` transcript vector so Dart and Rust agree on the exact bytes. Enrollment state is journaled before each network attempt, so a lost response resumes with byte-identical requests instead of leaving an orphaned installation. ### Related issue None found. Builds on [#9560 enroll Android installations](https://github.com/block/buzz/pull/9560) and [#9562 verify Key Attestation](https://github.com/block/buzz/pull/9562). ### Validation Journey tests cover first enrollment, a second relay, reuse and renewal, lost responses, token rotation, an installation the gateway dropped, a lost Keystore key, a phone that cannot attest, and sign-out revocation, against a fake gateway that keeps the real gateway's semantics. Transcripts replay the shared vectors byte for byte. A settings journey checks the Notifications row and the unavailable row on Android, and a resume table checks the FCM token refresh: it runs while the relay reconnects, but not when push is off or the relay doesn't offer push. On a physical Pixel 9a (debug build, a local test gateway on a local Postgres, reached over `adb reverse`), the real Keystore key and hardware attestation chain enrolled and delegated, and the gateway accepted the attestation. The same session then ran: a signed delivery authorized against the delegation, endpoint rotation and re-delegation at the next epoch, rotating back, delegation revocation, installation revocation, and re-enrolling the same FCM token afterwards. The notification prompt appears when registration starts, before the token is fetched: <img src="https://github.com/user-attachments/assets/2aed92fe-20c1-4658-b990-51c3f3c96120" width="270" alt="Android notification permission prompt"> Not validated on the device: the FCM wake itself (the local gateway has no credentials to call FCM, so the delivery was authorized and then failed at the FCM hop), lease publication to a relay, and the in-app unavailable row, which only the widget tests exercise. A relay-backed run needs a signed-in test community on the phone. ### Settings while turning off Turning notifications off sends a relay tombstone. Until the relay accepts it, the row now says so, on both platforms. An Android build without a gateway also keeps a saved opt-in visible so it can still be turned off; once off, the row goes away. These are rendered from the Settings journey test. | | Before | After | |---|---|---| | Android build without a gateway, saved opt-in | <img src="https://raw.githubusercontent.com/block/buzz/47220acf78ad21639d2a3a8b79be3f0272e74db2/pr-9811--01-before-config-less.png" width="270" alt="Before: no Notifications row"> | <img src="https://raw.githubusercontent.com/block/buzz/47220acf78ad21639d2a3a8b79be3f0272e74db2/pr-9811--02-after-config-less.png" width="270" alt="After: Notifications row with the switch on"> | | After turning off, relay has not accepted yet | <img src="https://raw.githubusercontent.com/block/buzz/47220acf78ad21639d2a3a8b79be3f0272e74db2/pr-9811--03-before-turning-off.png" width="270" alt="Before: plain off switch"> | <img src="https://raw.githubusercontent.com/block/buzz/47220acf78ad21639d2a3a8b79be3f0272e74db2/pr-9811--04-after-turning-off.png" width="270" alt="After: Turning off. Notifications may continue until this finishes."> | ### Regressions - iOS enrollment is unchanged: the shared bridge only branches to the Dart authority on Android. iOS gains the pending opt-out subtitle, and its opt-out now also tombstones after a gateway change using the saved lease id. - The Android app gains the `firebase-messaging` dependency and a `POST_NOTIFICATIONS` permission. Backups exclude the push preferences file. ### Known limits - An FCM token rotation while the app is running is picked up on the next resume or launch, because the wake service owns the single messaging service. It could call into the registration plugin once both Android push PRs merge. - After an endpoint rotation, only the active community's lease is republished. Other enabled communities' grants are void until each is opened, the same way their leases lapse at grant expiry today. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
476 lines
18 KiB
Dart
476 lines
18 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:buzz/features/settings/settings_page.dart';
|
|
import 'package:buzz/shared/auth/auth_provider.dart';
|
|
import 'package:buzz/shared/community/community.dart';
|
|
import 'package:buzz/shared/community/community_provider.dart';
|
|
import 'package:buzz/shared/community/community_storage.dart';
|
|
import 'package:buzz/shared/push/dev_push_lease.dart';
|
|
import 'package:buzz/shared/push/push_bootstrap.dart';
|
|
import 'package:buzz/shared/push/push_lease_revocation_outbox.dart';
|
|
import 'package:buzz/shared/crypto/nip44.dart';
|
|
import 'package:buzz/shared/relay/nostr_models.dart';
|
|
import 'package:buzz/shared/push/android_push_authority.dart';
|
|
import 'package:buzz/shared/push/push_bridge.dart';
|
|
import 'package:buzz/shared/push/push_relay_capability_provider.dart';
|
|
import 'package:buzz/shared/push/push_subscription.dart';
|
|
import 'package:buzz/shared/relay/app_lifecycle_provider.dart';
|
|
import 'package:buzz/shared/relay/relay_provider.dart';
|
|
import 'package:buzz/shared/relay/relay_session.dart';
|
|
import 'package:buzz/shared/theme/theme.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
import 'package:nostr/nostr.dart' as nostr;
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../helpers/android_push_fakes.dart';
|
|
import '../../shared/community/community_storage_test.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
setUpAll(() async {
|
|
final fonts = FontLoader('Inter')
|
|
..addFont(rootBundle.load('assets/fonts/InterVariable.ttf'));
|
|
await fonts.load();
|
|
});
|
|
|
|
for (final attests in [true, false]) {
|
|
testWidgets(
|
|
attests
|
|
? 'an attesting Android phone enrolls and publishes its lease'
|
|
: 'an Android phone that cannot attest keeps working and says so',
|
|
(tester) async {
|
|
tester.view.physicalSize = const Size(375, 1800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
PackageInfo.setMockInitialValues(
|
|
appName: 'Buzz',
|
|
packageName: 'buzz',
|
|
version: '1.0.0',
|
|
buildNumber: '1',
|
|
buildSignature: '',
|
|
);
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storage = CommunityStorage(secure: FakeSecureStorage());
|
|
final subscriptions = [
|
|
BuzzPushSubscription(
|
|
filter: BuzzPushFilter(kinds: const [9], pTags: ['a' * 64]),
|
|
notificationClass: 'default',
|
|
),
|
|
];
|
|
final session = _Connected();
|
|
var advertised = _descriptor;
|
|
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
final gateway = FakePushGateway(nowSeconds: () => now);
|
|
debugAndroidPushAuthority = AndroidPushAuthority(
|
|
keystore: FakeAndroidKeystore()..attests = attests,
|
|
gateway: fakeGatewayClient(gateway),
|
|
store: _MemoryStore(),
|
|
sleep: (_) async {},
|
|
);
|
|
addTearDown(() {
|
|
debugAndroidPushAuthority = null;
|
|
fcmDeviceToken.value = null;
|
|
pushUnavailableReason.value = null;
|
|
pushEndpointGrants.value = const [];
|
|
});
|
|
fcmDeviceToken.value = 'test-fcm-token';
|
|
const nativePush = MethodChannel('buzz/push_registration');
|
|
final messenger =
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
messenger.setMockMethodCallHandler(
|
|
nativePush,
|
|
(call) async => switch (call.method) {
|
|
'startRegistration' || 'refreshToken' || 'syncPushSnapshot' => null,
|
|
_ => throw StateError('Unexpected native call ${call.method}'),
|
|
},
|
|
);
|
|
addTearDown(() => messenger.setMockMethodCallHandler(nativePush, null));
|
|
final community =
|
|
Community.create(
|
|
name: 'Team',
|
|
relayUrl: 'https://relay.example',
|
|
).copyWith(
|
|
nsec: nostr.Nip19.encode(
|
|
prefix: nostr.Nip19Prefix.nsec,
|
|
data: '1' * 64,
|
|
),
|
|
pushNotificationsEnabled: true,
|
|
pushLeaseInstallationId: 'd' * 32,
|
|
pushSubscriptionState: BuzzPushLeaseSubscriptionState.desired(
|
|
desired: subscriptions,
|
|
).withAccepted(subscriptions: subscriptions, generation: 7),
|
|
);
|
|
await storage.save(community);
|
|
await storage.saveActiveId(community.id);
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
authProvider.overrideWith(_Auth.new),
|
|
communityStorageProvider.overrideWithValue(storage),
|
|
communitySnapshotWriterProvider.overrideWithValue(
|
|
(communities) async {},
|
|
),
|
|
buzzPushLeaseRevocationStorageProvider.overrideWithValue(
|
|
BuzzPushLeaseRevocationStorage(secure: FakeSecureStorage()),
|
|
),
|
|
relaySessionProvider.overrideWith(() => session),
|
|
myPubkeyProvider.overrideWithValue(nostr.Keys('1' * 64).public),
|
|
buzzPushDescriptorFetcherProvider.overrideWithValue(
|
|
(_) async => advertised,
|
|
),
|
|
appLifecycleProvider.overrideWith(_Lifecycle.new),
|
|
],
|
|
child: BuzzPushBootstrap(
|
|
child: MaterialApp(
|
|
theme: AppTheme.light(),
|
|
home: SettingsPage(
|
|
profileHeader: const SizedBox.shrink(),
|
|
identityRecoveryPageBuilder: (_) => const SizedBox.shrink(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
// Notification settings exist on Android, and the app stays usable
|
|
// either way.
|
|
expect(
|
|
find.byKey(const ValueKey('push-notifications-setting')),
|
|
findsOneWidget,
|
|
);
|
|
expect(tester.widget<Switch>(find.byType(Switch)).value, isTrue);
|
|
expect(tester.takeException(), isNull);
|
|
if (attests) {
|
|
expect(find.byKey(const ValueKey('push-unavailable')), findsNothing);
|
|
expect(gateway.installations, hasLength(1));
|
|
expect(session.leases.last['active'], isTrue);
|
|
expect(session.leases.last['endpoint'], isNotEmpty);
|
|
|
|
// The relay reconnects advertising a new executor key: the old key's
|
|
// delegation is revoked while push stays on, and the lease carries a
|
|
// grant for the new key.
|
|
final oldExecutor = _descriptor.executorPubkey;
|
|
final newExecutor = nostr.Keys('3' * 64).public;
|
|
advertised = _descriptorFor(newExecutor);
|
|
session.executorSecret = '3' * 64;
|
|
final installationBefore = gateway.installations.values.single;
|
|
session.setStatus(SessionStatus.reconnecting);
|
|
await tester.pumpAndSettle();
|
|
session.setStatus(SessionStatus.connected);
|
|
await tester.pumpAndSettle();
|
|
expect(installationBefore.revokedDelegations, {'$oldExecutor/1'});
|
|
expect(installationBefore.delegations, contains(newExecutor));
|
|
expect(session.leases.last['endpoint'], contains(newExecutor));
|
|
|
|
// Turning push off keeps the installation: the community remains.
|
|
// Removing that community afterwards is what revokes it.
|
|
final installation = gateway.installations.values.single;
|
|
await tester.tap(find.byType(Switch));
|
|
await tester.pumpAndSettle();
|
|
expect(installation.revokedDelegations, isNotEmpty);
|
|
expect(installation.revoked, isFalse);
|
|
final container = ProviderScope.containerOf(
|
|
tester.element(find.byType(SettingsPage)),
|
|
);
|
|
await container
|
|
.read(communityListProvider.notifier)
|
|
.removeCommunity(community.id);
|
|
await tester.pumpAndSettle();
|
|
expect(installation.revoked, isTrue);
|
|
} else {
|
|
expect(
|
|
find.byKey(const ValueKey('push-unavailable')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.text('Push is unavailable on this phone'), findsOne);
|
|
expect(gateway.installations, isEmpty);
|
|
expect(session.leases.where((l) => l['active'] == true), isEmpty);
|
|
}
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pumpAndSettle();
|
|
// Foundation checks its debug variables before teardowns run.
|
|
debugDefaultTargetPlatformOverride = null;
|
|
},
|
|
);
|
|
}
|
|
|
|
// Mounts only the push bootstrap over a community with the given relay URL
|
|
// and opt-in, recording the native registration calls.
|
|
Future<List<String>> pumpBootstrap(
|
|
WidgetTester tester, {
|
|
required TargetPlatform platform,
|
|
required String relayUrl,
|
|
required bool enabled,
|
|
_Connected? session,
|
|
bool advertisesPush = true,
|
|
FakePushGateway? gateway,
|
|
Future<void>? descriptorGate,
|
|
List<BuzzPushSubscription>? subscriptions,
|
|
}) async {
|
|
debugDefaultTargetPlatformOverride = platform;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storage = CommunityStorage(secure: FakeSecureStorage());
|
|
final pushGateway =
|
|
gateway ??
|
|
FakePushGateway(
|
|
nowSeconds: () => DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
);
|
|
debugAndroidPushAuthority = AndroidPushAuthority(
|
|
keystore: FakeAndroidKeystore(),
|
|
gateway: fakeGatewayClient(pushGateway),
|
|
store: _MemoryStore(),
|
|
sleep: (_) async {},
|
|
);
|
|
addTearDown(() => debugAndroidPushAuthority = null);
|
|
var descriptorFetches = 0;
|
|
final calls = <String>[];
|
|
final messenger =
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
for (final channel in const [
|
|
MethodChannel('buzz/push_registration'),
|
|
MethodChannel('buzz/push'),
|
|
]) {
|
|
messenger.setMockMethodCallHandler(channel, (call) async {
|
|
calls.add(call.method);
|
|
return null;
|
|
});
|
|
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
|
}
|
|
final community = Community.create(name: 'Team', relayUrl: relayUrl)
|
|
.copyWith(
|
|
nsec: nostr.Nip19.encode(
|
|
prefix: nostr.Nip19Prefix.nsec,
|
|
data: '1' * 64,
|
|
),
|
|
pushNotificationsEnabled: enabled,
|
|
pushSubscriptionState: subscriptions == null
|
|
? null
|
|
: BuzzPushLeaseSubscriptionState.desired(desired: subscriptions),
|
|
);
|
|
await storage.save(community);
|
|
await storage.saveActiveId(community.id);
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
authProvider.overrideWith(_Auth.new),
|
|
communityStorageProvider.overrideWithValue(storage),
|
|
communitySnapshotWriterProvider.overrideWithValue(
|
|
(communities) async {},
|
|
),
|
|
buzzPushLeaseRevocationStorageProvider.overrideWithValue(
|
|
BuzzPushLeaseRevocationStorage(secure: FakeSecureStorage()),
|
|
),
|
|
relaySessionProvider.overrideWith(() => session ?? _Connected()),
|
|
myPubkeyProvider.overrideWithValue(nostr.Keys('1' * 64).public),
|
|
buzzPushDescriptorFetcherProvider.overrideWithValue((_) async {
|
|
// Discovery reads the descriptor first, which sets push up; the
|
|
// fetch that publication makes next is the one held back.
|
|
if (++descriptorFetches > 1) await descriptorGate;
|
|
if (!advertisesPush) throw const BuzzPushNotAdvertised();
|
|
return _descriptor;
|
|
}),
|
|
appLifecycleProvider.overrideWith(_Lifecycle.new),
|
|
],
|
|
child: const BuzzPushBootstrap(child: SizedBox()),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
return calls;
|
|
}
|
|
|
|
Future<void> unmount(WidgetTester tester) async {
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pumpAndSettle();
|
|
// Foundation checks its debug variables before teardowns run.
|
|
debugDefaultTargetPlatformOverride = null;
|
|
}
|
|
|
|
for (final platform in [TargetPlatform.android, TargetPlatform.iOS]) {
|
|
testWidgets('a relay URL with a path does not break push on $platform', (
|
|
tester,
|
|
) async {
|
|
await pumpBootstrap(
|
|
tester,
|
|
platform: platform,
|
|
relayUrl: 'https://relay.example/team',
|
|
enabled: true,
|
|
);
|
|
|
|
expect(tester.takeException(), isNull);
|
|
await unmount(tester);
|
|
});
|
|
}
|
|
|
|
for (final (name, enabled, advertisesPush) in [
|
|
('refreshes the FCM token', true, true),
|
|
('fetches no token while opted out', false, true),
|
|
('fetches no token for a relay without push', true, false),
|
|
]) {
|
|
testWidgets('resuming the app $name', (tester) async {
|
|
fcmDeviceToken.value = 'test-fcm-token';
|
|
addTearDown(() => fcmDeviceToken.value = null);
|
|
final calls = await pumpBootstrap(
|
|
tester,
|
|
platform: TargetPlatform.android,
|
|
relayUrl: 'https://relay.example',
|
|
enabled: enabled,
|
|
advertisesPush: advertisesPush,
|
|
);
|
|
calls.clear();
|
|
|
|
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
|
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(calls.contains('refreshToken'), enabled && advertisesPush);
|
|
await unmount(tester);
|
|
});
|
|
}
|
|
|
|
testWidgets('turning push off while its enrollment waits publishes nothing', (
|
|
tester,
|
|
) async {
|
|
fcmDeviceToken.value = 'test-fcm-token';
|
|
addTearDown(() => fcmDeviceToken.value = null);
|
|
final gateway = FakePushGateway(
|
|
nowSeconds: () => DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
);
|
|
final session = _Connected();
|
|
final descriptorGate = Completer<void>();
|
|
await pumpBootstrap(
|
|
tester,
|
|
platform: TargetPlatform.android,
|
|
relayUrl: 'https://relay.example',
|
|
enabled: true,
|
|
session: session,
|
|
gateway: gateway,
|
|
descriptorGate: descriptorGate.future,
|
|
subscriptions: [
|
|
BuzzPushSubscription(
|
|
filter: BuzzPushFilter(kinds: const [9], pTags: ['a' * 64]),
|
|
notificationClass: 'default',
|
|
),
|
|
],
|
|
);
|
|
final container = ProviderScope.containerOf(
|
|
tester.element(find.byType(BuzzPushBootstrap)),
|
|
);
|
|
final notifier = container.read(communityListProvider.notifier);
|
|
await notifier.setPushNotificationsEnabled(
|
|
container.read(communityListProvider).value!.single.id,
|
|
false,
|
|
);
|
|
|
|
// The descriptor arrives after the opt-out: nothing is enrolled, delegated
|
|
// or published for a community that no longer wants push.
|
|
descriptorGate.complete();
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.requests, isEmpty);
|
|
expect(session.leases.where((lease) => lease['active'] == true), isEmpty);
|
|
await unmount(tester);
|
|
});
|
|
|
|
testWidgets('resuming while the relay reconnects refreshes the FCM token', (
|
|
tester,
|
|
) async {
|
|
fcmDeviceToken.value = 'test-fcm-token';
|
|
addTearDown(() => fcmDeviceToken.value = null);
|
|
final session = _Connected();
|
|
final calls = await pumpBootstrap(
|
|
tester,
|
|
platform: TargetPlatform.android,
|
|
relayUrl: 'https://relay.example',
|
|
enabled: true,
|
|
session: session,
|
|
);
|
|
session.setStatus(SessionStatus.reconnecting);
|
|
await tester.pumpAndSettle();
|
|
calls.clear();
|
|
|
|
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
|
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(calls, contains('refreshToken'));
|
|
await unmount(tester);
|
|
});
|
|
}
|
|
|
|
class _MemoryStore implements AndroidPushStateStore {
|
|
String? value;
|
|
|
|
@override
|
|
Future<String?> read() async => value;
|
|
|
|
@override
|
|
Future<void> write(String? next) async => value = next;
|
|
}
|
|
|
|
class _Lifecycle extends AppLifecycleNotifier {
|
|
@override
|
|
AppLifecycleState build() => AppLifecycleState.resumed;
|
|
}
|
|
|
|
class _Auth extends AuthNotifier {
|
|
@override
|
|
Future<AuthState> build() async =>
|
|
const AuthState(status: AuthStatus.unauthenticated);
|
|
}
|
|
|
|
class _Connected extends RelaySessionNotifier {
|
|
final leases = <Map<String, dynamic>>[];
|
|
String executorSecret = '2' * 64;
|
|
|
|
@override
|
|
Future<NostrEvent> publish(
|
|
NostrEvent event, {
|
|
Duration timeout = const Duration(seconds: 8),
|
|
Future<bool> Function()? mayPublish,
|
|
}) async {
|
|
expect(event.kind, buzzPushLeaseKind);
|
|
final plaintext = nip44Decrypt(
|
|
getConversationKey(executorSecret, event.pubkey),
|
|
event.content,
|
|
);
|
|
leases.add(jsonDecode(plaintext) as Map<String, dynamic>);
|
|
return event;
|
|
}
|
|
|
|
void setStatus(SessionStatus status) => state = SessionState(status: status);
|
|
|
|
@override
|
|
SessionState build() => const SessionState(status: SessionStatus.connected);
|
|
}
|
|
|
|
final _descriptor = _descriptorFor(nostr.Keys('2' * 64).public);
|
|
|
|
BuzzPushLeaseDescriptor _descriptorFor(String executorPubkey) =>
|
|
BuzzPushLeaseDescriptor(
|
|
origin: 'wss://relay.example',
|
|
executorKeyId: 'relay-v1',
|
|
executorPubkey: executorPubkey,
|
|
transport: 'apns',
|
|
maxLeaseTtlSeconds: 3600,
|
|
maxContentLength: 4096,
|
|
maxPlaintextLength: 4096,
|
|
maxEndpointLength: 2048,
|
|
maxStringLength: 512,
|
|
);
|