Skip to content

feat: Namecoin NIP-05 identity resolution (.bit domains, d/ and id/ namespaces)#623

Open
mstrofnone wants to merge 2 commits intov0l:mainfrom
mstrofnone:feat/namecoin-nip05
Open

feat: Namecoin NIP-05 identity resolution (.bit domains, d/ and id/ namespaces)#623
mstrofnone wants to merge 2 commits intov0l:mainfrom
mstrofnone:feat/namecoin-nip05

Conversation

@mstrofnone
Copy link
Copy Markdown

Summary

Add decentralised NIP-05-style identity verification via the Namecoin blockchain. Users with .bit domains or d//id/ namespace names can have their Nostr public keys verified without relying on centralised HTTP servers.

What is Namecoin?

Namecoin is a decentralised naming blockchain (the first fork of Bitcoin, launched 2011). Names registered in the d/ (domain) and id/ (identity) namespaces can store arbitrary JSON values, including Nostr public keys. This enables fully decentralised NIP-05 — identity verification that depends on no single server, registrar, or DNS provider.

Architecture

Browser  ──HTTP──▶  Proxy  ──TCP/TLS──▶  ElectrumX  ──▶  Namecoin blockchain
(fetch)           (Node.js)             (nmc2.bitcoins.sk:57001)

Browsers cannot make raw TCP/TLS connections to ElectrumX servers. A lightweight HTTP proxy bridges the gap, handling all ElectrumX protocol details:

  1. Build canonical name index script (OP_NAME_UPDATE + name + empty + OP_2DROP OP_DROP OP_RETURN)
  2. Compute Electrum-style scripthash (SHA-256, byte-reversed)
  3. Query blockchain.scripthash.get_history
  4. Fetch raw transaction and parse NAME_UPDATE script
  5. Check name expiry against current block height (NAME_EXPIRE_DEPTH = 36000)

Supported Identifier Formats

Input Namecoin name Lookup
alice@example.bit d/example Look up alice in nostr.names
_@example.bit d/example Root entry
example.bit d/example Root entry
d/example d/example Direct domain lookup
id/alice id/alice Identity namespace lookup

Namecoin Value Formats

Domain (d/) — simple:

{"nostr": "hex64pubkey"}

Domain (d/) — NIP-05-like extended:

{"nostr": {"names": {"alice": "hex64pubkey"}, "relays": {"hex64pubkey": ["wss://..."]}}}

Identity (id/) — simple:

{"nostr": "hex64pubkey"}

Identity (id/) — with relays:

{"nostr": {"pubkey": "hex64pubkey", "relays": ["wss://..."]}}

Changes

New files

  • packages/shared/src/namecoin.ts — Core resolver module with LRU cache, identifier parsing, value extraction
  • packages/shared/src/namecoin.test.ts — Unit tests for parsing and value extraction
  • proxy/electrumx-client.mjs — Server-side ElectrumX TCP/TLS client
  • proxy/electrumx-proxy.mjs — Standalone HTTP proxy server
  • proxy/vite-plugin-namecoin.mjs — Vite dev middleware for zero-setup development

Modified files

  • packages/shared/src/utils.ts — Routes .bit domains to Namecoin resolver in fetchNip05PubkeyWithThrow and fetchNostrAddressWithThrow
  • packages/shared/src/index.ts — Exports namecoin module
  • packages/app/src/Components/User/Nip05.tsx — Amber .bit badge with ⛓ chain-link icon and "Verified via Namecoin blockchain" tooltip
  • packages/app/vite.config.ts — Registers Vite proxy plugin for dev

How to Run

Development (zero setup)

The Vite plugin automatically serves /api/namecoin/* during bun run dev, proxying to the default ElectrumX server. No additional configuration needed.

Production

Set VITE_NAMECOIN_PROXY_URL to your hosted proxy URL:

VITE_NAMECOIN_PROXY_URL=https://your-proxy.example.com

Or run the standalone proxy:

node proxy/electrumx-proxy.mjs --port 8089 --host nmc2.bitcoins.sk --electrum-port 57001

Prior Art

M added 2 commits April 12, 2026 15:13
Add decentralised NIP-05-style identity verification via the Namecoin
blockchain. Users with .bit domains or d//id/ namespace names can now
have their Nostr pubkeys verified without relying on HTTP servers.

Architecture:
- Browser -> HTTP proxy -> ElectrumX TCP/TLS -> Namecoin blockchain
- Proxy handles scripthash computation, tx parsing, NAME_UPDATE extraction
- LRU cache (1h TTL, 500 entries) for resolved identities

Components:
- packages/shared/src/namecoin.ts: Core resolver module
  - isNamecoinIdentifier() detection
  - parseNamecoinIdentifier() for all formats
  - resolveNamecoin/resolveNamecoinCached with LRU cache
  - verifyNamecoinNip05 for pubkey verification
  - fetchNamecoinNip05Pubkey/fetchNamecoinNostrAddress for compatibility

- proxy/electrumx-client.mjs: Server-side ElectrumX TCP/TLS client
  - Canonical name index script construction
  - Electrum-style scripthash computation (SHA-256, byte-reversed)
  - blockchain.scripthash.get_history queries
  - Raw transaction parsing for NAME_UPDATE scripts
  - Name expiry checking (NAME_EXPIRE_DEPTH = 36000 blocks)

- proxy/electrumx-proxy.mjs: Standalone HTTP proxy server
- proxy/vite-plugin-namecoin.mjs: Vite dev middleware (zero-setup)

- Modified packages/shared/src/utils.ts:
  - fetchNip05PubkeyWithThrow routes .bit to Namecoin resolver
  - fetchNostrAddressWithThrow routes .bit to Namecoin resolver

- Modified packages/app/src/Components/User/Nip05.tsx:
  - Amber-colored .bit domain display
  - Chain-link emoji badge for Namecoin-verified identities
  - 'Verified via Namecoin blockchain' tooltip

- packages/shared/src/namecoin.test.ts: Unit tests

Supported identifier formats:
- alice@example.bit -> d/example, look up 'alice'
- _@example.bit / example.bit -> d/example, root entry
- d/example -> direct domain lookup
- id/alice -> identity namespace lookup

Default ElectrumX server: nmc2.bitcoins.sk:57001
Replaces the HTTP proxy approach with direct WebSocket connections
from the browser to ElectrumX servers. No backend or middleware
required — works as a fully static web app.

Based on the approach from hzrd149/nostrudel#352
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