android content query add reject colum

This commit is contained in:
DASHU
2025-06-03 18:02:02 +08:00
parent bbc8dee210
commit b9d41594d4
6 changed files with 48 additions and 23 deletions

View File

@@ -254,7 +254,7 @@ class _WebViewComponent extends State<WebViewComponent>
}
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<WebViewComponent>
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<WebViewComponent>
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<WebViewComponent>
}
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<WebViewComponent>
}
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<WebViewComponent>
}
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<WebViewComponent>
}
checkPermission(context, AppType.WEB, code, AuthType.NIP44_DECRYPT,
(app) {
(app, rejectType) {
nip07Reject(resultId, "Forbid");
}, (app, signer) async {
var resultStr = await signer.nip44Decrypt(pubkey, ciphertext);

View File

@@ -0,0 +1,4 @@
class RejectType {
static const int OTHERS = 0;
static const int REJECT = 1;
}

View File

@@ -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<int?>();
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;
}

View File

@@ -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(

View File

@@ -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<void> checkPermission(BuildContext? context, int appType, String code,
int authType, Function(App?) reject, Function(App, NostrSigner) confirm,
{int? eventKind, String? authDetail}) async {
Future<void> 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;
}

View File

@@ -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);