Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2eb9f5

Browse files
Merge pull request #6 from sebdeveloper6952/5-implement-ambers-decrypt_zap_event
add decrypt zap event, match field names with Amber
2 parents 3f6ebd3 + ddf6e91 commit d2eb9f5

File tree

4 files changed

+101
-60
lines changed

4 files changed

+101
-60
lines changed

example/lib/main.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class _MyHomePageState extends State<MyHomePage> {
8484

8585
amber
8686
.signEvent(
87-
npub: _npub,
88-
event: eventJson,
87+
currentUser: _npub,
88+
eventJson: eventJson,
8989
)
9090
.then((value) {
9191
setState(() {
@@ -100,8 +100,8 @@ class _MyHomePageState extends State<MyHomePage> {
100100
amber
101101
.nip04Encrypt(
102102
plaintext: "Hello from Amber Flutter, Nip 04!",
103-
npub: _npub,
104-
pubkey: _pubkeyHex,
103+
currentUser: _npub,
104+
pubKey: _pubkeyHex,
105105
)
106106
.then((value) {
107107
_cipherText = value['signature'] ?? '';
@@ -117,8 +117,8 @@ class _MyHomePageState extends State<MyHomePage> {
117117
amber
118118
.nip04Decrypt(
119119
ciphertext: _cipherText,
120-
npub: _npub,
121-
pubkey: _pubkeyHex,
120+
currentUser: _npub,
121+
pubKey: _pubkeyHex,
122122
)
123123
.then((value) {
124124
setState(() {
@@ -133,8 +133,8 @@ class _MyHomePageState extends State<MyHomePage> {
133133
amber
134134
.nip44Encrypt(
135135
plaintext: "Hello from Amber Flutter, Nip 44!",
136-
npub: _npub,
137-
pubkey: _pubkeyHex,
136+
currentUser: _npub,
137+
pubKey: _pubkeyHex,
138138
)
139139
.then((value) {
140140
_cipherText = value['signature'] ?? '';
@@ -150,8 +150,8 @@ class _MyHomePageState extends State<MyHomePage> {
150150
amber
151151
.nip44Decrypt(
152152
ciphertext: _cipherText,
153-
npub: _npub,
154-
pubkey: _pubkeyHex,
153+
currentUser: _npub,
154+
pubKey: _pubkeyHex,
155155
)
156156
.then((value) {
157157
setState(() {

lib/amberflutter.dart

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,69 +13,81 @@ class Amberflutter {
1313
}
1414

1515
Future<Map<dynamic, dynamic>> signEvent({
16-
required String npub,
17-
required String event,
16+
required String currentUser,
17+
required String eventJson,
1818
String? id,
1919
}) {
2020
return AmberflutterPlatform.instance.signEvent(
21-
npub,
22-
event,
21+
currentUser,
22+
eventJson,
2323
id,
2424
);
2525
}
2626

2727
Future<Map<dynamic, dynamic>> nip04Encrypt({
2828
required String plaintext,
29-
required String npub,
30-
required String pubkey,
29+
required String currentUser,
30+
required String pubKey,
3131
String? id,
3232
}) {
3333
return AmberflutterPlatform.instance.nip04Encrypt(
3434
plaintext,
35-
npub,
36-
pubkey,
35+
currentUser,
36+
pubKey,
3737
id,
3838
);
3939
}
4040

4141
Future<Map<dynamic, dynamic>> nip04Decrypt({
4242
required String ciphertext,
43-
required String npub,
44-
required String pubkey,
43+
required String currentUser,
44+
required String pubKey,
4545
String? id,
4646
}) {
4747
return AmberflutterPlatform.instance.nip04Decrypt(
4848
ciphertext,
49-
npub,
50-
pubkey,
49+
currentUser,
50+
pubKey,
5151
id,
5252
);
5353
}
5454

5555
Future<Map<dynamic, dynamic>> nip44Encrypt({
5656
required String plaintext,
57-
required String npub,
58-
required String pubkey,
57+
required String currentUser,
58+
required String pubKey,
5959
String? id,
6060
}) {
6161
return AmberflutterPlatform.instance.nip44Encrypt(
6262
plaintext,
63-
npub,
64-
pubkey,
63+
currentUser,
64+
pubKey,
6565
id,
6666
);
6767
}
6868

6969
Future<Map<dynamic, dynamic>> nip44Decrypt({
7070
required String ciphertext,
71-
required String npub,
72-
required String pubkey,
71+
required String currentUser,
72+
required String pubKey,
7373
String? id,
7474
}) {
7575
return AmberflutterPlatform.instance.nip44Decrypt(
7676
ciphertext,
77-
npub,
78-
pubkey,
77+
currentUser,
78+
pubKey,
79+
id,
80+
);
81+
}
82+
83+
Future<Map<dynamic, dynamic>> decryptZapEvent({
84+
required String eventJson,
85+
required String currentUser,
86+
String? id,
87+
}) {
88+
return AmberflutterPlatform.instance.decryptZapEvent(
89+
eventJson,
90+
currentUser,
7991
id,
8092
);
8193
}

lib/amberflutter_method_channel.dart

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class MethodChannelAmberflutter extends AmberflutterPlatform {
3333

3434
@override
3535
Future<Map<dynamic, dynamic>> signEvent(
36-
String npub,
37-
String event,
36+
String currentUser,
37+
String eventJson,
3838
String? id,
3939
) async {
4040
final arguments = {
4141
"type": "sign_event",
42-
"current_user": npub,
43-
"uri_data": event,
42+
"current_user": currentUser,
43+
"uri_data": eventJson,
4444
"id": id,
4545
};
4646

@@ -55,15 +55,15 @@ class MethodChannelAmberflutter extends AmberflutterPlatform {
5555
@override
5656
Future<Map<dynamic, dynamic>> nip04Encrypt(
5757
String plaintext,
58-
String npub,
59-
String pubkey,
58+
String currentUser,
59+
String pubKey,
6060
String? id,
6161
) async {
6262
final arguments = {
6363
"type": "nip04_encrypt",
6464
"uri_data": plaintext,
65-
"current_user": npub,
66-
"pubKey": pubkey,
65+
"current_user": currentUser,
66+
"pubKey": pubKey,
6767
"id": id,
6868
};
6969

@@ -78,15 +78,15 @@ class MethodChannelAmberflutter extends AmberflutterPlatform {
7878
@override
7979
Future<Map<dynamic, dynamic>> nip04Decrypt(
8080
String ciphertext,
81-
String npub,
82-
String pubkey,
81+
String currentUser,
82+
String pubKey,
8383
String? id,
8484
) async {
8585
final arguments = {
8686
"type": "nip04_decrypt",
8787
"uri_data": ciphertext,
88-
"current_user": npub,
89-
"pubKey": pubkey,
88+
"current_user": currentUser,
89+
"pubKey": pubKey,
9090
"id": id,
9191
};
9292

@@ -101,15 +101,15 @@ class MethodChannelAmberflutter extends AmberflutterPlatform {
101101
@override
102102
Future<Map<dynamic, dynamic>> nip44Encrypt(
103103
String plaintext,
104-
String npub,
105-
String pubkey,
104+
String currentUser,
105+
String pubKey,
106106
String? id,
107107
) async {
108108
final arguments = {
109109
"type": "nip44_encrypt",
110110
"uri_data": plaintext,
111-
"current_user": npub,
112-
"pubKey": pubkey,
111+
"current_user": currentUser,
112+
"pubKey": pubKey,
113113
"id": id,
114114
};
115115

@@ -124,15 +124,36 @@ class MethodChannelAmberflutter extends AmberflutterPlatform {
124124
@override
125125
Future<Map<dynamic, dynamic>> nip44Decrypt(
126126
String ciphertext,
127-
String npub,
128-
String pubkey,
127+
String currentUser,
128+
String pubKey,
129129
String? id,
130130
) async {
131131
final arguments = {
132132
"type": "nip44_decrypt",
133133
"uri_data": ciphertext,
134-
"current_user": npub,
135-
"pubKey": pubkey,
134+
"current_user": currentUser,
135+
"pubKey": pubKey,
136+
"id": id,
137+
};
138+
139+
final data = await methodChannel.invokeMethod<Map<dynamic, dynamic>>(
140+
'nostrsigner',
141+
arguments,
142+
);
143+
144+
return data ?? {};
145+
}
146+
147+
@override
148+
Future<Map<dynamic, dynamic>> decryptZapEvent(
149+
String eventJson,
150+
String currentUser,
151+
String? id,
152+
) async {
153+
final arguments = {
154+
"type": "decrypt_zap_event",
155+
"uri_data": eventJson,
156+
"current_user": currentUser,
136157
"id": id,
137158
};
138159

lib/amberflutter_platform_interface.dart

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,54 @@ abstract class AmberflutterPlatform extends PlatformInterface {
2828
}
2929

3030
Future<Map<dynamic, dynamic>> signEvent(
31-
String npub,
32-
String event,
31+
String currentUser,
32+
String eventJson,
3333
String? id,
3434
) {
3535
throw UnimplementedError('signEvent() has not been implemented.');
3636
}
3737

3838
Future<Map<dynamic, dynamic>> nip04Encrypt(
3939
String plaintext,
40-
String npub,
41-
String pubkey,
40+
String currentUser,
41+
String pubKey,
4242
String? id,
4343
) {
4444
throw UnimplementedError('nip04Encrypt() has not been implemented.');
4545
}
4646

4747
Future<Map<dynamic, dynamic>> nip04Decrypt(
4848
String ciphertext,
49-
String npub,
50-
String pubkey,
49+
String currentUser,
50+
String pubKey,
5151
String? id,
5252
) {
5353
throw UnimplementedError('nip04Decrypt() has not been implemented.');
5454
}
5555

5656
Future<Map<dynamic, dynamic>> nip44Encrypt(
5757
String plaintext,
58-
String npub,
59-
String pubkey,
58+
String currentUser,
59+
String pubKey,
6060
String? id,
6161
) {
6262
throw UnimplementedError('nip44Encrypt() has not been implemented.');
6363
}
6464

6565
Future<Map<dynamic, dynamic>> nip44Decrypt(
6666
String ciphertext,
67-
String npub,
68-
String pubkey,
67+
String currentUser,
68+
String pubKey,
6969
String? id,
7070
) {
7171
throw UnimplementedError('nip44Decrypt() has not been implemented.');
7272
}
73+
74+
Future<Map<dynamic, dynamic>> decryptZapEvent(
75+
String eventJson,
76+
String currentUser,
77+
String? id,
78+
) {
79+
throw UnimplementedError('decryptZapEvent() has not been implemented.');
80+
}
7381
}

0 commit comments

Comments
 (0)