summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/file-utils.js
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-03 15:20:52 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-03 15:20:52 +0200
commit0b3ffdb8d7f07aee817ece24fd44a24ac60e6714 (patch)
tree4f65c9bb9128abf18f7739a711c77cfc8012fc06 /packages/meshbay-hub/src/meshbay_hub/static/file-utils.js
parentc1be7571973c3d0b671ed4db2da41266ae3099d8 (diff)
downloadmeshbay-0b3ffdb8d7f07aee817ece24fd44a24ac60e6714.tar.gz
refactor(hub): drop the base64 chunk fallback and the dead HTTP file client
With MNP 0.15 no node can emit a base64 `file_chunk`, so the browser's fallback for that shape is unreachable. Three things go with it: - `file-utils.js` kept a third branch below the fallback that base64-decoded `chunkMsg.ct_b64 || chunkMsg.data_b64` when neither was present, i.e. decoded `undefined` and wrote the result into the file the user was saving. A chunk we cannot decrypt now stops the download with an error naming the file and suggesting the node is older than the page. Deliberately not in `_isRetryableTransportError`: this is a version mismatch, not a bad moment on the link. - `crypto.js` `decryptChunk` (base64) was the real path until Phase 9.15 and has had no caller since. - `crypto.js` `decryptFile` was never called in any commit. It fetched `${nodeUrl}/file/${id}/${chunk}?token=` in a loop — the node's unauthenticated HTTP file API, which is finding C1 and was deleted in Phase 11.5. A client for an endpoint that no longer exists, kept alive by being exported. `decryptChunkBin` — every file download and every video segment — is untouched. `packages/meshbay-client/ui/` was resynchronised with `npm run sync-ui`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsoWC3GmhNdwVFomW3QjH3
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/file-utils.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/file-utils.js34
1 files changed, 17 insertions, 17 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/file-utils.js b/packages/meshbay-hub/src/meshbay_hub/static/file-utils.js
index ba76ac9..09ee6c9 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/file-utils.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/file-utils.js
@@ -110,13 +110,6 @@ function _saveBlob(blob, filename) {
URL.revokeObjectURL(url);
}
-function _b64ToU8(b64) {
- const bin = atob(b64);
- const arr = new Uint8Array(bin.length);
- for (let i = 0; i < bin.length; i++) arr[i] = bin.charCodeAt(i);
- return arr;
-}
-
// A dead transport (screen-lock WebRTC failure, see transport.js's
// _reconnectLoop) surfaces here as a rejected fetchChunk — TransportLostError
// when the pending request was killed outright, a plain timeout if it was
@@ -173,16 +166,23 @@ async function pipelinedDownload(transport, gekKey, fileId, totalChunks, onChunk
throw err;
}
const chunkMsg = await inflight[nextRecv];
- let plaintext;
- if (gekKey && chunkMsg.ct) {
- plaintext = await window.MeshBayCrypto.decryptChunkBin(
- gekKey, fileId, nextRecv, chunkMsg.nonce, chunkMsg.ct);
- } else if (gekKey && chunkMsg.ct_b64) {
- plaintext = await window.MeshBayCrypto.decryptChunk(
- gekKey, fileId, nextRecv, chunkMsg.nonce_b64, chunkMsg.ct_b64);
- } else {
- plaintext = _b64ToU8(chunkMsg.ct_b64 || chunkMsg.data_b64);
+ // One shape, and a refusal for anything else. There used to be two fallbacks
+ // below this: a base64 `ct_b64` chunk, which was the real wire format until
+ // the binary switch in Phase 9.15 and which no node has sent since, and a
+ // plaintext branch that base64-decoded `undefined` when neither field was
+ // there. That last one is why this now throws: a chunk we cannot decrypt has
+ // to stop the download, not write whatever it decoded into the file the user
+ // is saving. MNP 0.15 removed the last producer of the base64 shape (it was
+ // still emitted on the QUIC transport), so a node that sends one is a node
+ // older than the SPA serving this page.
+ if (!gekKey || !chunkMsg.ct) {
+ throw new Error(
+ `Chunk ${nextRecv} of ${fileId.slice(0, 8)} cannot be decrypted `
+ + `(${gekKey ? 'unexpected chunk format' : 'no group key'}) — `
+ + 'the node may be running an older version.');
}
+ const plaintext = await window.MeshBayCrypto.decryptChunkBin(
+ gekKey, fileId, nextRecv, chunkMsg.nonce, chunkMsg.ct);
if (writable) {
await writable.write(plaintext);
} else {
@@ -328,6 +328,6 @@ async function downloadDirectory(transfers, transport, gek, entries, dir, { setE
export {
FILE_ICONS,
formatSize, formatDate, PREVIEWABLE_TEXT, canPreview, CHUNK_SIZE,
- _openDownloadTarget, _saveBlob, _b64ToU8, pipelinedDownload, downloadEntry,
+ _openDownloadTarget, _saveBlob, pipelinedDownload, downloadEntry,
downloadDirectory,
};