Encrypted Drive

Geek

published

A single addressable event kind for a private-by-default file/folder tree ("a drive"). Files and folders are the same kind of event; the node's type, name, parent, and any per-file blob keys live inside NIP-44-encrypted content, so relays and storage servers only ever see ciphertext and never learn the folder structure.

Motivation

Apps that store files on Blossom servers need an index: names, folders, which blob is which, and per-file encryption keys. Keeping that index in plaintext events leaks the whole layout. This NIP puts the index in one encrypted event kind so the tree stays private while still living on ordinary relays.

The drive key (DK)

A drive is unlocked by one 32-byte random key, the DK. The DK is used directly as a NIP-44 v2 conversation key to encrypt every node.

The DK is stored for the owner as a NIP-78 app-data event (kind:30078) with d tag "/drive-key", whose content is a small JSON object {"k":"<hex DK>"}, NIP-44-encrypted to the owner's own pubkey. So the DK never leaves the owner's control, and a signed-in client fetches + unlocks it once per session.

The node event

Each file or folder is one addressable event:

{
  "kind": 30630,
  "tags": [
    ["d", "<node id>"],       // random 8-byte hex; also how children point to a parent
    ["client", "<app name>"]
  ],
  "content": "<NIP-44(DK, node_json)>"
}

The decrypted content is a JSON object:

{
  "type": "file",            // or "folder"
  "name": "photo.jpg",
  "parent": "<parent node id>", // "root" for the top level
  "deleted": false,

  // files only:
  "blobHash": "<sha256 of the stored bytes>",
  "size": 12345,
  "mime": "image/jpeg",
  "servers": ["https://blossom.example"],

  // private files only (the stored blob is segmented AES-256-GCM ciphertext):
  "blobKey": "<base64 32-byte AES key>",
  "encv": 1,                 // encryption-format version; see Large files
  "ox": "<sha256 of the plaintext>" // optional; integrity + dedup
}

Large files (private blob encryption)

A private file's blob is not encrypted as one monolithic AEAD. It's encrypted as a sequence of fixed-size segments, each authenticated on its own, so a client encrypts and decrypts one segment at a time with bounded memory (no full-file buffering, no OOM) regardless of file size, and can seek: any segment is decryptable on its own from a Range request over the single blob. The result is still one blob with one sha256, whose content-addressing gives per-file integrity and hash-healing. (Encrypted bytes never dedup, since a fresh key and nonces are used every time, so dedup is not a goal of the blob layout; that's what the plaintext hash ox is for.)

The construction is a STREAM-style segmented AEAD (the same shape age uses). This is format version 1, marked by encv: 1 on the node (absent means 1); the params below are fixed for v1, and a future encv MAY change them (e.g. the segment size) without breaking existing blobs, since each node records its version:

  • Segment size: 65536 bytes (64 KiB) of plaintext per segment. Every segment but the last is exactly this size; the last may be shorter (including empty).
  • Cipher: AES-256-GCM under the file's 32-byte blobKey.
  • Per-segment nonce (12 bytes): an 11-byte big-endian segment counter starting at 0, followed by a 1-byte flag, 0x00 for every segment except the last, 0x01 for the last.
  • Segment output: AES-256-GCM-Seal(key, nonce, plaintext_segment) → ciphertext ‖ 16-byte tag. The stored blob is the concatenation of all segment outputs, and its sha256 is the blobHash value.

Why the counter and last-flag:

  • The counter ties each segment to its position, so a reordered or swapped segment fails its tag.
  • The last-flag marks the final segment, so a truncated tail is detected: the decryptor never reaches a 0x01 segment and errors, instead of silently returning a short file.

Decrypting reads 65536 + 16 bytes per segment (the last is shorter), opens each with the derived nonce, and stops at the 0x01 segment.

A file that fits in one segment is just the N = 1 case (a single 0x01 segment), so small and large files use the exact same format, no special case. No nonce is stored: the segment nonces are derived from the counter, and the per-file blobKey is fresh random 32 bytes, so no (key, nonce) pair is ever reused.

Notes

  • Parents are ids, not paths. Moving a folder is one re-publish (change parent); nothing else moves, so folder rename/move is O(1), not an O(N) rewrite of every file beneath it.
  • Private files: the blob is the ciphertext; its blobKey is here in the node. See Large files for the encryption format and encv.
  • Public files: omit blobKey; blobHash is the sha256 of the plaintext bytes as usual for Blossom.
  • ox (private files, optional): the sha256 of the plaintext. For a private file blobHash is the ciphertext hash, which changes on every encryption, so ox is the stable content identity, used to verify plaintext integrity and to skip re-uploading a file already held. Public files omit ox: their blobHash already is the plaintext hash.
  • Folders may carry optional display fields (e.g. color, emoji).
  • File bytes are stored and retrieved as content-addressed blobs per BUD-01 (GET/HEAD) and BUD-02 (upload/list/delete); the servers field follows BUD-03. The Blossom server stays oblivious: it only ever sees an opaque blob.
  • Extra fields: clients MAY include additional application-specific fields, and MUST preserve unknown fields when re-publishing a node, so different clients interoperate without dropping each other's data. The names v and history are reserved (see Versioning).

Deletes

Because relays don't always honor NIP-09, a delete is a tombstone: re-publish the node with "deleted": true and a strictly newer created_at. Clients treat a tombstoned node as gone. A NIP-09 kind:5 MAY also be sent as a best-effort cleanup.

Client behavior

  • On load, fetch the owner's kind:30630 events, decrypt each with the DK, and assemble the tree by parent.
  • Newest created_at wins per d (addressable-event replacement).
  • A node that fails to decrypt is another owner's / another drive's, ignore it.

Versioning (reserved)

This version of the spec stores a single current version per file. The field names v (a per-file version counter) and history (an array of prior full-copy versions, newest-first) are reserved for a future optional versioning extension. Clients that don't implement versioning MUST still preserve these fields if present (see Extra fields), so a versioning client and a non-versioning one interoperate on the current version without data loss.

Discussion

9 comments · 3 correspondents · since 2026-07-22

Connect a key to comment.

ABH3PO2026-07-22

Don't agree with a folders being ids, that goes against the flat file structure and creates completely avoidable events which increase relay overheads. Rest seems fine other than the fact that in don't see an option for chunking? And withoit it, encrypting large files WILL cause OOMs.

Geek2026-07-22

yeah i left the chunking out of the spec and part of the client implementation

Infinity x22026-07-22

Hey, regarding concatenating the chunks, i do not see the advantage of it. The deduplication at the client can still be done using the unencrypted file hash in the metadata event. The deduplication at the blossom will anyways be not possible as the chunks will be encrypted by a different nonce everytime. Also fixing 64Kib in the spec will make updates to the chunk size really hard in the future. Storing chunks in a list will also enable the use case of storing each chunk in a separate server(if a client wants).

Geek2026-07-24

wouldn't let me reply to your response so replying here lol...

with that said, this is the clarification i wanted. the size-cap case is interesting. if a server caps uploads at 2gb and the file is 4gb there's no one-blob answer. so i agree chunked storage belongs in the spec for files bigger than any single server will take, and since we already version the format that's exactly what a later encv is for, an optional ordered chunk list where leaving it out is just today's single blob, rather than something v1 forces on every client now.

the SNDL angle sells me less, mostly because it pulls against the durability one. the AEAD already handles harvest-now-decrypt-later, and spreading chunks so no server holds the whole file is the opposite of replicating each chunk for durability. replicate and every server ends up with everything (spread benefit gone), spread and one server going down takes part of the file with it. you can't get both from the same mechanism, and if the real worry is a future crypto break the honest fix is a post-quantum cipher, not physical splitting.

resumable upload i'd rather solve at the transport layer where it already is. BUD-14's PATCH / gives resumable multipart upload that still yields one content-addressed blob, spec untouched, so a client gets resumability without the format carrying a chunk list or pushing reassembly into every reader to route around a server gap that has its own standard.

on the size math, it's tighter than it looks once chunks carry placement. 450-800 hashes fits with one or two servers each, but the distribution cases want multiple, and server urls run 30-50 bytes apiece, so at ~800 chunks x (hash + 3 urls) you're already past nip-44's ~64kb cap. big or widely-distributed files end up needing a separate manifest blob anyway, which is the indirection chunking was meant to avoid. (50mb chunks running well on a pixel 8 is a good datapoint though, and it argues for keeping the count low.)

the above-cap point as legitimate but it's niche in practice, and for self-hosted setups the operator just raises their own cap, so i don't want to commit the format to a chunk list ahead of real demand. the versioning already leaves that door open, if people actually hit the wall on large files we can add chunking in a later encv then, when we can design it against a concrete need instead of guessing at the manifest, gc, and availability tradeoffs now.

Infinity x22026-07-22

also another advantage of having separate blobs per chunk is the download/upload resiliency. if there is a single large blob and it fails, then the whole blob will need to be retried. with multiple individual chunks, download/uploads can be much mpre resilient

Geek2026-07-24

thanks, agreed on dedup, deduping the ciphertext is pointless (fresh key + nonce each time), so i dropped that as a reason and added an ox field (the plaintext hash), which is the real dedup/identity key like you said.

on the 64kib, it's not actually locked in, the format is versioned (this is v1), so a later version can pick a different segment size and old blobs stay readable since each one records its version. so no worries there.

on separate chunk blobs, i'd rather understand the actual use case than guess, can you say more about what you're picturing? for storing chunks on separate servers especially, is the goal durability (so no single server holds the whole file), load spreading, something else? there are pretty different answers depending on the goal, and i don't want to talk past what you actually mean.

on the resilience point specifically, that one's fair, though resumable download is already free with a Range request on the single blob, and resumable upload is more of a transport-layer gap (blossom PUT isn't resumable) that i'd rather fix there than by chunking the format. one constraint either way: a flat chunk list in the event would blow past nip-44's ~64kb content cap for big files, so it'd need a separate manifest blob.

so for now i'm keeping the single concatenated blob + segmented AEAD (bounded memory so no OOM, seekable via Range), but genuinely open to revisiting if the use case points somewhere i'm missing.

Infinity x22026-07-24

great! on separate chunk blobs, there are a whole lot of use cases on storing different chunks on different servers. people might want to distribute the file due to size limitations. eg server allows max uploads of 2 gb, but a file is 4 gb so it will become possible to split the file and store it. another use case may be the mitigation of SNDL attacks. There might be many more use cases, but i think having a list of chunks in the protocol itself will enable those use cases without any significant downsides or complexities

On the resiliency point, I sort of agree with you that the fix should be on the transport layer, however it is an added advantage of chunk list structure. so if a blossom server in the future doesnt support resumeable uploads even then client will be able to support it

on the point of 64KiB limit, by my estimate an event should easily be able to contain 450-800 chunk hashes easily(assuming multiple different servers per chunk). We also tested chunk sizes and settled on 50Mb chunks. we tested on pixel 8 device and it worked quite well. so yes there is a limit, but practically we should be safe there. what do you think?

ABH3PO2026-07-26

Okay, going back on my folder ids comment, I thought the only way to do ids was to have each folder be a nostr event (which it probably is in your case) , but i found a way to make it so that we can have ids, that are events only when needed. Will update this in the form* NIP soon, but it's awesome how we can learn from each other!

Geek2026-07-26

Yes, every node, file or folder, is its own event (kind 30630), with a random id in the d tag and everything else encrypted in content. Children reference the parent's id, so a rename or move is a single event republish, and empty folders exist for free. The tradeoff is one event per folder whether or not it carries any state.

Looking to seeing your update, but remember that iif a folder is only an event when needed, something still has to mint its id and keep it stable before the event exists, otherwise two clients could materialize the same folder with different ids and you end up with duplicates. Deterministic ids might solve it but unsure. Keep me posted!