Repository navigation
Support NIP-44 encryption for Nostr Wallet Connect - #1
Open
Pauciradiatus wants to merge 1 commit into
Open
Pauciradiatus wants to merge 1 commit into
Pauciradiatus wants to merge 1 commit into
Conversation
NWC requests were always decrypted as nip04, whatever their encryption tag said, so a client speaking nip44 got a decryption error and no answer. The info event carried no encryption tag either, which tells spec-following clients the wallet speaks nip04 only. - Add encryptNip44/decryptNip44 to NostrClient, with a cached conversation key - Read the request's encryption tag (absent means nip04) and answer in the same scheme; an unknown scheme gets UNSUPPORTED_ENCRYPTION in nip04 - Advertise "nip44_v2 nip04" in the info event and republish it when the relays hold an outdated one, so existing connections move to nip44 too - Test the helpers against the official NIP-44 v2 vectors and the request handling end to end in both schemes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
NIP-47 deprecates nip04 for Nostr Wallet Connect and asks clients to use nip44 whenever the wallet offers it. The wallet did not support it:
encryptiontag said. A client using nip44 got a decryption error and no response at all.encryptiontag. Clients that follow the spec read that as "nip04 only".What changes
NostrClient.encryptNip44anddecryptNip44(nostr-toolsnip44v2), with a cached conversation key per peer.NwcConnection.handleNwcRequestTaskreads the request'sencryptiontag (no tag means nip04) and decrypts accordingly.sendResponseanswers in the same scheme.UNSUPPORTED_ENCRYPTIONerror, encrypted in nip04.result_typeis empty because the method is inside content the wallet cannot read.["encryption", "nip44_v2 nip04"]. The newNwcStore.ensureInfoEventrepublishes it when the relays hold an outdated one (wrong methods or no tag). It runs when a connection is added and on foreground startup, so existing connections also move to nip44.src/models/NwcEncryption.ts, split out likeNwcTransaction.tsso it can be tested without the whole store.Clients that send no tag see no change: they stay on nip04.
Tests
__tests__/nip44.test.ts: the helpers against the official NIP-44 v2 test vectors (paulmillr/nip44): conversation keys, valid payloads, invalid keys and tampered payloads (78 tests).__tests__/nwcEncryption.test.ts: real NWC requests sent through a connection in nip44, nip04 (with and without tag) and an unknown scheme, read back from the client side. Also coversensureInfoEventand the tag parsing (16 tests). Against the oldNwcStorethe 6 tests for the new behaviour fail.tscand ESLint report the same pre-existing problems asmain, none new.Not yet tested against a real NWC client that speaks nip44, such as Alby Go.
Out of scope
The two remaining nip04 uses with the Minibits server (push payloads, claimed tokens) need a server-side change. Incoming legacy kind-4 DMs are still read.
🤖 Generated with Claude Code