ndk
ndk copied to clipboard
Bug: ndkSignerFromPayload restores correctly but sign() hangs
🐞 Bug: ndkSignerFromPayload restores correctly but sign() hangs
NDK Version: @nostr-dev-kit/[email protected]
Context: I'm using NDKNip46Signer with persistence via toPayload() and restore via ndkSignerFromPayload(...).
✅ Login Phase
const localSigner = NDKPrivateKeySigner.generate();
const signer = NDKNip46Signer.bunker(ndk, bunkerUri, localSigner.privateKey);
signer.on("authUrl", (url) => {
window.open(url, "auth", "width=400,height=700");
});
await signer.blockUntilReady();
ndk.signer = signer;
const payloadString = signer.toPayload();
localStorage.setItem("currentUserSigner", payloadString);
✅ Restore Phase
const storedPayload = localStorage.getItem("currentUserSigner");
if (storedPayload) {
try {
const restoredSigner = await ndkSignerFromPayload(storedPayload, ndk);
ndk.signer = restoredSigner;
console.log("Signer restored successfully!");
const user = await restoredSigner.user();
console.log("Restored user pubkey:", user.pubkey);
} catch (error) {
console.error("Error during signer deserialization:", error);
}
}
❌ Problem
After restoring:
-
restoredSigner.user()works fine - but
await event.sign()hangs forever (no result, no error) -
restoredSigner.rpcisundefined - so no signing request is actually sent via NIP-46
🔎 Hypothesis
The payload generated via toPayload() looks complete (type: "nip46", relayUrls, etc.), but upon deserialization, the internal NIP-46 connection (rpc) is not being properly initialized or persisted.
✅ Possible Fix
ndkSignerFromPayload(...) (or NDKNip46Signer.fromPayload(...)) may not reliably initialize rpc or call connect() internally.
📌 Request
Please verify that:
-
rpcis initialized during payload restore -
connect()is called internally or exposed for manual reconnection if needed
Thanks for the amazing work on NDK 🙏
@alessiofx I migrated my app to using this instead, and it is working https://welshman.coracle.social/signer/nip-46.html