mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-29 00:42:30 +00:00
Merge pull request #717 from PR0M3TH3AN/codex/add-nip44-permissions-to-default_nip07_permission_methods
Request NIP-44 permissions during NIP-07 login
This commit is contained in:
2 files changed
+31
-37
No files matched your search
+13
-6
@@ -196,17 +196,21 @@ const WATCH_HISTORY_REPUBLISH_MAX_DELAY_MS = 5 * 60 * 1000;
|
||||
const WATCH_HISTORY_REPUBLISH_MAX_ATTEMPTS = 8;
|
||||
const WATCH_HISTORY_REPUBLISH_JITTER = 0.25;
|
||||
|
||||
export const DEFAULT_NIP07_ENCRYPTION_METHODS = Object.freeze([
|
||||
// Encryption helpers — request both legacy NIP-04 and modern NIP-44 upfront
|
||||
"nip04.encrypt",
|
||||
"nip04.decrypt",
|
||||
"nip44.encrypt",
|
||||
"nip44.decrypt",
|
||||
]);
|
||||
|
||||
export const DEFAULT_NIP07_PERMISSION_METHODS = Object.freeze([
|
||||
// Core auth + relay metadata
|
||||
"get_public_key",
|
||||
"sign_event",
|
||||
"read_relays",
|
||||
"write_relays",
|
||||
// Encryption helpers — request both legacy NIP-04 and modern NIP-44 upfront
|
||||
"nip04.encrypt",
|
||||
"nip04.decrypt",
|
||||
"nip44.encrypt",
|
||||
"nip44.decrypt",
|
||||
...DEFAULT_NIP07_ENCRYPTION_METHODS,
|
||||
]);
|
||||
|
||||
const viewEventPublishMemory = new Map();
|
||||
@@ -560,7 +564,10 @@ async function runNip07WithRetry(
|
||||
}
|
||||
}
|
||||
|
||||
export const __testExports = { runNip07WithRetry };
|
||||
export const __testExports = {
|
||||
runNip07WithRetry,
|
||||
DEFAULT_NIP07_ENCRYPTION_METHODS,
|
||||
};
|
||||
|
||||
function withRequestTimeout(promise, timeoutMs, onTimeout, message = "Request timed out") {
|
||||
const resolvedTimeout = Number(timeoutMs);
|
||||
|
||||
@@ -5,7 +5,16 @@ import test from "node:test";
|
||||
import { NostrClient, nostrClient, __testExports } from "../js/nostr.js";
|
||||
import { accessControl } from "../js/accessControl.js";
|
||||
|
||||
const { runNip07WithRetry } = __testExports ?? {};
|
||||
const {
|
||||
runNip07WithRetry,
|
||||
DEFAULT_NIP07_ENCRYPTION_METHODS,
|
||||
} = __testExports ?? {};
|
||||
|
||||
const EXPECTED_ENCRYPTION_PERMISSIONS = Array.isArray(
|
||||
DEFAULT_NIP07_ENCRYPTION_METHODS,
|
||||
)
|
||||
? DEFAULT_NIP07_ENCRYPTION_METHODS
|
||||
: ["nip04.encrypt", "nip04.decrypt", "nip44.encrypt", "nip44.decrypt"];
|
||||
|
||||
const HEX_PUBKEY = "f".repeat(64);
|
||||
const PERMISSIONS_STORAGE_KEY = "bitvid:nip07:permissions";
|
||||
@@ -143,26 +152,16 @@ test("NIP-07 login requests decrypt permissions upfront", async () => {
|
||||
const pubkey = await nostrClient.login();
|
||||
assert.equal(pubkey, HEX_PUBKEY);
|
||||
assert.ok(env.enableCalls.length >= 1, "extension.enable should be invoked");
|
||||
assert.ok(
|
||||
nostrClient.extensionPermissionCache.has("nip04.decrypt"),
|
||||
"nip04.decrypt permission should be tracked as granted",
|
||||
);
|
||||
assert.ok(
|
||||
nostrClient.extensionPermissionCache.has("nip04.encrypt"),
|
||||
"nip04.encrypt permission should be tracked as granted",
|
||||
);
|
||||
for (const method of EXPECTED_ENCRYPTION_PERMISSIONS) {
|
||||
assert.ok(
|
||||
nostrClient.extensionPermissionCache.has(method),
|
||||
`${method} permission should be tracked as granted`,
|
||||
);
|
||||
}
|
||||
assert.ok(
|
||||
nostrClient.extensionPermissionCache.has("sign_event"),
|
||||
"sign_event permission should be tracked as granted",
|
||||
);
|
||||
assert.ok(
|
||||
nostrClient.extensionPermissionCache.has("nip44.encrypt"),
|
||||
"nip44.encrypt permission should be tracked as granted",
|
||||
);
|
||||
assert.ok(
|
||||
nostrClient.extensionPermissionCache.has("nip44.decrypt"),
|
||||
"nip44.decrypt permission should be tracked as granted",
|
||||
);
|
||||
} finally {
|
||||
env.restore();
|
||||
nostrClient.logout();
|
||||
@@ -204,13 +203,7 @@ test("NIP-07 decrypt reuses cached extension permissions", async () => {
|
||||
.map((method) => method.trim())
|
||||
.filter(Boolean),
|
||||
);
|
||||
const expectedStoredPermissions = [
|
||||
"nip04.decrypt",
|
||||
"nip04.encrypt",
|
||||
"nip44.encrypt",
|
||||
"nip44.decrypt",
|
||||
];
|
||||
for (const method of expectedStoredPermissions) {
|
||||
for (const method of EXPECTED_ENCRYPTION_PERMISSIONS) {
|
||||
assert.ok(
|
||||
storedSet.has(method),
|
||||
`stored permissions should include ${method}`,
|
||||
@@ -220,13 +213,7 @@ test("NIP-07 decrypt reuses cached extension permissions", async () => {
|
||||
const freshClient = new NostrClient();
|
||||
freshClient.pubkey = HEX_PUBKEY;
|
||||
|
||||
const expectedCachedPermissions = [
|
||||
"nip04.decrypt",
|
||||
"nip04.encrypt",
|
||||
"nip44.encrypt",
|
||||
"nip44.decrypt",
|
||||
];
|
||||
for (const method of expectedCachedPermissions) {
|
||||
for (const method of EXPECTED_ENCRYPTION_PERMISSIONS) {
|
||||
assert.ok(
|
||||
freshClient.extensionPermissionCache.has(method),
|
||||
`fresh client should hydrate ${method} from storage`,
|
||||
|
||||
Reference in new issue
Block a user