8000 Support NIP-44 encryption for Nostr Wallet Connect by Pauciradiatus · Pull Request #1 · Pauciradiatus/minibits_NIP-44 · GitHub
[go: up one dir, main page]

Skip to content

Support NIP-44 encryption for Nostr Wallet Connect - #1

Open
Pauciradiatus wants to merge 1 commit into
mainfrom
feat/nwc-nip44
Open

Pauciradiatus wants to merge 1 commit into
mainfrom
feat/nwc-nip44

Conversation

@Pauciradiatus
Copy link
Copy Markdown
Owner

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:

  • Every request was decrypted as nip04, whatever its encryption tag said. A client using nip44 got a decryption error and no response at all.
  • The info event (kind 13194) carried no encryption tag. Clients that follow the spec read that as "nip04 only".

What changes

  • NIP-44 helpers: NostrClient.encryptNip44 and decryptNip44 (nostr-tools nip44 v2), with a cached conversation key per peer.
  • Request handling: NwcConnection.handleNwcRequestTask reads the request's encryption tag (no tag means nip04) and decrypts accordingly. sendResponse answers in the same scheme.
  • Unsupported schemes: an unknown scheme gets an UNSUPPORTED_ENCRYPTION error, encrypted in nip04. result_type is empty because the method is inside content the wallet cannot read.
  • Info event: it advertises ["encryption", "nip44_v2 nip04"]. The new NwcStore.ensureInfoEvent republishes 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.
  • New module: the negotiation logic lives in src/models/NwcEncryption.ts, split out like NwcTransaction.ts so 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 covers ensureInfoEvent and the tag parsing (16 tests). Against the old NwcStore the 6 tests for the new behaviour fail.
  • Full suite: 833 passed. tsc and ESLint report the same pre-existing problems as main, 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0