nostr-did
Generate W3C-compliant DID Documents from did:nostr identifiers.
Uses nostr-did-key for BIP-340 → Multikey
cryptographic transformation and produces fully spec-compliant documents matching
the Nostr DID Method Specification v0.0.12.
Maintains the official conformance test vectors for the specification — any implementation can validate correctness against this crate's output.
Quick Start
use DocumentBuilder;
let doc = new
.build
.unwrap;
println!;
Output
§2.3.1 Minimal DID Document (Offline)
Zero network — generated deterministically from the public key alone. No services, no profile, no signed parts.
§2.3.3 Complete DID Document (Profile + Social Graph)
Enriched with Nostr kind 0 profile, kind 3 follows, and alsoKnownAs cross-platform links.
modified is computed from max(created_at) of all signed parts.
use ;
let profile = Profile ;
let doc = new
.with_relay
.with_profile
.with_also_known_as
.with_follows
.with_relay_created_at
.build
.unwrap;
Installation
[]
= "0.1"
API Reference
Constructors
| Method | Description |
|---|---|
DocumentBuilder::new() |
Empty builder — produces minimal §2.3.1 documents |
DocumentBuilder::with_defaults() |
Pre-seeded with 5 high-availability relays |
Builder Methods
| Method | Description |
|---|---|
build(did) |
Generate the DID Document |
with_relay(url) |
Add a single relay URL (deduplicated) |
with_relays(vec) |
Replace all relays with a custom set |
with_profile(profile) |
Set Nostr kind 0 profile metadata |
with_also_known_as(vec) |
Set cross-platform identity links |
with_follows(vec) |
Set followed DIDs (kind 3 contacts) |
with_relay_created_at(ts) |
Set relay event timestamp for modified computation |
with_modified(iso8601) |
Explicit modified override (ISO-8601) |
Types
| Type | Description |
|---|---|
DidDocument |
Full W3C-compliant DID Document |
VerificationMethod |
Multikey verification method |
Service |
Relay or FollowsEndpoint service entry |
Profile |
Nostr kind 0 profile metadata |
Design Decisions
- Verification method
idandcontrollerare absolute (did:nostr:<pubkey>#key1) authenticationandassertionMethodreferences are relative ("#key1") — matches DID authoring conventionsmodifiedis computed frommax(created_at)of all signed parts, not hardcoded- Relay IDs are always indexed (
#relay1,#relay2, ...) regardless of count - Parity: canonical Multikey is even-parity
0x02; decoders accept0x03for interop
Conformance Suite
This crate generates the official test vectors for the did:nostr specification. 21 vectors covering key transformation, decoding, error cases, and all three DID Document forms. Vectors are language-agnostic JSON — any implementation can validate correctness by matching the output.
Default Relays (with_defaults())
| Relay | Purpose |
|---|---|
wss://nos.lol |
General purpose, high uptime |
wss://relay.damus.io |
General purpose, Damus ecosystem |
wss://relay.primal.net |
General purpose, Primal ecosystem |
wss://relay.nostr.band |
Full-text search, network trends |
wss://purplepag.es |
Long-form content, user profiles |
Running the Demo
License
Dual-licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)