mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-11-04 03:52:34 +00:00
The web viewer's static/js/meshcore-browser.mjs was an esbuild bundle of @michaelhart/meshcore-decoder at 0.2.7 or older, added without a record of its version or how it was built. Those versions read the path-length byte as a plain byte count, so every packet with 2- or 3-byte hops was misparsed from the path onward: wrong header and type, a path split into single bytes, garbage payload fields, garbled advert names and group text that never decrypted. The bundle is rebuilt from 0.3.0, which takes the hop count from bits 0-5 and the hash size from bits 6-7. Twelve real packets from the bot's database (adverts, group text, direct messages and returned paths at 1, 2 and 3 bytes per hop) decode to the same hop count, path and payload as the bot's own decoder; multibyte adverts get their real names and a 2-byte-hop Public message decrypts, on the tape and in the byte breakdown. scripts/meshcore-decoder-browser/ holds the browser entry the old bundle was built from (recovered from the bundle: it re-exports the library and routes Ed25519's SHA-512 through crypto-js so signatures verify on a plain-HTTP page) and build.sh, which fetches the published package, installs its runtime dependencies with install scripts disabled and bundles it with a pinned esbuild in a temporary directory. It reproduces the committed bundle byte for byte. The unused meshcore-browser.min.mjs is removed, and the multibyte workarounds from the byte breakdown polish (skipping the browser decode and saying so) are taken out again.
33 lines
1.3 KiB
Bash
Executable File
33 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Rebuild the web viewer's browser bundle of @michaelhart/meshcore-decoder.
|
|
#
|
|
# scripts/meshcore-decoder-browser/build.sh [version]
|
|
#
|
|
# Fetches the published package (source included), adds index.ts from this
|
|
# directory as src/browser/index.ts, installs its runtime dependencies with
|
|
# install scripts disabled, and bundles it with esbuild into
|
|
# modules/web_viewer/static/js/meshcore-browser.mjs. Everything is built in a
|
|
# temporary directory; only the bundle is written into the repo.
|
|
set -euo pipefail
|
|
|
|
VERSION="${1:-0.3.0}"
|
|
ESBUILD_VERSION="0.24.0"
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO="$(cd "$HERE/../.." && pwd)"
|
|
OUT="$REPO/modules/web_viewer/static/js/meshcore-browser.mjs"
|
|
WORK="$(mktemp -d)"
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
|
|
cd "$WORK"
|
|
npm pack "@michaelhart/meshcore-decoder@$VERSION" --silent >/dev/null
|
|
tar xzf ./*.tgz
|
|
cd package
|
|
mkdir -p src/browser
|
|
cp "$HERE/index.ts" src/browser/index.ts
|
|
npm install --omit=dev --ignore-scripts --no-audit --no-fund --silent
|
|
npx --yes "esbuild@$ESBUILD_VERSION" src/browser/index.ts \
|
|
--bundle --format=esm --platform=browser --target=es2020 \
|
|
--outfile="$OUT" --log-level=warning
|
|
|
|
echo "Built @michaelhart/meshcore-decoder@$VERSION -> ${OUT#"$REPO"/} ($(wc -c < "$OUT" | tr -d ' ') bytes)"
|