Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ class Nip46EventSigner implements EventSigner {
Future<void> listenRelays() async {
subscription = requests.subscription(
explicitRelays: connection.relays,
filters: [
Filter(
authors: [connection.remotePubkey],
kinds: [BunkerRequest.kKind],
pTags: [localEventSigner.publicKey],
),
],
filter: Filter(
authors: [connection.remotePubkey],
kinds: [BunkerRequest.kKind],
pTags: [localEventSigner.publicKey],
),
);

subscription!.stream.listen(onEvent);
Expand Down
38 changes: 20 additions & 18 deletions packages/ndk/lib/domain_layer/usecases/bunkers/bunkers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,25 @@ class Bunkers {
);

final signedEvent = await localEventSigner.sign(requestEvent);
final broadcastRes =
_broadcast.broadcast(nostrEvent: signedEvent, specificRelays: relays);
await broadcastRes.broadcastDoneFuture;

// Subscribe BEFORE broadcasting to avoid missing the response,
// since NIP-46 uses ephemeral events (kind 24133)
final subscription = _requests.subscription(
explicitRelays: relays,
filters: [
Filter(
authors: [remotePubkey],
kinds: [BunkerRequest.kKind],
pTags: [localEventSigner.publicKey],
since: someTimeAgo(),
),
],
filter: Filter(
authors: [remotePubkey],
kinds: [BunkerRequest.kKind],
pTags: [localEventSigner.publicKey],
since: someTimeAgo(),
),
);

final broadcastRes = _broadcast.broadcast(
nostrEvent: signedEvent,
specificRelays: relays,
);
await broadcastRes.broadcastDoneFuture;

BunkerConnection? result;

await for (final event in subscription.stream
Expand Down Expand Up @@ -144,13 +148,11 @@ class Bunkers {

final subscription = _requests.subscription(
explicitRelays: relays,
filters: [
Filter(
kinds: [BunkerRequest.kKind],
pTags: [localEventSigner.publicKey],
since: someTimeAgo(),
),
],
filter: Filter(
kinds: [BunkerRequest.kKind],
pTags: [localEventSigner.publicKey],
since: someTimeAgo(),
),
);
BunkerConnection? result;

Expand Down
21 changes: 11 additions & 10 deletions packages/ndk/test/signers/nip46_event_signer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void main() {

tearDown(() async {
signer.dispose();
await ndk.destroy();
await mockRelay.stopServer();
});

Expand Down Expand Up @@ -121,10 +122,10 @@ void main() {
content: 'Test event via bunker URL',
);

await bunkerSigner.sign(testEvent);
final signedTestEvent = await bunkerSigner.sign(testEvent);

expect(testEvent.id, isNotNull);
expect(testEvent.sig, isNotNull);
expect(signedTestEvent.id, isNotNull);
expect(signedTestEvent.sig, isNotNull);

bunkerSigner.dispose();
});
Expand Down Expand Up @@ -169,10 +170,10 @@ void main() {
content: 'Test event via loginWithBunkerUrl',
);

await accounts.sign(testEvent);
final signedTestEvent = await accounts.sign(testEvent);

expect(testEvent.id, isNotNull);
expect(testEvent.sig, isNotNull);
expect(signedTestEvent.id, isNotNull);
expect(signedTestEvent.sig, isNotNull);

// Cleanup
accounts.logout();
Expand Down Expand Up @@ -217,10 +218,10 @@ void main() {
content: 'Test event via loginWithBunkerConnection',
);

await accounts.sign(testEvent);
final signedTestEvent = await accounts.sign(testEvent);

expect(testEvent.id, isNotNull);
expect(testEvent.sig, isNotNull);
expect(signedTestEvent.id, isNotNull);
expect(signedTestEvent.sig, isNotNull);

// Cleanup
accounts.logout();
Expand Down Expand Up @@ -353,5 +354,5 @@ void main() {
final response = await signer.ping();
expect(response, equals('pong'));
});
}, skip: true);
});
}