There was no packaging target anywhere, no artifact, and no `key` in `manifest/chrome.json` — so an unpacked Chrome load derived its extension id, and therefore its `chrome.storage.local` partition, from the absolute checkout path. Moving or re-cloning the checkout presented an empty wallet, with no error and nothing in the UI to say so. `manifest/chrome.json` now carries a fixed `key`: the public half of an RSA keypair, which pins the extension id to `gipbhkogfopeahplcjhipkgpcimdpkip`. The private half is a credential and is not in this repo; no target generates one into the working tree, and `tests/extensionId.test.js` fails if a `.pem` is ever committed. Changing `key` changes the id and orphans every wallet stored under the old one. `make package` (script/package) runs `make build` — the only audited path to a release build — and writes one self-contained, versioned archive per browser into `release/`, plus `SHA256SUMS`. The archives are deterministic: entries sorted, timestamps fixed, compression level fixed, so two builds of one commit are byte-identical. Self-containment is checked rather than assumed: every path the manifests and the popup HTML reference is resolved and required to be inside the archive, a reference that climbs out of the extension root is a hard failure, and files left at the `dist/` root — `dist/styles.css`, which build.js copies into each browser directory — are reported as deliberately not shipped rather than dropped by a glob. The archive is then read back off disk and compared member by member against the directory it was built from. The zip writer and reader are stdlib zlib in `script/lib/zip.js`; no new dependency, and nothing unpinned. One version, enforced rather than generated. `script/lib/version.js` requires `package.json`, `manifest/chrome.json` and `manifest/firefox.json` to agree and fails the build naming each file and what it said, instead of reading from one of the three. `BUILD_COMMIT` now carries `-dirty` when the working tree does not match `HEAD`, and `-unknown` when git cannot say; the full hash behind the About screen's commit link stays clean so the link still resolves. Two real-browser observations, both run through the pinned harnesses: - `tests/e2e/storagePartition.js` loads the build from two different paths in one Chrome profile. With `key`: same id, and the second load reads the first load's storage. Without `key`: different ids, and the second load sees an empty partition. Loading both keyed copies at once yields one id, not two. - `tests/e2e/firefox/reinstall.js` installs the packaged XPI in a real Firefox, creates a wallet, quits the browser, restarts on the same profile, adds the add-on again, and decrypts the vault back to the original recovery phrase. It then observes that an explicit uninstall DESTROYS that storage — correct browser behaviour, but for a wallet it means Remove is irreversible except from the recovery phrase, so README.md says so. Firefox ships an UNSIGNED XPI. README.md states plainly that release Firefox and ESR will refuse it, that Developer Edition, Nightly or an Unbranded build is required, and that a temporary add-on does not survive a browser restart. AMO signing, CRX packing, tagging and any upload are deliberately out of scope.
75 lines
2.9 KiB
JavaScript
75 lines
2.9 KiB
JavaScript
// The version, and the rule that there is only one of it.
|
|
//
|
|
// Three files declare a version and none of them can be derived from another:
|
|
// Chrome and Firefox each need their own manifest, both are copied to dist/
|
|
// verbatim (tests/manifest.test.js asserts that what is in manifest/ is what
|
|
// ships), and package.json's copy is what build.js compiles into the About
|
|
// screen. So the single source of truth is enforced rather than generated —
|
|
// they must all agree or there is no version and no build.
|
|
//
|
|
// Reading one of the three and ignoring the rest is what this replaces. That
|
|
// shape cannot fail: it silently ships an extension whose About screen and
|
|
// whose browser-reported version disagree, and whose release artifact is named
|
|
// after whichever file the packager happened to read.
|
|
//
|
|
// Required by build.js, script/lib/package.js and tests/version.test.js, so
|
|
// the build, the release artifacts and make check all apply the same rule to
|
|
// the same files.
|
|
|
|
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const VERSION_SOURCES = [
|
|
"package.json",
|
|
"manifest/chrome.json",
|
|
"manifest/firefox.json",
|
|
];
|
|
|
|
// Every declared version, in VERSION_SOURCES order, as { source, version }.
|
|
// A file that declares nothing usable fails here rather than being skipped:
|
|
// a missing version is not agreement.
|
|
function declaredVersions(root) {
|
|
return VERSION_SOURCES.map((source) => {
|
|
const file = path.join(root, source);
|
|
let parsed;
|
|
try {
|
|
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
} catch (e) {
|
|
throw new Error(
|
|
`${source} could not be read as JSON: ${e.message}`,
|
|
);
|
|
}
|
|
const version = parsed.version;
|
|
if (typeof version !== "string" || version.trim() === "") {
|
|
throw new Error(
|
|
`${source} declares no usable "version" (found ` +
|
|
`${JSON.stringify(version)}). Every artifact is named and ` +
|
|
`stamped with it, so there is nothing to build without it.`,
|
|
);
|
|
}
|
|
return { source, version };
|
|
});
|
|
}
|
|
|
|
// The one version all three declare, or a failure naming every disagreeing
|
|
// file and what it said.
|
|
function resolveVersion(root) {
|
|
const declared = declaredVersions(root);
|
|
const distinct = [...new Set(declared.map((d) => d.version))];
|
|
if (distinct.length !== 1) {
|
|
throw new Error(
|
|
"the declared versions disagree, so this tree has no version: " +
|
|
declared.map((d) => `${d.source}=${d.version}`).join(", ") +
|
|
". Set all of them to the same value: the manifests are what " +
|
|
"the browser reports and package.json is what the About " +
|
|
"screen shows, and a build that picked one of them would " +
|
|
"ship the disagreement.",
|
|
);
|
|
}
|
|
return distinct[0];
|
|
}
|
|
|
|
module.exports = { VERSION_SOURCES, declaredVersions, resolveVersion };
|