fix(auth): restore NIP-07 permission request flow on login (agent)

This change restores the missing `ensureExtensionPermissions` call in `NostrClient.loginWithExtension` to ensure that encryption permissions (NIP-04/NIP-44) are requested upfront as intended. It also updates the unit tests to match the current optimized permission request strategy (Plain -> Structured -> String) and fixes a timeout calculation logic that was preventing fast test execution.

- js/nostr/client.js: Added `ensureExtensionPermissions` call in `loginWithExtension` and throw on failure.
- js/nostr/nip07Permissions.js: Allow short timeouts (<1s) to bypass the default 15s minimum for faster testing.
- tests/nostr-login-permissions.test.mjs: Updated test expectations to match the Plain -> Structured -> String request order.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-01-28 20:17:13 +00:00
1 parent 617095d995
commit 9edf4e3e6b
3 files changed
+27 -29

No files matched your search

+9
View File
@@ -2107,6 +2107,15 @@ export class NostrClient {
adapter.pubkey = pubkey;
setActiveSigner(adapter);
const permissionResult = await this.ensureExtensionPermissions([
...DEFAULT_NIP07_PERMISSION_METHODS,
...DEFAULT_NIP07_ENCRYPTION_METHODS,
]);
if (!permissionResult.ok) {
throw permissionResult.error;
}
return { pubkey, signer: adapter };
}
+4 -4
View File
@@ -338,10 +338,10 @@ export async function requestEnablePermissions(
const enableTimeoutMs = getEnableVariantTimeoutMs();
const loginTimeoutMs = getNip07LoginTimeoutMs();
const shortEnableTimeoutMs = Math.min(5_000, enableTimeoutMs);
const explicitEnableTimeoutMs = Math.max(
enableTimeoutMs,
Math.min(15_000, loginTimeoutMs),
);
const explicitEnableTimeoutMs =
enableTimeoutMs < 1000
? enableTimeoutMs
: Math.max(enableTimeoutMs, Math.min(15_000, loginTimeoutMs));
let lastError = null;
for (const options of permissionVariants) {