mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 09:54:19 +01:00
try to add decryptZapEvent support
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
|
||||
<provider
|
||||
android:name="com.github.haorendashu.nowser.NowserSignerProvider"
|
||||
android:authorities="com.github.haorendashu.nowser.SIGN_EVENT;com.github.haorendashu.nowser.NIP04_ENCRYPT;com.github.haorendashu.nowser.NIP04_DECRYPT;com.github.haorendashu.nowser.NIP44_ENCRYPT;com.github.haorendashu.nowser.NIP44_DECRYPT;com.github.haorendashu.nowser.GET_PUBLIC_KEY"
|
||||
android:authorities="com.github.haorendashu.nowser.SIGN_EVENT;com.github.haorendashu.nowser.NIP04_ENCRYPT;com.github.haorendashu.nowser.NIP04_DECRYPT;com.github.haorendashu.nowser.NIP44_ENCRYPT;com.github.haorendashu.nowser.NIP44_DECRYPT;com.github.haorendashu.nowser.GET_PUBLIC_KEY;com.github.haorendashu.nowser.DECRYPT_ZAP_EVENT"
|
||||
android:exported="true" />
|
||||
</application>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class NowserSignerProvider extends AndroidContentProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getAuthority() {
|
||||
return "com.github.haorendashu.nowser.SIGN_EVENT;com.github.haorendashu.nowser.NIP04_ENCRYPT;com.github.haorendashu.nowser.NIP04_DECRYPT;com.github.haorendashu.nowser.NIP44_ENCRYPT;com.github.haorendashu.nowser.NIP44_DECRYPT;com.github.haorendashu.nowser.GET_PUBLIC_KEY";
|
||||
return "com.github.haorendashu.nowser.SIGN_EVENT;com.github.haorendashu.nowser.NIP04_ENCRYPT;com.github.haorendashu.nowser.NIP04_DECRYPT;com.github.haorendashu.nowser.NIP44_ENCRYPT;com.github.haorendashu.nowser.NIP44_DECRYPT;com.github.haorendashu.nowser.GET_PUBLIC_KEY;com.github.haorendashu.nowser.DECRYPT_ZAP_EVENT";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -88,6 +88,9 @@ class _AuthDialog extends State<AuthDialog> {
|
||||
} else if (widget.authType == AuthType.NIP44_DECRYPT) {
|
||||
authTitle = "Decrypt (NIP-44)";
|
||||
authDes += "Decrypt (NIP-44)";
|
||||
} else if (widget.authType == AuthType.DECRYPT_ZAP_EVENT) {
|
||||
authTitle = "Decrypt zap event";
|
||||
authDes += "Decrypt zap event";
|
||||
}
|
||||
|
||||
List<Widget> list = [];
|
||||
|
||||
@@ -15,6 +15,8 @@ class AuthType {
|
||||
|
||||
static const NIP44_DECRYPT = 7;
|
||||
|
||||
static const DECRYPT_ZAP_EVENT = 8;
|
||||
|
||||
static String getAuthName(BuildContext context, int authType) {
|
||||
if (authType == GET_PUBLIC_KEY) {
|
||||
return "Get Public Key";
|
||||
@@ -30,6 +32,8 @@ class AuthType {
|
||||
return "Encrypt (NIP-44)";
|
||||
} else if (authType == NIP44_DECRYPT) {
|
||||
return "Decrypt (NIP-44)";
|
||||
} else if (authType == DECRYPT_ZAP_EVENT) {
|
||||
return "Decrypt zap event";
|
||||
}
|
||||
|
||||
return "Unknow";
|
||||
|
||||
@@ -341,5 +341,5 @@ Future<void> nowserSignerProviderEntrypoint() async {
|
||||
// if we call content resolver this should init first, to receive request.
|
||||
// so, doInit() method move to query method.
|
||||
AndroidSignerContentResolverProvider(
|
||||
'com.github.haorendashu.nowser.SIGN_EVENT;com.github.haorendashu.nowser.NIP04_ENCRYPT;com.github.haorendashu.nowser.NIP04_DECRYPT;com.github.haorendashu.nowser.NIP44_ENCRYPT;com.github.haorendashu.nowser.NIP44_DECRYPT;com.github.haorendashu.nowser.GET_PUBLIC_KEY');
|
||||
'com.github.haorendashu.nowser.SIGN_EVENT;com.github.haorendashu.nowser.NIP04_ENCRYPT;com.github.haorendashu.nowser.NIP04_DECRYPT;com.github.haorendashu.nowser.NIP44_ENCRYPT;com.github.haorendashu.nowser.NIP44_DECRYPT;com.github.haorendashu.nowser.GET_PUBLIC_KEY;com.github.haorendashu.nowser.DECRYPT_ZAP_EVENT');
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:nostr_sdk/event.dart';
|
||||
import 'package:nostr_sdk/nip19/nip19.dart';
|
||||
import 'package:nostr_sdk/signer/nostr_signer.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nostr_sdk/zap/private_zap.dart';
|
||||
import 'package:nowser/const/app_type.dart';
|
||||
import 'package:nowser/provider/permission_check_mixin.dart';
|
||||
|
||||
@@ -75,6 +76,8 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
authType = AuthType.NIP44_ENCRYPT;
|
||||
} else if (authTypeStr == "NIP44_DECRYPT") {
|
||||
authType = AuthType.NIP44_DECRYPT;
|
||||
} else if (authTypeStr == "DECRYPT_ZAP_EVENT") {
|
||||
authType = AuthType.DECRYPT_ZAP_EVENT;
|
||||
}
|
||||
|
||||
int appType = AppType.ANDROID_APP;
|
||||
@@ -86,9 +89,10 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
|
||||
int? eventKind;
|
||||
dynamic eventObj;
|
||||
if (authType == AuthType.SIGN_EVENT) {
|
||||
if (authType == AuthType.SIGN_EVENT ||
|
||||
authType == AuthType.DECRYPT_ZAP_EVENT) {
|
||||
eventObj = jsonDecode(authDetail);
|
||||
if (eventObj != null) {
|
||||
if (eventObj != null && authType == AuthType.SIGN_EVENT) {
|
||||
eventKind = eventObj["kind"];
|
||||
}
|
||||
}
|
||||
@@ -98,7 +102,9 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
var complete = Completer();
|
||||
|
||||
rejectFunc(_app) {
|
||||
if (_app != null) {
|
||||
saveAuthLog(_app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
complete.complete();
|
||||
}
|
||||
|
||||
@@ -170,6 +176,14 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
columnNames: ["signature"], notificationUris: [uri]);
|
||||
data.addRow([result]);
|
||||
}
|
||||
} else if (authType == AuthType.DECRYPT_ZAP_EVENT) {
|
||||
var event = Event.fromJson(eventObj);
|
||||
var result = await PrivateZap.decryptZapEvent(signer!, event);
|
||||
if (StringUtil.isNotBlank(result)) {
|
||||
data = MatrixCursorData(
|
||||
columnNames: ["signature"], notificationUris: [uri]);
|
||||
data.addRow([result]);
|
||||
}
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
|
||||
@@ -3,13 +3,16 @@ import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/event.dart';
|
||||
import 'package:nostr_sdk/nip04/nip04.dart';
|
||||
import 'package:nostr_sdk/nip19/nip19.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nostr_sdk/zap/private_zap.dart';
|
||||
import 'package:nowser/const/app_type.dart';
|
||||
import 'package:nowser/const/auth_result.dart';
|
||||
import 'package:nowser/const/auth_type.dart';
|
||||
import 'package:nowser/provider/permission_check_mixin.dart';
|
||||
import 'package:receive_intent/receive_intent.dart' as receiveIntent;
|
||||
import 'package:hex/hex.dart';
|
||||
|
||||
mixin AndroidSignerMixin on PermissionCheckMixin {
|
||||
// StreamSubscription? _sub;
|
||||
@@ -77,15 +80,18 @@ mixin AndroidSignerMixin on PermissionCheckMixin {
|
||||
authType = AuthType.NIP44_ENCRYPT;
|
||||
} else if (authTypeStr == "nip44_decrypt") {
|
||||
authType = AuthType.NIP44_DECRYPT;
|
||||
} else if (authTypeStr == "decrypt_zap_event") {
|
||||
authType = AuthType.DECRYPT_ZAP_EVENT;
|
||||
}
|
||||
|
||||
var playload = intent.data!.replaceFirst(PREFIX, "");
|
||||
int? eventKind;
|
||||
dynamic eventObj;
|
||||
if (authType == AuthType.SIGN_EVENT) {
|
||||
if (authType == AuthType.SIGN_EVENT ||
|
||||
authType == AuthType.DECRYPT_ZAP_EVENT) {
|
||||
print(playload);
|
||||
eventObj = jsonDecode(playload);
|
||||
if (eventObj != null) {
|
||||
if (eventObj != null && authType == AuthType.SIGN_EVENT) {
|
||||
eventKind = eventObj["kind"];
|
||||
print("eventKind $eventKind");
|
||||
}
|
||||
@@ -107,12 +113,12 @@ mixin AndroidSignerMixin on PermissionCheckMixin {
|
||||
// confirm
|
||||
Map<String, Object?> data = {};
|
||||
data["id"] = callId;
|
||||
var signerPubkey = await signer.getPublicKey();
|
||||
|
||||
if (authType == AuthType.GET_PUBLIC_KEY) {
|
||||
// TODO should handle permissions
|
||||
// var permissions = extra["permissions"];
|
||||
var pubkey = await signer.getPublicKey();
|
||||
data["signature"] = Nip19.encodePubKey(pubkey!);
|
||||
data["signature"] = Nip19.encodePubKey(signerPubkey!);
|
||||
data["package"] = "com.github.haorendashu.nowser";
|
||||
} else if (authType == AuthType.SIGN_EVENT) {
|
||||
var tags = eventObj["tags"];
|
||||
@@ -150,6 +156,10 @@ mixin AndroidSignerMixin on PermissionCheckMixin {
|
||||
if (StringUtil.isNotBlank(result)) {
|
||||
data["signature"] = result;
|
||||
}
|
||||
} else if (authType == AuthType.DECRYPT_ZAP_EVENT) {
|
||||
var event = Event.fromJson(eventObj);
|
||||
var source = await PrivateZap.decryptZapEvent(signer, event);
|
||||
data["signature"] = source;
|
||||
}
|
||||
|
||||
saveAuthLog(app, authType, eventKind, playload, AuthResult.OK);
|
||||
|
||||
@@ -50,16 +50,28 @@ mixin PermissionCheckMixin {
|
||||
}
|
||||
|
||||
if (app.connectType == ConnectType.FULLY_TRUST) {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
try {
|
||||
confirm(app, signer);
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
} catch (e) {
|
||||
print("confirm error $e");
|
||||
reject(app);
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
return;
|
||||
} else if (app.connectType == ConnectType.REASONABLE) {
|
||||
var permissionCheckResult = appProvider
|
||||
.checkPermission(appType, code, authType, eventKind: eventKind);
|
||||
print("permissionCheckResult $permissionCheckResult");
|
||||
if (permissionCheckResult == AuthResult.OK) {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
try {
|
||||
confirm(app, signer);
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
} catch (e) {
|
||||
print("confirm error $e");
|
||||
reject(app);
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
return;
|
||||
} else if (permissionCheckResult == AuthResult.REJECT) {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
@@ -71,8 +83,15 @@ mixin PermissionCheckMixin {
|
||||
var authResult = await AuthDialog.show(context, app, authType,
|
||||
eventKind: eventKind, authDetail: authDetail);
|
||||
if (authResult == AuthResult.OK) {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
try {
|
||||
confirm(app, signer);
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
} catch (e) {
|
||||
print("confirm error $e");
|
||||
reject(app);
|
||||
saveAuthLog(
|
||||
app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Submodule packages/nostr_sdk updated: bfa2e7d4d0...ec94e10258
Reference in New Issue
Block a user