-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from relaystr/nip-42-new
nip-42
- Loading branch information
Showing
9 changed files
with
178 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/ndk/lib/domain_layer/usecases/nip42/auth_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:ndk/domain_layer/entities/nip_01_event.dart'; | ||
|
||
/// auth event to send to relays | ||
class AuthEvent extends Nip01Event { | ||
/// auth kind | ||
// ignore: constant_identifier_names | ||
static const int KIND = 22242; | ||
|
||
/// Zap Request | ||
AuthEvent({ | ||
required super.pubKey, | ||
required super.tags, | ||
}) : super(kind: KIND, content: ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:ndk/data_layer/repositories/nostr_transport/websocket_client_nostr_transport_factory.dart'; | ||
import 'package:ndk/data_layer/repositories/signers/bip340_event_signer.dart'; | ||
import 'package:ndk/domain_layer/entities/global_state.dart'; | ||
import 'package:ndk/domain_layer/usecases/relay_manager.dart'; | ||
import 'package:ndk/entities.dart'; | ||
import 'package:ndk/ndk.dart'; | ||
import 'package:ndk/shared/nips/nip01/bip340.dart'; | ||
import 'package:ndk/shared/nips/nip01/key_pair.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../mocks/mock_relay.dart'; | ||
|
||
void main() async { | ||
group('NIP-42', () { | ||
|
||
KeyPair key1 = Bip340.generatePrivateKey(); | ||
|
||
Map<KeyPair, String> keyNames = { | ||
key1: "key1", | ||
}; | ||
|
||
Nip01Event textNote(KeyPair key2) { | ||
return Nip01Event( | ||
kind: Nip01Event.TEXT_NODE_KIND, | ||
pubKey: key2.publicKey, | ||
content: "some note from key ${keyNames[key1]}", | ||
tags: [], | ||
createdAt: DateTime.now().millisecondsSinceEpoch ~/ 1000); | ||
} | ||
|
||
Map<KeyPair, Nip01Event> key1TextNotes = {key1: textNote(key1)}; | ||
|
||
test('respond to auth challenge', () async { | ||
MockRelay relay1 = MockRelay(name: "relay 1", explicitPort: 3900, requireAuthForRequests: true); | ||
await relay1.startServer(textNotes: key1TextNotes); | ||
|
||
final ndk = Ndk( | ||
NdkConfig( | ||
eventVerifier: Bip340EventVerifier(), | ||
eventSigner: Bip340EventSigner( | ||
privateKey: key1.privateKey, | ||
publicKey: key1.publicKey, | ||
), | ||
cache: MemCacheManager(), | ||
logLevel: Logger.logLevels.trace, | ||
bootstrapRelays: [relay1.url]), | ||
); | ||
|
||
await Future.delayed(Duration(seconds: 1)); | ||
final response = ndk.requests.query(filters: [ | ||
Filter(kinds: [Nip01Event.TEXT_NODE_KIND], authors: [key1.publicKey]) | ||
]); | ||
await expectLater(response.stream, emitsInAnyOrder(key1TextNotes.values)); | ||
|
||
// TODO write some events | ||
// TODO do some requests | ||
await ndk.destroy(); | ||
await relay1.stopServer(); | ||
}); | ||
|
||
test("check that relay does not return events if we don't provide a signer", () async { | ||
MockRelay relay1 = MockRelay(name: "relay 1", explicitPort: 3900, requireAuthForRequests: true); | ||
await relay1.startServer(textNotes: key1TextNotes); | ||
|
||
final ndk = Ndk( | ||
NdkConfig( | ||
eventVerifier: Bip340EventVerifier(), | ||
cache: MemCacheManager(), | ||
logLevel: Logger.logLevels.trace, | ||
bootstrapRelays: [relay1.url]), | ||
); | ||
|
||
await Future.delayed(Duration(seconds: 1)); | ||
final response = ndk.requests.query(filters: [ | ||
Filter(kinds: [Nip01Event.TEXT_NODE_KIND], authors: [key1.publicKey]) | ||
]); | ||
List<Nip01Event> events = await response.future; | ||
expect(events, isEmpty); | ||
await ndk.destroy(); | ||
await relay1.stopServer(); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters