Skip to content

Commit e98c109

Browse files
square-tombstudioclaude
committed
fix(mobile): reread NIP-FI discovery for every new hosted socket
Only the relay session and the admission probe passed `fresh`, so huddle transports, one-shot agent publications, push-lease revocations and tombstones reused cached discovery: after a community started enforcing, they opened sockets without an assertion until the main session reconnected. Every socket-opening caller now rereads discovery. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent 3fb362e commit e98c109

6 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎mobile/lib/shared/agents/remote_agents.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ class RemoteAgentController extends ChangeNotifier {
790790
final config = RelayConfig(baseUrl: relay, nsec: key.nsec);
791791
await submitSignedEventOnce(
792792
wsUrl: config.wsUrl,
793-
headers: await relayAuth.headers(config),
793+
headers: await relayAuth.headers(config, fresh: true),
794794
nsec: key.nsec,
795795
kind: 30177,
796796
content: jsonEncode({
@@ -813,7 +813,7 @@ class RemoteAgentController extends ChangeNotifier {
813813
final config = RelayConfig(baseUrl: relay, nsec: key.nsec);
814814
await submitSignedEventOnce(
815815
wsUrl: config.wsUrl,
816-
headers: await relayAuth.headers(config),
816+
headers: await relayAuth.headers(config, fresh: true),
817817
nsec: key.nsec,
818818
kind: 5,
819819
content: '',

‎mobile/lib/shared/community/community_provider.dart‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ Future<void> _deactivateCommunityPushLease(
179179
({required kind, required content, required tags, createdAt}) async =>
180180
submitSignedEventOnce(
181181
wsUrl: wsUrl,
182-
headers: await relayAuth.headers(relayConfig, background: true),
182+
headers: await relayAuth.headers(
183+
relayConfig,
184+
background: true,
185+
fresh: true,
186+
),
183187
nsec: nsec,
184188
kind: kind,
185189
content: content,

‎mobile/lib/shared/hosted/hosted_relay_auth.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ class HostedRelayAuth extends ChangeNotifier {
202202
/// relay decides.
203203
///
204204
/// A hosted relay gets an assertion only when its NIP-FI discovery requires
205-
/// one. A [fresh] caller (a new socket connection) rereads discovery, so a
206-
/// community that starts enforcing is picked up on its next connect; other
207-
/// requests reuse the latest discovery.
205+
/// one. Every caller opening a new socket passes [fresh] to reread
206+
/// discovery, so a community that changes enforcement is picked up on its
207+
/// next connect; HTTP requests reuse the latest discovery.
208208
Future<Map<String, String>> headers(
209209
RelayConfig config, {
210210
bool background = false,

‎mobile/lib/shared/huddle/huddle_session.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ final huddleTransportFactoryProvider = Provider<HuddleTransportFactory>((ref) {
160160
parameters: parameters,
161161
headers: () => auth.headers(
162162
RelayConfig(baseUrl: parameters.relayWebSocketUrl, nsec: parameters.nsec),
163+
fresh: true,
163164
),
164165
);
165166
});

‎mobile/lib/shared/push/push_lease_revocation_outbox.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ Future<void> publishBuzzPushLeaseRevocation(
553553
headers: await relayAuth.headers(
554554
RelayConfig(baseUrl: record.relayUrl, nsec: record.nsec),
555555
background: true,
556+
fresh: true,
556557
),
557558
nsec: record.nsec,
558559
kind: kind,

‎mobile/test/shared/push/push_lease_revocation_outbox_test.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void main() {
9595
expect(auth.configs.single.nsec, keys.nsec);
9696
// A removed community's failure must not hide the active one's recovery.
9797
expect(auth.backgrounds.single, isTrue);
98+
// A new socket rereads NIP-FI discovery, so a community that started
99+
// enforcing since its last read still gets the assertion.
100+
expect(auth.freshes.single, isTrue);
98101

99102
// Removing the community publishes its tombstone the same way.
100103
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
@@ -504,6 +507,7 @@ class _AssertingRelayAuth extends HostedRelayAuth {
504507

505508
final configs = <RelayConfig>[];
506509
final backgrounds = <bool>[];
510+
final freshes = <bool>[];
507511

508512
@override
509513
Future<Map<String, String>> headers(
@@ -513,6 +517,7 @@ class _AssertingRelayAuth extends HostedRelayAuth {
513517
}) async {
514518
configs.add(config);
515519
backgrounds.add(background);
520+
freshes.add(fresh);
516521
return {'Nostr-Federated-Identity': 'Bearer hosted-token'};
517522
}
518523
}

0 commit comments

Comments
 (0)