Skip to content

Commit

Permalink
fix: CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-kreios committed Dec 12, 2024
1 parent cf134bc commit 7ecb5e1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
6 changes: 4 additions & 2 deletions lib/app/services/nostr/nostr_gift_wrap_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -65,6 +65,8 @@ class NostrGiftWrapServiceImpl implements NostrGiftWrapService {
pubkey,
);

return EventMessage.fromJson(jsonDecode(decryptedContent) as List);
return EventMessage.fromPayloadJson(
jsonDecode(decryptedContent) as Map<String, dynamic>,
);
}
}
6 changes: 4 additions & 2 deletions lib/app/services/nostr/nostr_seal_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,6 +62,8 @@ class NostrSealServiceImpl implements NostrSealService {
pubkey,
);

return EventMessage.fromJson(jsonDecode(decryptedContent) as List);
return EventMessage.fromPayloadJson(
jsonDecode(decryptedContent) as Map<String, dynamic>,
);
}
}
22 changes: 8 additions & 14 deletions test/app/services/nostr/nostr_gift_wrap_service_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand All @@ -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,
Expand Down
22 changes: 8 additions & 14 deletions test/app/services/nostr/nostr_seal_service_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 7ecb5e1

Please sign in to comment.