Skip to content

feat: Namecoin NIP-05 identity resolution#1

Open
mstrofnone wants to merge 2 commits intoirislib:masterfrom
mstrofnone:feat/namecoin-nip05
Open

feat: Namecoin NIP-05 identity resolution#1
mstrofnone wants to merge 2 commits intoirislib:masterfrom
mstrofnone:feat/namecoin-nip05

Conversation

@mstrofnone
Copy link
Copy Markdown

Namecoin NIP-05 Identity Resolution

This PR adds decentralised NIP-05-style identity verification using Namecoin blockchain names, enabling Nostr identity lookups without relying on centralised HTTP servers.

What is Namecoin?

Namecoin is the first fork of Bitcoin (2011) — a decentralised naming blockchain. Names in the d/ (domain) and id/ (identity) namespaces can store arbitrary JSON values, including Nostr public keys. This enables trustless, censorship-resistant identity verification.

Architecture

Browser  →  HTTP Proxy  →  ElectrumX  →  Namecoin Blockchain
(fetch)     (Node.js)      (TCP/TLS)     (SPV verification)

Browsers cannot open raw TCP/TLS connections to ElectrumX servers, so an HTTP proxy bridges the gap. Three proxy options are included:

  • Vite plugin (vite-plugin-namecoin.mjs) — zero-config dev middleware at /__namecoin
  • Standalone proxy (electrumx-proxy.mjs) — production HTTP server
  • ElectrumX client (electrumx-client.mjs) — reusable Node.js TCP client

The ElectrumX protocol flow:

  1. Build canonical name-index script (OP_NAME_UPDATE + name)
  2. Compute scripthash (SHA-256, byte-reversed)
  3. blockchain.scripthash.get_history → get latest transaction
  4. blockchain.transaction.get → parse NAME_UPDATE script for JSON value
  5. Check expiry (names expire after 36,000 blocks without renewal)

Supported Identifier Formats

Format Resolves to
alice@example.bit d/example → names.alice
_@example.bit / example.bit d/example → root identity
d/example Direct domain namespace lookup
id/alice Direct identity namespace lookup

Namecoin Value Formats

Domain namespace (d/) — NIP-05-compatible:

{ "nostr": { "names": { "alice": "<hex-pubkey>" }, "relays": { "<hex-pubkey>": ["wss://..."] } } }

Identity namespace (id/):

{ "nostr": { "pubkey": "<hex-pubkey>", "relays": ["wss://..."] } }

Both also support the simple form: { "nostr": "<hex-pubkey>" }

Integration

The resolver hooks into the existing getNip05For() function in nip05.ts. When an identifier is detected as Namecoin (.bit suffix, d/, or id/ prefix), it routes to the decentralised resolver instead of the standard HTTPS fetch path. The return type is the same ProfilePointer, so all downstream code works unchanged.

Includes an LRU cache (500 entries, 1hr TTL) to minimise ElectrumX round-trips.

Tests

21 unit tests covering identifier detection, parsing, and value extraction for all supported formats.

Related Work

M added 2 commits April 12, 2026 15:14
Add decentralised NIP-05-style identity verification using Namecoin
blockchain names. Supports d/ (domain) and id/ (identity) namespaces
with .bit domain syntax (alice@example.bit) and direct namespace
syntax (d/example, id/alice).

Architecture: browser → HTTP proxy → ElectrumX → Namecoin blockchain

New files:
- namecoin.ts: identifier detection, parsing, value extraction, resolver
- namecoin.test.ts: 21 unit tests for parsing and value extraction
- namecoin-proxy/electrumx-client.mjs: server-side ElectrumX TCP client
- namecoin-proxy/electrumx-proxy.mjs: standalone HTTP proxy server
- namecoin-proxy/vite-plugin-namecoin.mjs: Vite dev middleware

Modified:
- nip05.ts: route Namecoin identifiers to decentralised resolver
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