SNIP-08: IPFS over Nostr

⚡tephen

published

draft optional

This SNIP defines a standard for publishing, referencing, discovering, and persisting IPFS (InterPlanetary File System) content using Nostr events. It introduces specific event kinds for static manifests, mutable pointers, and a Data Vending Machine (DVM) workflow for storage pinning services.

Motivation

Nostr relays are optimized for small, text-based messages, not large file storage. While NIP-94 exists for file metadata, it is storage-agnostic and often relies on centralized HTTP URLs.

Integrating IPFS allows Nostr to serve as a Global Signaling Layer for a Decentralized Storage Layer. This enables:

  • True Permanence: Content is addressed by its hash (CID), making it verifiable and immutable.
  • Relay Efficiency: Relays store only the tiny event manifest, while the IPFS swarm handles the data.
  • Deduplication: The same file shared by thousands of users results in a single referenced CID.
  • Marketplace: A native way to request and pay for storage persistence (Pinning) using Lightning.

Specification

1. Static Content Manifest (kind:4737)

This event represents a static, immutable file or directory on the IPFS network.

Kind: 4737 (Mnemonic: IPFS on a telephone keypad)

Tags

  • ipfs (required): The IPFS Content Identifier (CID). Should be a version 1 CID (starts with b) for future compatibility, but v0 (starts with Q) is acceptable.
    • Example: ["ipfs", "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi"]
  • size (optional): Size of the file in bytes.
    • Example: ["size", "123456"]
  • m (optional): MIME type.
    • Example: ["m", "image/png"]
  • name (optional): Suggested filename.
    • Example: ["name", "cool_avatar.png"]
  • gateway (optional, repeatable): A hint for a public or private gateway where this content is known to be seeded. This acts like a "Relay Hint" but for file data.
  • thumb (optional): A URL (HTTP or IPFS gateway link) to a thumbnail for preview purposes.

Content

The .content field is a human-readable description or caption for the file.

2. Mutable IPNS Record (kind:34737)

This event represents a mutable pointer (InterPlanetary Name System). Unlike a CID which changes if the file changes, an IPNS record provides a static address (via the d tag) that points to the current version of a file.

Kind: 34737 (Parameterized Replaceable Event)

Tags

  • d (required): A unique identifier for this record (e.g., "my-website", "daily-backup").
  • ipns (required): The IPNS key (usually the Peer ID or a key hash).
  • ipfs (recommended): The current CID that this record resolves to. This allows clients to fetch the content immediately without performing a slow IPNS DHT lookup.
  • gateway (optional): Gateway hints.

Content

Description of the mutable resource.

3. Pinning Service (DVM Workflow)

Storage persistence is not guaranteed on IPFS. This section defines a mechanism for users to request (and potentially pay for) "Pinning" services from relays or DVMs, adhering to NIP-90.

Service Discovery (kind:31990)

Pinning providers announce their service using NIP-89 Handler Information.

  • k: 5437 (The job kind they handle).
  • d: Unique service identifier.
  • amount: (Optional) Base price in msats.

Job Request (kind:5437)

A user publishes this event to request that a service provider pin a specific CID.

  • i (required): The input CID to pin.
    • Format: ["i", "", "ipfs"]
  • param (optional): Retention duration.
    • Format: ["param", "retention", ""]
  • p (optional): The pubkey of a specific DVM to target.

Job Result (kind:6437)

The service provider responds with the status of the pin.

  • request (required): The event ID of the job request.
  • e: The event ID of the job request.
  • status (required):
    • success: Content is pinned.
    • error: Pinning failed.
    • payment-required: Payment is needed to proceed.
  • amount (conditional): If status is payment-required, the requested amount in millisats.

Payment Flow (NIP-57)

  1. User publishes Job Request (5437).
  2. DVM responds with Job Result (6437) containing ["status", "payment-required"] and ["amount", "100000"].
  3. User sends a Zap (9735) to the DVM's pubkey, referencing the Job Request ID in the e tag.
  4. DVM detects the Zap, verifies the amount, pins the content, and publishes a new Job Result (6437) with ["status", "success"].

Client Implementation Guidelines

Discovery

  1. Parse: Clients parse the ipfs tag to get the CID.
  2. Fetch:
    • Tier 1 (Local): If the client has a local IPFS node, request directly.
    • Tier 2 (Gateway Hint): Use provided gateway tags.
    • Tier 3 (Public Fallback): Fall back to a list of known public gateways.

Verification

Clients MUST verify integrity.

  • IPFS: When fetching via a local node, verification is automatic.
  • HTTP Gateway: The client SHOULD verify that the downloaded file hashes to the CID claimed in the event if strictly necessary, though trust-on-first-use is common for web clients.

Security Considerations

  • Content Safety: IPFS content is not inherently safe. Clients should apply standard malware scanning or sandboxing (e.g., CSP headers for HTML).
  • Privacy: IPFS is a public network. Publishing a kind:4737 broadcasts the file's existence. Sensitive data MUST be encrypted before adding to IPFS.
  • Deduplication Leaks: Because IPFS deduplicates content, if two users upload the exact same file, they generate the same CID. An observer could link identities based on shared unique files.

Example Events

Static Manifest:

{  
  "kind": 4737,  
  "tags": [  
    ["ipfs", "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi"],  
    ["m", "video/mp4"],  
    ["size", "54920392"],  
    ["gateway", "[https://ipfs.io/ipfs/](https://ipfs.io/ipfs/)"]  
  ],  
  "content": "My skate video"  
}

Pin Request:

{  
  "kind": 5437,  
  "tags": [  
    ["i", "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi", "ipfs"],  
    ["param", "retention", "604800"]  
  ],  
  "content": "Pin for 1 week"  
}  

Discussion

Connect a key to comment.