A single-file browser viewer for encrypted Filecoin uploads (filecoin-pin add --encrypt), opened from keysmith Share links (#v1/<cid>&d=…[&k=fak1_…]). See README.md for the format, behaviour and limits.
pnpm install --frozen-lockfile
pnpm typecheck && pnpm test && pnpm build && pnpm exec biome check .
pnpm dev:share <file-or-folder> # writes dev/share.fee and prints links, then: pnpm devAll four checks must pass before work is done. pnpm build runs scripts/check-dist.mjs, which fails if the built CSP differs from index.html or any dev code leaks into dist/index.html.
src/: one module per concern:fragment.tsparses#v1/<cid>&d=…[&k=…]fragments and thefak1_Access key text.range-source.tsreads the share with Range requests (no-store,206only, never byte 0), or from memory when the head read gets the whole envelope in a200.unixfs-car-layout.tscomputes the tree and every block's offset from the metadata-first CAR, within the limits in README.md "Limits".car-archive.tsopens the link's payload with keysmith, derives the piece key, decrypts the metadata, builds the entry list, and streams a file's ranges in batches.errors.tsholds the error classes the UI maps to messages.decrypt.tsbounds inline entry collection.sandbox.tscreates the locked HTML iframe.save.tspicks the save path (dialog, OPFS, or in-memory), andopfs-save.tsstages files in OPFS.render.tsrenders bounded content and the file views.file-type.tsmaps sniffed MIME types to friendly labels, andformat.tsformats byte sizes.zip.tsstreams the "Download all" ZIP from the open archive (withclient-zip).card-label.tsmanages the label above the card and the card layout per screen.ui.tsowns the Access key prompt (with its local checks) and retry, the folder tree, and the save, too-large, not-available and can't-be-opened states.main.tsconnects the link, Access key, archive, entry and renderer paths, and reopens on every fragment change (hashchange), closing the previous share; a generation number stops its late work.
tests/: vitest in thenodeenvironment. The fixtures intests/fixtures/build real metadata-first shares (make-share.ts), serve them with Range (serve-range.ts), and fake OPFS and Web Locks (fake-opfs.ts).
pnpm dev:share <file-or-folder> prints, for a plain grant and for a Delivery (valid for an hour), the link without its key, the Access key on its own line, and the link with &k=. The share and the keys are made from fixed dev keys (tests/fixtures/make-share.ts). The dev server answers the share's Range requests from dev/share.fee and relaxes the page CSP for Vite; neither exists in pnpm build, which fails if either leaks into dist/index.html. In dev, the console also logs [foc-viewer dev] timings for each unlock, file open and range request.
| State | How to trigger |
|---|---|
| Wrong Access key | Enter any other fak1_ key, or change a character of the printed one |
| Prompt-side checks | Paste a Share link, a fgr1_ Grant, or a key without its prefix |
| Not available | Delete dev/share.fee, then submit |
| Share served whole | Add ?ignore-range before the # (http://localhost:5173/?ignore-range#v1/<cid>&d=…); the dev server then answers 200 with the whole file and its Content-Length, and a share up to 256 MiB opens from that one response |
| Can't be opened in the browser | Add ?ignore-range=chunked instead; the 200 then has no Content-Length (as over the in-memory cap), so the viewer offers the body as encrypted.fee |
| Incomplete link | Use any other fragment, for example #nope |
The real path (the inbrowser.link service worker intercepting https://<cid>.ipfs.inbrowser.link/ and fetching from storage providers; the host is never reached directly) can only be tested on the published Viewer.
README.md "Verifiable build" describes the release flow. For changes to it:
ci.ymlruns the four checks on every PR and push tomain, then filoz-webmaster's dry run, and fails ifscripts/release.ts ciddiffers from the CID webmaster packs.release.yml:release-pleaseandrelease-pr-readmekeep the release PR and its README row; on a release,deploy-check(no secrets) checks and builds it,upload(environmentupload, the wallet key only) publishes it with webmaster,dnslink(environmentrelease, the Cloudflare token only, approval required) waits for cid.contact and switches the DNSLink, andrelease-notesrecords the CIDs.rollback.ymlswitches the DNSLink back, in thereleaseenvironment.- Never put the wallet key and the Cloudflare token in the same job: a job's steps share one runner, and the upload runs third-party code.
- Environments, both limited to the deployment branch
main:upload: the secretFILECOIN_WALLET_KEY, the key of the release wallet0x97ce47f23068C1F1B26e0BF73433FCF2Fc71bca0.release: required reviewers and "Prevent self-review"; the secretCLOUDFLARE_API_TOKEN(Zone → DNS → Edit,filecoin.cloudonly) and the variablesCLOUDFLARE_ZONE_IDandDNSLINK_RECORD_ID.
- The repo setting "Allow GitHub Actions to create and approve pull requests" must be on for release-please.
- The logic lives in
scripts/release.ts(tested intests/release.test.ts), not in the workflow YAML. Pin every action by commit SHA.
- The build is one self-contained HTML file. No external requests except Range requests to
https://*.ipfs.inbrowser.link, which the service worker intercepts. Don't add dependencies lightly, and keep everything inline. - Don't change the CSP in
index.htmlwithout a reason recorded next to it.'self'inconnect-srcis required for Firefox. - Security invariants:
- every Download link is an
application/octet-streamblob; - typed blobs only for previewable raster images, audio, video and PDF;
- HTML only in the sandboxed iframe;
- SVG and XML as text.
- every Download link is an
- Range invariants:
- every request uses
cache: 'no-store'and must get a206. The one exception is the head read: a200carrying the whole envelope, under the in-memory cap (wholeBodyCap()), is kept and read from memory; - never request byte 0: the gateway's service worker answers a range starting at byte 0 by downloading the whole file in the background (js-ipfs-unixfs#501). The first request is
bytes=1-327679, and byte 0 is supplied as0xd0, the COSE_Encrypt0 tag every envelope starts with (seerange-source.ts); - cancel the body of any response you throw away.
- every request uses
- OPFS:
- write exactly sized buffers only (
exactBytes), because WebKit writes a view's whole underlying buffer; - never delete a staged file that's locked.
- write exactly sized buffers only (
- Copied files:
unixfs-car-layout.tsis copied from filecoin-pin and marked with aponytail:note. Keep it in step with filecoin-pin, and note any deliberate difference in the file header. Key handling is@filoz/keysmith; the link codec infragment.tsmust match filecoin-pin'ssrc/common/share-link.ts. - Tests: compare large byte arrays with
expectSameBytes(tests/fixtures/bytes.ts), nottoEqual, which takes seconds per MiB. Give a test its own timeout only when it does real work. - Style: Biome (
biome.json, line width 120). Small, boring code. Mark deliberate shortcuts with aponytail:comment naming the limit and the upgrade path. - Don't commit
dev/,dist/or local test folders. They're gitignored.