Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nip-44 #88

Merged
merged 3 commits into from
Dec 25, 2024
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
2 changes: 1 addition & 1 deletion packages/ndk/example/nwc/make_invoice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() async {
final nwcUri = Platform.environment['NWC_URI']!;
final connection = await ndk.nwc.connect(nwcUri);

final amount = 1000;
final amount = 21;
final description = "hello";
final response = await ndk.nwc
.makeInvoice(connection, amountSats: amount, description: description);
Expand Down
1 change: 1 addition & 0 deletions packages/ndk/example/nwc/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void main() async {
var nwcUri = Platform.environment['NWC_URI']!;
final connection = await ndk.nwc.connect(nwcUri);

print("waiting for ${connection.isLegacyNotifications()?"legacy ":""}notifications");
await for (final notification in connection.notificationStream.stream) {
print('notification ${notification.type} amount: ${notification.amount}');
}
Expand Down
30 changes: 18 additions & 12 deletions packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:async';
import 'dart:convert';

import 'package:elliptic/elliptic.dart' as elliptic;

import 'package:ndk/ndk.dart';
import 'package:ndk/shared/nips/nip04/nip04.dart';
import 'package:ndk/shared/nips/nip44/nip44.dart';

import 'consts/nwc_kind.dart';
import 'consts/nwc_method.dart';
Expand Down Expand Up @@ -187,18 +190,21 @@
Future<void> _onNotification(
Nip01Event event, NwcConnection connection) async {
if (event.content != "") {
// TODO
// var decrypted = Nip44.decrypt(
// connection.uri.secret, connection.uri.walletPubkey, event.content);
// Map<String, dynamic> data;
// data = json.decode(decrypted);
// if (data.containsKey("notification_type") &&
// data['notification'] != null) {
// NwcNotification notification = NwcNotification.fromMap(data['notification']);
// connection.notificationStream.add(notification);
// } else if (data.containsKey("error")) {
// // TODO ??
// }
final decrypted = await Nip44.decryptMessage(
event.content,
connection.uri.secret,
connection.uri.walletPubkey,

Check warning on line 196 in packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart#L193-L196

Added lines #L193 - L196 were not covered by tests
);
Map<String, dynamic> data;
data = json.decode(decrypted);
if (data.containsKey("notification_type") &&
data['notification'] != null) {

Check warning on line 201 in packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart#L199-L201

Added lines #L199 - L201 were not covered by tests
NwcNotification notification =
NwcNotification.fromMap(data['notification']);
connection.notificationStream.add(notification);
} else if (data.containsKey("error")) {

Check warning on line 205 in packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart#L203-L205

Added lines #L203 - L205 were not covered by tests
// TODO ??
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class NwcConnection {
return _signer!;
}

/// does this connection only support legacy notifications
bool isLegacyNotifications() {
return supportedVersions.length == 1 && supportedVersions.first == "0.0" ||
!supportedVersions.any((e) => e != "0.0");
Expand Down
278 changes: 0 additions & 278 deletions packages/ndk/lib/objectbox-model.json

This file was deleted.

Loading
Loading