Ensure NIP-07 permissions are granted before signing and encrypting

This commit is contained in:
thePR0M3TH3AN committed 2025-10-15 22:36:57 -04:00
1 parent a36d807361
commit deffbf7670
6 files changed
+232 -80

No files matched your search

+12 -1
View File
@@ -7,7 +7,10 @@ import {
ADMIN_EDITORS_NPUBS,
isDevMode,
} from "./config.js";
import { nostrClient } from "./nostr.js";
import {
nostrClient,
requestDefaultExtensionPermissions,
} from "./nostr.js";
import { devLogger, userLogger } from "./utils/logger.js";
import {
buildAdminListEvent,
@@ -502,6 +505,14 @@ function publishToRelay(url, signedEvent, listKey) {
async function persistNostrState(actorNpub, updates = {}) {
ensureNostrReady();
const permissionResult = await requestDefaultExtensionPermissions();
if (!permissionResult.ok) {
throw createError(
"extension-permission-denied",
"The NIP-07 extension must allow signing before updating admin lists.",
permissionResult.error,
);
}
const extension = window?.nostr;
if (!extension || typeof extension.signEvent !== "function") {
throw createError(