diag(nip46): add temporary lifecycle diagnostics for #33

Code-level audit of the NIP-46/Amber login+profile+persistence bug points at a
single shared SignerManager.nip46Client + per-profile restore/switch not being
multi-account-aware. Added TEMP [nip46-diag] userLogger traces (visible on
unstable; devLogger is gated off there) at:
- scheduleStoredRemoteSignerRestore (restore-on-load → "unknown user")
- disconnectRemoteSigner (the shared-client teardown → "logs out everyone")
- SignerManager.logout (scope)
- authService.switchProfile (does the switch resolve the expected pubkey)

These let a single Amber reproduction pinpoint the exact failure before the fix.
Findings + plan recorded under TODO #33. Remove diagnostics with the fix.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.8 committed 2026-06-29 20:22:40 -04:00
1 parent adf0488df8
commit 088a5c797d
3 files changed
+76 -1

No files matched your search

+17
View File
@@ -977,6 +977,12 @@ export default class AuthService {
const providerId = normalizeProviderId(normalizedOptions.providerId);
const normalizedActive = this.normalizeHexPubkey(getActiveProfilePubkey());
// [nip46-diag] TEMP (todo #33): trace profile switching — from/to + provider.
userLogger.info("[nip46-diag] switchProfile: begin", {
from: normalizedActive || null,
to: normalizedTarget,
providerId: providerId || null,
});
if (normalizedActive && normalizedActive === normalizedTarget) {
return { switched: false, reason: "already-active" };
}
@@ -993,6 +999,10 @@ export default class AuthService {
try {
requestResult = await this.requestLogin(requestOptions);
} catch (error) {
userLogger.warn("[nip46-diag] switchProfile: requestLogin FAILED", {
to: normalizedTarget,
message: error?.message || String(error),
});
throw error;
}
@@ -1001,6 +1011,13 @@ export default class AuthService {
(typeof requestResult?.pubkey === "string"
? requestResult.pubkey.trim()
: "");
// [nip46-diag] TEMP (todo #33): did the switch resolve the EXPECTED pubkey?
userLogger.info("[nip46-diag] switchProfile: requestLogin returned", {
to: normalizedTarget,
requestedPubkey: requestedPubkey || null,
matchesTarget: requestedPubkey === normalizedTarget,
hasDetail: !!requestResult?.detail,
});
let detail = requestResult?.detail || null;