diff --git a/lib/component/webview/webview_component.dart b/lib/component/webview/webview_component.dart index 90b319e..14e772d 100644 --- a/lib/component/webview/webview_component.dart +++ b/lib/component/webview/webview_component.dart @@ -254,7 +254,7 @@ class _WebViewComponent extends State } checkPermission(context, AppType.WEB, code, AuthType.GET_PUBLIC_KEY, - (app) { + (app, rejectType) { nip07Reject(resultId, "Forbid"); }, (app, signer) { print("confirm get pubkey"); @@ -283,7 +283,7 @@ class _WebViewComponent extends State var eventKind = eventObj["kind"]; if (eventKind is int) { checkPermission(context, AppType.WEB, code, AuthType.SIGN_EVENT, - eventKind: eventKind, authDetail: content, (app) { + eventKind: eventKind, authDetail: content, (app, rejectType) { nip07Reject(resultId, "Forbid"); }, (app, signer) async { var tags = eventObj["tags"]; @@ -321,7 +321,8 @@ class _WebViewComponent extends State return; } - checkPermission(context, AppType.WEB, code, AuthType.GET_RELAYS, (app) { + checkPermission(context, AppType.WEB, code, AuthType.GET_RELAYS, + (app, rejectType) { nip07Reject(resultId, "Forbid"); }, (app, signer) { // TODO handle getRelays @@ -359,7 +360,7 @@ class _WebViewComponent extends State } checkPermission(context, AppType.WEB, code, AuthType.NIP04_ENCRYPT, - (app) { + (app, rejectType) { nip07Reject(resultId, "Forbid"); }, (app, signer) async { var resultStr = await signer.encrypt(pubkey, plaintext); @@ -391,7 +392,7 @@ class _WebViewComponent extends State } checkPermission(context, AppType.WEB, code, AuthType.NIP04_DECRYPT, - (app) { + (app, rejectType) { nip07Reject(resultId, "Forbid"); }, (app, signer) async { var app = appProvider.getApp(AppType.WEB, code); @@ -426,7 +427,7 @@ class _WebViewComponent extends State } checkPermission(context, AppType.WEB, code, AuthType.NIP44_ENCRYPT, - (app) { + (app, rejectType) { nip07Reject(resultId, "Forbid"); }, (app, signer) async { var resultStr = await signer.nip44Encrypt(pubkey, plaintext); @@ -458,7 +459,7 @@ class _WebViewComponent extends State } checkPermission(context, AppType.WEB, code, AuthType.NIP44_DECRYPT, - (app) { + (app, rejectType) { nip07Reject(resultId, "Forbid"); }, (app, signer) async { var resultStr = await signer.nip44Decrypt(pubkey, ciphertext); diff --git a/lib/const/reject_type.dart b/lib/const/reject_type.dart new file mode 100644 index 0000000..f5e0591 --- /dev/null +++ b/lib/const/reject_type.dart @@ -0,0 +1,4 @@ +class RejectType { + static const int OTHERS = 0; + static const int REJECT = 1; +} diff --git a/lib/provider/android_signer_content_resolver_provider.dart b/lib/provider/android_signer_content_resolver_provider.dart index 4c274f9..6637b50 100644 --- a/lib/provider/android_signer_content_resolver_provider.dart +++ b/lib/provider/android_signer_content_resolver_provider.dart @@ -10,6 +10,7 @@ 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/const/reject_type.dart'; import 'package:nowser/provider/permission_check_mixin.dart'; import '../const/auth_result.dart'; @@ -148,13 +149,14 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider App? app; NostrSigner? signer; - var complete = Completer(); + var complete = Completer(); - rejectFunc(_app) { + rejectFunc(_app, rejectType) { if (_app != null) { saveAuthLog(_app, authType, eventKind, authDetail, AuthResult.REJECT); } - complete.complete(); + + complete.complete(rejectType); } confirmFunc(_app, _signer) { @@ -166,8 +168,17 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider checkPermission(null, appType, code!, authType, rejectFunc, confirmFunc, eventKind: eventKind, authDetail: authDetail); - await complete.future; + var rejectType = await complete.future; if (signer == null || app == null) { + if (rejectType == AuthResult.REJECT) { + // if there is a rejected colum, the app will not open the signer app. + data = MatrixCursorData( + columnNames: ["rejected"], notificationUris: [uri]); + data.addRow(["Could not decrypt the message"]); + return data; + } + + /// The app will open the signer with to ask sign request again. return null; } diff --git a/lib/provider/android_signer_mixin.dart b/lib/provider/android_signer_mixin.dart index d06ae25..97a1b8d 100644 --- a/lib/provider/android_signer_mixin.dart +++ b/lib/provider/android_signer_mixin.dart @@ -109,7 +109,7 @@ mixin AndroidSignerMixin on PermissionCheckMixin { } checkPermission(context, AppType.ANDROID_APP, code!, authType, - eventKind: eventKind, authDetail: playload, (app) { + eventKind: eventKind, authDetail: playload, (app, rejectType) { // this place should do some about reject if (app != null) { saveAuthLog( diff --git a/lib/provider/permission_check_mixin.dart b/lib/provider/permission_check_mixin.dart index 95448d4..adc8b17 100644 --- a/lib/provider/permission_check_mixin.dart +++ b/lib/provider/permission_check_mixin.dart @@ -4,6 +4,7 @@ import 'package:nowser/component/auth_dialog/auth_app_connect_dialog.dart'; import 'package:nowser/component/auth_dialog/auth_dialog.dart'; import 'package:nowser/component/user/user_login_dialog.dart'; import 'package:nowser/const/auth_result.dart'; +import 'package:nowser/const/reject_type.dart'; import 'package:nowser/data/auth_log.dart'; import 'package:nowser/data/auth_log_db.dart'; import 'package:nowser/main.dart'; @@ -12,9 +13,15 @@ import '../const/connect_type.dart'; import '../data/app.dart'; mixin PermissionCheckMixin { - Future checkPermission(BuildContext? context, int appType, String code, - int authType, Function(App?) reject, Function(App, NostrSigner) confirm, - {int? eventKind, String? authDetail}) async { + Future checkPermission( + BuildContext? context, + int appType, + String code, + int authType, + Function(App?, int rejectType) reject, + Function(App, NostrSigner) confirm, + {int? eventKind, + String? authDetail}) async { if (keyProvider.keys.isEmpty) { // should add a key first if (context != null) { @@ -38,14 +45,14 @@ mixin PermissionCheckMixin { if (app == null) { // not allow connect - reject(null); + reject(null, RejectType.OTHERS); return; } var signer = await getSigner(app.pubkey!); if (signer == null) { saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT); - reject(app); + reject(app, RejectType.OTHERS); return; } @@ -55,7 +62,7 @@ mixin PermissionCheckMixin { saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK); } catch (e) { print("confirm error $e"); - reject(app); + reject(app, RejectType.OTHERS); saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT); } return; @@ -69,13 +76,13 @@ mixin PermissionCheckMixin { saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK); } catch (e) { print("confirm error $e"); - reject(app); + reject(app, RejectType.OTHERS); saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT); } return; } else if (permissionCheckResult == AuthResult.REJECT) { saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT); - reject(app); + reject(app, RejectType.REJECT); return; } @@ -88,17 +95,19 @@ mixin PermissionCheckMixin { saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK); } catch (e) { print("confirm error $e"); - reject(app); + reject(app, RejectType.OTHERS); saveAuthLog( app, authType, eventKind, authDetail, AuthResult.REJECT); } return; + } else if (authResult == AuthResult.REJECT) { + // return reject here ? } } } saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT); - reject(app); + reject(app, RejectType.OTHERS); return; } diff --git a/lib/provider/remote_signing_provider.dart b/lib/provider/remote_signing_provider.dart index 59116b7..0cc5604 100644 --- a/lib/provider/remote_signing_provider.dart +++ b/lib/provider/remote_signing_provider.dart @@ -231,7 +231,7 @@ class RemoteSigningProvider extends ChangeNotifier with PermissionCheckMixin { } checkPermission(context!, appType, code, authType, - eventKind: eventKind, authDetail: authDetail, (app) { + eventKind: eventKind, authDetail: authDetail, (app, rejectType) { response = NostrRemoteResponse(request.id, "", error: "forbid"); sendResponse( relays, response, signerSigner, localPubkey, remoteSignerPubkey);