Skip to content

Commit

Permalink
Merge pull request #88 from relaystr/nip-44
Browse files Browse the repository at this point in the history
nip-44
  • Loading branch information
frnandu authored Dec 25, 2024
2 parents 141cc69 + bb39373 commit 693fdc8
Show file tree
Hide file tree
Showing 10 changed files with 1,539 additions and 291 deletions.
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 @@ class Nwc {
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,
);
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 ??
}
}
}

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

0 comments on commit 693fdc8

Please sign in to comment.