Nostr npubs are self-describing: any client can compute which prefix or
suffix edge to display prominently using the difficulty metric
L × (5 − H).
Paste an npub or generate a random one. The resolver finds the edge with the highest difficulty (bits of pattern) and highlights it.
Each row shows the difficulty for a prefix edge (right) and suffix edge (left) of that length. The winning edge is highlighted.
Compare random npubs (no visible edge, low difficulty) with mined npubs (obvious green edge, high difficulty). This is the asymmetric anti-impersonation advantage.
Every npub is encoded in bech32, which uses exactly 32 symbols:
Bech32 deliberately excludes 1, b,
i, and o to prevent visual confusion
(1 vs l,
0 vs o). That leaves
36 − 4 = 32 symbols.
Shannon entropy of a uniform distribution over N symbols is
log2(N). For bech32:
log2(32) = log2(25) = 5.0 bits per character
This is the maximum possible entropy — a perfectly random bech32 string has entropy exactly 5.0 bits/char. Any pattern (repeated characters, skewed distribution) drives it below 5.0. The value 5.0 is not a tuning parameter; it is mathematically determined by the bech32 specification. Anyone who knows the charset can derive it.
L × (5 − H)L is the edge length (characters from the start or end of the npub data). H is the Shannon entropy of those characters. The product measures bits of pattern — how far below maximum randomness the edge is, scaled by its length.
H ≤ 3.0Edges with entropy above 3.0 = log2(8) are "barely below random" and receive zero difficulty. Only edges using effectively ≤ 8 of the 32 bech32 symbols qualify. This prevents a long mediocre edge (e.g. 29 chars at H=4.0) from outscoring a short genuinely-patterned edge (e.g. 10 chars at H=1.0).
| Edge | L | H | Above floor? | Difficulty | Visual |
|---|---|---|---|---|---|
aa | 2 | 0.0 | no | 10.0 | Trivial |
aaaaaaabcab | 10 | 0.7 | no | 43.0 | Good |
aaaaabcaaaabcd | 14 | 1.2 | no | 53.2 | Very recognizable |
qpzry9x8gf2tvdw0 | 16 | 4.0 | yes → zeroed | 0.0 | Rejected — too random |
abcdefghijklmnopqrs | 20 | 4.1 | yes → zeroed | 0.0 | Rejected — too random |
Classic vanity npubs (e.g. npub1rana...) are forgeable:
an attacker can mine a look-alike prefix at the same cost the original
holder paid. The vanity property is symmetric.
Low-entropy edges flip this into an asymmetric defense. An attacker can mine another npub with similarly low entropy, but the residual randomness forces the result to look recognisably different. Pattern-imitation is not identity-imitation.
The bestEdge(npub) function is deterministic and requires
no parameters beyond the constants 5.0 (derived from the
bech32 charset) and 3.0 (the quality floor). Any Nostr
client can implement it to determine which portion of an npub to display
prominently. The miner (rana) and the client agree on the same edge
without any out-of-band communication.
cargo install rana rana --entropy-difficulty=40