Skip to content

About

Open encrypted Filecoin shares in your browser

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Filecoin private sharing

filecoin-encryption-viewer

Open encrypted Filecoin shares in your browser. Decryption never leaves the page.

Try it · Opening a share · Usage · Test locally · Verifiable build · Credits

A single-file browser viewer for encrypted Filecoin uploads (filecoin-pin add --encrypt), opened from the Share links filecoin-pin mints with keysmith. The build output is one self-contained dist/index.html, published once to IPFS and opened through inbrowser.link. Decryption happens entirely in the recipient's browser. There's no server and no analytics, the Access key never leaves the page, and nothing is kept after you close it (large saves use temporary files that are deleted, see Saving).

Try it

A demo folder on the calibration network, shared with filecoin-pin get-share-link, in both kinds of link:

  • Open link: carries its Access key, so it opens without a prompt.
  • Restricted link: asks for its Access key, fak1_txekkuXRme36QrbqRN_uvG91DBa8OhpCJShw8MsJcEg.

Warning

This Access key is public only because it's a demo. For a real share, send the Access key on a separate channel from the link, never next to it.

The first visit takes a few seconds while inbrowser.link sets up its service worker.

Screenshots

Access key prompt
The Access key prompt
Shared folder
A shared folder, with "Download all"

Opening a share

  1. Open the Share link you were sent.
  2. If it asks for an Access key, paste the fak1_… key the sender gave you separately. An open link carries its key and skips this step.
  3. Browse the files, preview them, and download one or all of them.

The link opens that one upload only. To open a share from a terminal or a script instead, use filecoin-pin get --share '<link>'.

Usage

https://<viewer-cid>.ipfs.inbrowser.link/#v1/<encrypted-root-cid>&d=<payload>[&k=fak1_<access key>]

This is exactly what filecoin-pin get-share-link writes. Everything is in the fragment, so nothing reaches a server, and every value is base64url without padding.

  • d is the keysmith payload: the upload's key wrapped to a throwaway secp256k1 key T that the sender made for this link. It's one of two kinds, told apart by the CBOR type of its first byte:
    • a plain piece grant (encodeGrant, a CBOR map): the wrapped key alone. This is what filecoin-pin writes, from the owner wallet and from a session key with a Grant;
    • a Delivery (encodeDelivery, a CBOR array): an owner-signed claim chain naming T's address as its bearer, with an expiry, plus the wrapped key. filecoin-pin doesn't write these yet; the viewer accepts them for when storage providers gate retrieval.
  • k is the Access key: fak1_ plus the 32 bytes of T's private key (43 characters). An open link carries it; a restricted link doesn't, and the sender sends the Access key separately.

The viewer accepts d then k in that order, d up to 8192 characters, and nothing else. A link with any other parameter, a repeated one, a missing or empty d, or bad base64url gets the incomplete-link message.

Opening a link

With k, the viewer clears it from the address bar (keeping d) before it fetches anything, so a reload or a copy of the address no longer carries the key, then opens the share with no prompt. The history entry records only that a key was removed, so a reload asks for the Access key with a notice saying why. If the key doesn't work it falls back to the prompt with a notice. Another link opened in the same tab (pasted, or by Back and Forward) closes the open share first, zeroing its keys, and its unfinished work never reaches the page. Without k, it asks for the Access key and checks the pasted text first: whitespace is dropped, and a group key Grant (fgr1_…), a Share link, text without fak1_ or a key of the wrong length is refused with its own message before anything else happens.

  1. Open the payload, before any request. A Delivery goes through keysmith's openDelivery (chain signatures, expiry, T as the bearer, the key commitment, the grant naming the claim). A plain grant is unwrapped with unwrapWith. The grant must name one piece (piece:<salt>); a grant for a whole group key or a group is refused. A wrong Access key fails here, with nothing fetched.
  2. Read the envelope header with Range requests: a chunked FEE envelope of a CAR.
  3. Derive the piece key with keyForEnvelope, which checks the envelope's keysmith labels (owner, group key, salt) against the grant. The node key and T's bytes are zeroed once used; the piece key is zeroed when the share is closed, or on any failure.
  4. Read files with decryptRange.
Case Message
Wrong Access key (doesn't unwrap, not the Delivery's bearer, or not a valid private key) That Access key doesn't open this share
The payload is for another upload than the envelope at this CID This link is for another upload
The Delivery has expired This share has expired
The payload isn't a valid grant or Delivery, or a signature fails This link is damaged
A chunk fails authentication, or the envelope's length doesn't match its header (the ciphertext was modified or is damaged) This share is damaged or was modified
The envelope has no keysmith labels, or isn't what add --encrypt writes This link doesn't point to a filecoin-pin encrypted share

No message names anything from inside the envelope.

The viewer fetches https://<encrypted-root-cid>.ipfs.inbrowser.link/ with HTTP Range requests. inbrowser.link's service worker intercepts that request (the host is never reached directly) and serves it from the storage providers through IPNI, so the viewer only works when opened at an inbrowser.link origin. A share opened before IPNI has caught up shows "not available yet".

Encryption format

The format is defined by filecoin-pin add --encrypt:

outer CAR (public, IPNI)  ── UnixFS file, root = Encrypted root CID
  └─ FEE envelope (chunked scheme, filecoin-encryption-envelope)
       └─ inner CAR (unixfs-v1-2025, metadata-first), root = a wrapping directory
            with exactly one entry: the shared file, or the shared folder, under its own name
  • The envelope's content_type is application/vnd.ipld.car. The inner CAR lists every directory and file node before any file data, so the viewer knows the whole tree, and every file's byte ranges, from the first few hundred KB.
  • The envelope's authenticated appMetadata holds keysmith's piece labels (pieceMetadata, keysmith format 2): foc/v (2), foc/own, foc/gkid, optionally foc/group, and foc/salt. The piece key is derived from the group key (through the group, if any) and the salt, so every upload has its own key, and a Share link opens only its own upload, whatever group it is in. Links from filecoin-pin 2.3 and 2.4 (keysmith 0.1.0, format 1: foc/v 1, foc/ks) still open: the payload names its format before anything is fetched, and that format's keysmith reads it. A link of one format never opens an upload of the other.
  • File and folder names exist only inside the ciphertext. The on-chain piece name is encrypted.fee.

Key handling is @filoz/keysmith (with viem), plus keysmith 0.1.0 under the keysmith-v1 alias for format 1 links.

Content rendering

The viewer reads the share with HTTP Range requests. It fetches only the metadata to show the tree (usually one request), and only a file's own ranges when you open it, in batches of up to 8 MiB. There is no cap on the share's size.

  • Single file: opens straight into its file.
  • Folder: shown as a tree under the folder's real name.
  • "← All files": every file view of a folder share has this button. It returns to the tree from the already-open archive, with no new fetch and no new decryption, and remembers which folders were open.
  • "Download all": streams a ZIP of the whole folder from the open archive (no re-decryption) and saves it as <folder>.zip, the same way as a single file.
  • File views: each starts with the file name, a type label and the size, then the preview, then a Download button.
Entry Rendering
HTML up to 8 MiB Static markup in an opaque-origin iframe; scripts, handlers, refresh, forms, embedded contexts, anchors, SVG animation and navigation/resource URLs are removed
Text up to 8 MiB, including SVG and XML Shown as plain text, in a scrolling box
Raster image (JPEG, PNG, GIF, WebP, AVIF, BMP), audio or video up to 64 MiB Inline browser preview with a Download button
PDF up to 64 MiB, starting with %PDF- A panel with "Open PDF in a new tab" and a Download button
Unknown type A download card: file name, "Unknown file type · size" and a Download button
Any larger entry A save screen with the type, the size and a Download button

The type is detected from a bounded sniff of the decrypted bytes, never from the file name. PDFs open in the browser's own PDF viewer in a new tab, with no inline preview, so the page CSP can forbid frames and plugins. Download links are always application/octet-stream blobs, so a decrypted HTML or SVG file opened from a link can't run script on the viewer's origin.

Saving

Browser How a file is saved
Chrome, Edge, Brave (desktop) The save dialog (showSaveFilePicker), streamed straight to disk
Firefox 111+, Safari 26+ Decrypted into a temporary file in the browser's private storage (OPFS), with "Decrypting… N%" progress, then downloaded from disk. Memory stays low at any size
Private windows, older browsers Built in memory, capped at 512 MiB on desktop and 256 MiB on mobile. Above that: "too large to save in this browser, use filecoin-pin decrypt"

Temporary OPFS files are deleted at the next save, when the page starts, and when it's closed. If the server ignores Range and answers the first request with the whole file, the viewer reads it into memory when its Content-Length is present and at most 256 MiB (128 MiB on mobile, half the in-memory save cap), and opens the share from it. A body that doesn't start with the envelope tag is refused on its first chunk as "not a share", and one whose length doesn't match its Content-Length is "not available" (try again): it has been read by then, so it can't be offered for download. With no usable Content-Length, over the cap, or when a later read gets the whole file, the viewer offers that encrypted file as a download (encrypted.fee), to decrypt with filecoin-pin decrypt. A share is never HTML, so a 200 with an HTML body is discarded and never offered for download. If no service worker controls the tab, it's inbrowser.link's installer page and the viewer asks the user to open the link again; otherwise it says a web page came back instead of the share (a captive portal or a proxy, for example).

Limits

A share must be exactly what filecoin-pin add --encrypt writes. The viewer rejects anything else as "not a filecoin-pin encrypted share", and it bounds the work a crafted share can cause. A real share over the entry or path limit gets "too many files, or folders nested too deeply, to open in the browser. Use filecoin-pin get <CID>."

Limit Value
Entries (files and folders) 10,000
Name / path length 1024 / 4096 bytes
Metadata read before the tree shows 16 MiB
Layout work 1,000,000 visits
A whole-file 200 kept in memory 256 MiB (128 MiB on mobile)

Development

Requires Node 24 and pnpm 10.7.0 (packageManager).

pnpm install --frozen-lockfile
pnpm dev
pnpm test
pnpm typecheck
pnpm build

Test locally

pnpm dev alone has nothing to open. Make a local share first, then start the dev server:

pnpm dev:share ./some-folder   # or a single file
pnpm dev

AGENTS.md describes what it prints, how the dev server works, and how to trigger each error state.

Verifiable build

Recipients trust this page with their Access key, so anyone should be able to check that a Viewer CID was built from this source. The build is reproducible: lockfile, Node 24, pnpm 10.7.0, and no timestamps in the output. CI checks each release's CID against the table below, so a toolchain that changes the build fails the release.

git checkout <tag>
pnpm install --frozen-lockfile
pnpm build
node scripts/release.ts cid   # the CID of dist/ as a folder holding index.html

Releases are published as a folder holding index.html, with filoz-webmaster, so their CIDs start with bafybei.

The stable URL https://viewer.filecoin.cloud/ redirects to https://viewer-filecoin-cloud.ipns.inbrowser.link/, which serves the build named by the DNSLink record _dnslink.viewer.filecoin.cloud. Releases are made by CI:

  1. Each push to main updates a release PR (version bump and changelog), and CI commits that build's CID to the table below, keyed by the upcoming tag. Release PRs are opened with GITHUB_TOKEN, so GitHub runs no CI checks on them.
  2. Merging the release PR tags the release. CI runs the checks on the released commit, builds it, and fails if its CID differs from the table. A release deploys only when it changes the viewer, that is, when its CID differs from the previous row; a rollback stays until then.
  3. CI uploads that build to mainnet with the release wallet 0x97ce47f23068C1F1B26e0BF73433FCF2Fc71bca0. A maintainer then approves the DNSLink switch: CI waits until cid.contact indexes the CID and points the DNSLink record at it. The release notes record the new and the previous CID.
Release Viewer CID Network
0a0b8b5 bafkreif2klvyz4fol7wvbsbv5e5uwj2dkjt5znaiudzll2ribl6u4hgi64 mainnet
v0.2.0 bafybeigcgrecgdj43oxpqyosssb3vrm2jxyse6zql6h52qrjvrkcox6or4 mainnet

The 0a0b8b5 row predates releases, so it names a commit. To point the stable URL back at a recorded build, run the Rollback workflow with its CID.

Credits

  • Based on Jenni's packages/foc-viewer in jennijuju/foc-encryption-demo (commit 7d5119b), which gave the rendering, sandbox, save and folder UI.
  • Fonts: Funnel Sans (body) and Aspekta (headings), under the SIL Open Font License 1.1. See assets/fonts/OFL.txt.

License

MIT

About

Open encrypted Filecoin shares in your browser

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages