diff --git a/lib/app/services/nostr/nostr_gift_wrap_service.dart b/lib/app/services/nostr/nostr_gift_wrap_service.dart index b2de816e2..d0130a3e1 100644 --- a/lib/app/services/nostr/nostr_gift_wrap_service.dart +++ b/lib/app/services/nostr/nostr_gift_wrap_service.dart @@ -32,7 +32,7 @@ class NostrGiftWrapServiceImpl implements NostrGiftWrapService { EventSigner signer, ) async { final encryptedEvent = await Nip44.encryptMessage( - jsonEncode(event.toJson()), + jsonEncode(event.toJson().last), signer.privateKey, pubkey, ); @@ -65,6 +65,8 @@ class NostrGiftWrapServiceImpl implements NostrGiftWrapService { pubkey, ); - return EventMessage.fromJson(jsonDecode(decryptedContent) as List); + return EventMessage.fromPayloadJson( + jsonDecode(decryptedContent) as Map, + ); } } diff --git a/lib/app/services/nostr/nostr_seal_service.dart b/lib/app/services/nostr/nostr_seal_service.dart index c5627df81..e9f562e21 100644 --- a/lib/app/services/nostr/nostr_seal_service.dart +++ b/lib/app/services/nostr/nostr_seal_service.dart @@ -30,7 +30,7 @@ class NostrSealServiceImpl implements NostrSealService { EventSigner signer, String pubkey, ) async { - final encodedRumor = jsonEncode(rumor.toJson()); + final encodedRumor = jsonEncode(rumor.toJson().last); final encryptedRumor = await Nip44.encryptMessage( encodedRumor, @@ -62,6 +62,8 @@ class NostrSealServiceImpl implements NostrSealService { pubkey, ); - return EventMessage.fromJson(jsonDecode(decryptedContent) as List); + return EventMessage.fromPayloadJson( + jsonDecode(decryptedContent) as Map, + ); } } diff --git a/test/app/services/nostr/nostr_gift_wrap_service_test.dart b/test/app/services/nostr/nostr_gift_wrap_service_test.dart index f922504d2..d5848d107 100644 --- a/test/app/services/nostr/nostr_gift_wrap_service_test.dart +++ b/test/app/services/nostr/nostr_gift_wrap_service_test.dart @@ -1,6 +1,8 @@ // SPDX-License-Identifier: ice License 1.0 import 'package:flutter_test/flutter_test.dart'; +import 'package:ion/app/features/chat/model/entities/private_direct_message_data.c.dart'; +import 'package:ion/app/services/nostr/ed25519_key_store.dart'; import 'package:ion/app/services/nostr/nostr_gift_wrap_service.dart'; import 'package:nostr_dart/nostr_dart.dart'; @@ -9,19 +11,15 @@ void main() { late EventSigner signer; const pubkey = 'c95c07ad5aad2d81a3890f13b3eaa80a3d8aca173a91dc2be9fd04720a5a9377'; - setUp(() { + setUp(() async { giftWrapService = NostrGiftWrapServiceImpl(); - signer = KeyStore.generate(); + signer = await Ed25519KeyStore.generate(); }); group('NostrGiftWrapService', () { test('creates wrap from event', () async { - final event = await EventMessage.fromData( - signer: signer, - kind: 14, - content: 'test message', - createdAt: DateTime.now(), - ); + final event = + await PrivateDirectMessageData.fromRawContent('test').toEventMessage(pubkey: pubkey); final wrap = await giftWrapService.createWrap( event, @@ -40,12 +38,8 @@ void main() { }); test('decodes wrap back to original event', () async { - final event = await EventMessage.fromData( - signer: signer, - kind: 14, - content: 'test message', - createdAt: DateTime.now(), - ); + final event = + await PrivateDirectMessageData.fromRawContent('test').toEventMessage(pubkey: pubkey); final wrap = await giftWrapService.createWrap( event, diff --git a/test/app/services/nostr/nostr_seal_service_test.dart b/test/app/services/nostr/nostr_seal_service_test.dart index 2bd5984ab..7794216c2 100644 --- a/test/app/services/nostr/nostr_seal_service_test.dart +++ b/test/app/services/nostr/nostr_seal_service_test.dart @@ -1,6 +1,8 @@ // SPDX-License-Identifier: ice License 1.0 import 'package:flutter_test/flutter_test.dart'; +import 'package:ion/app/features/chat/model/entities/private_direct_message_data.c.dart'; +import 'package:ion/app/services/nostr/ed25519_key_store.dart'; import 'package:ion/app/services/nostr/nostr_seal_service.dart'; import 'package:nostr_dart/nostr_dart.dart'; @@ -9,19 +11,15 @@ void main() { late EventSigner signer; const pubkey = 'c95c07ad5aad2d81a3890f13b3eaa80a3d8aca173a91dc2be9fd04720a5a9377'; - setUp(() { + setUp(() async { sealService = NostrSealServiceImpl(); - signer = KeyStore.generate(); + signer = await Ed25519KeyStore.generate(); }); group('NostrSealService', () { test('creates seal from rumor', () async { - final rumor = await EventMessage.fromData( - signer: signer, - kind: 14, - content: 'test message', - createdAt: DateTime.now(), - ); + final rumor = + await PrivateDirectMessageData.fromRawContent('test').toEventMessage(pubkey: pubkey); final seal = await sealService.createSeal( rumor, @@ -36,12 +34,8 @@ void main() { }); test('decodes seal back to original event', () async { - final rumor = await EventMessage.fromData( - signer: signer, - kind: 14, - content: 'test message', - createdAt: DateTime.now(), - ); + final rumor = + await PrivateDirectMessageData.fromRawContent('test').toEventMessage(pubkey: pubkey); final seal = await sealService.createSeal( rumor,