# Rebuild the SoLoVault vault client and replace its LGPL libraries

This procedure lets anyone who received the SoLoVault web client rebuild the
vault client script from source and swap in a modified `openpgp` or
`@openpgp/hkp-client`. Everything it needs is published beside it in
`third-party/source/` on the same site:

| File | What it is |
| --- | --- |
| `psono-client-source.tar.gz` | Psono web client source, commit `cdddb8cfb079ddc0f9202574df135c76f3aabedc` (Apache-2.0) |
| `solovault-web.patch` | SoLoVision's changes to that source: the page layout (header, side menu, vault home, Settings page). It does not touch crypto or the libraries below |
| `package-lock.json` | The exact dependency tree the delivered build used |
| `application-packages.tar.gz` | Every installed package that is bundled into the delivered scripts (186 package paths), as installed |
| `lgpl/openpgp-5.11.3.tar.gz` | OpenPGP.js 5.11.3 source, including its build configuration |
| `lgpl/openpgp__hkp-client-0.0.2.tar.gz` | @openpgp/hkp-client 0.0.2 source |
| `BUILD-RECORD.json`, `BUILD-SHA256SUMS` | SHA-256 of every delivered script and the build environment |
| `SHA256SUMS` | SHA-256 of each file in this directory |

## What is delivered

The Psono build, with `solovault-web.patch` applied, writes the vault client
into `build/webclient/`. The SoLoVault site serves that output unchanged, with four additions that do not contain or
link the libraries: `account-entry.js` (a separate sign-in program that loads
`/js/bundle.min.js` as its own script), `account.css`, a site `config.json`, and
rewritten `index.html`/`register.html` that start `account-entry.js` instead of
the bundle. It also replaces `fonts/fontawesome-webfont.svg` with the original
Font Awesome 4.7.0 file.

`openpgp` and `@openpgp/hkp-client` are imported statically, so Webpack places
them inside `js/bundle.min.js`. The files you replace after a rebuild are the
files listed in `BUILD-SHA256SUMS`: everything under `js/` (the bundle, its
chunks, their `.map` and `.LICENSE.txt` files and `js/crypto-worker.js`).

## 1. Verify the inputs

```sh
sha256sum -c SHA256SUMS
```

## 2. Rebuild the client

Use Node.js 20.19.5 and npm 10.8.2 on Linux x64. Leave `CI_COMMIT_TAG` and
`CI_COMMIT_SHA` unset; the delivered build used the defaults (`VERSION.txt`
reads `1.1.0 (build abcd1234)`).

```sh
tar -xzf psono-client-source.tar.gz
cd psono-client-cdddb8cfb079ddc0f9202574df135c76f3aabedc
patch -p1 < ../solovault-web.patch
cp ../package-lock.json package-lock.json   # identical to the archived lockfile
npm ci --ignore-scripts --no-audit --no-fund
npm run buildwebclient
cd build/webclient && sha256sum -c ../../../BUILD-SHA256SUMS
```

Every listed file matches byte for byte. `service-worker.js` is left out of
`BUILD-SHA256SUMS` because Workbox stamps it with the build time. The build output does not depend on the
directory you build in.

If the registry is unreachable for any dependency, the bundled packages are in
`application-packages.tar.gz` at their installed paths. `xlsx` 0.20.3 is
fetched from `cdn.sheetjs.com`, not the npm registry; if that host is
unavailable, pack the archived copy and point the dependency at it:

```sh
mkdir -p ../vendor && tar -xzf ../application-packages.tar.gz -C ../vendor node_modules/xlsx
(cd ../vendor && npm pack ./node_modules/xlsx)
node -e '
const fs = require("fs"), t = "file:../vendor/xlsx-0.20.3.tgz";
const p = JSON.parse(fs.readFileSync("package.json")); p.dependencies.xlsx = t;
fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n");
const l = JSON.parse(fs.readFileSync("package-lock.json"));
l.packages[""].dependencies.xlsx = t;
l.packages["node_modules/xlsx"].resolved = t; delete l.packages["node_modules/xlsx"].integrity;
fs.writeFileSync("package-lock.json", JSON.stringify(l, null, 2) + "\n");'
# then run npm ci and the build as above
```

This substitution produces the same delivered files because the package
contents are identical.

## 3. Replace a library with a modified version

**@openpgp/hkp-client** is consumed from source (`src/hkp.js`). Unpack
`lgpl/openpgp__hkp-client-0.0.2.tar.gz`, change it, and copy the result over
`node_modules/@openpgp/hkp-client` (keep `package.json`).

**openpgp** is consumed from its prebuilt `dist/openpgp.min.mjs`. Unpack
`lgpl/openpgp-5.11.3.tar.gz`, change the source, then build it:

```sh
npm ci && npm run build    # rollup writes dist/
```

Copy the new `dist/`, `lightweight/`, `openpgp.d.ts` and `package.json` over
`node_modules/openpgp`. Keep the public API compatible with 5.11.3.

Then rebuild the client:

```sh
npm run typecheck && npm run buildwebclient
```

## 4. Use the modified client

Copy every file under `build/webclient/js/` over `js/` in a copy of the
delivered site (the site's other files stay as delivered). The SoLoVault account
entry loads whatever `/js/bundle.min.js` the site serves, so no SoLoVault source
is needed. Before relying on a modified build, run the Psono client's own tests
(`npm test`).

This is an engineering procedure, not legal advice.
