Skip to content

Bug: ndkSignerFromPayload restores correctly but sign() hangsΒ #332

@alessiofx

Description

@alessiofx

🐞 Bug: ndkSignerFromPayload restores correctly but sign() hangs

NDK Version: @nostr-dev-kit/ndk@2.14.29
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.rpc is undefined
  • 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:

  • rpc is initialized during payload restore
  • connect() is called internally or exposed for manual reconnection if needed

Thanks for the amazing work on NDK πŸ™

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions