diff --git a/apps/mobile/src/licenses.test.ts b/apps/mobile/src/licenses.test.ts index 9c15fa1..0db7c3b 100644 --- a/apps/mobile/src/licenses.test.ts +++ b/apps/mobile/src/licenses.test.ts @@ -4,10 +4,42 @@ import assert from "node:assert/strict"; import { readdirSync, readFileSync } from "node:fs"; import { LICENSES, covers } from "./licenses.ts"; -const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { dependencies: Record }; -const shipped = Object.keys(pkg.dependencies).filter((name) => !name.startsWith("@hermit/")); +const readDeps = (url: URL): string[] => { + const parsed = JSON.parse(readFileSync(url, "utf8")) as { dependencies?: Record }; + return Object.keys(parsed.dependencies ?? {}); +}; -test("every dependency the app ships is credited on HM-SET-08 (US-SET-10)", () => { +function shippedDependencies(): string[] { + const thirdParty = new Set(); + const seenWorkspace = new Set(); + const queue = readDeps(new URL("../package.json", import.meta.url)); + + while (queue.length > 0) { + const dep = queue.shift()!; + if (!dep.startsWith("@hermit/")) { + thirdParty.add(dep); + continue; + } + if (seenWorkspace.has(dep)) continue; + seenWorkspace.add(dep); + const pkgName = dep.slice("@hermit/".length); + for (const child of readDeps(new URL(`../../../packages/${pkgName}/package.json`, import.meta.url))) { + queue.push(child); + } + } + + for (const dep of readDeps(new URL("../worklets/wallet/package.json", import.meta.url))) { + if (!dep.startsWith("@hermit/")) thirdParty.add(dep); + } + return [...thirdParty].sort(); +} + +const shipped = shippedDependencies(); + +test("every dependency the app, its @hermit/* packages, and the wallet worklet ship is credited on HM-SET-08 (US-SET-10)", () => { + for (const expected of ["@noble/curves", "@noble/hashes", "@tetherto/wdk-wallet-evm", "bare-crypto", "bare-node-runtime", "bip39"]) { + assert.ok(shipped.includes(expected), `expected ${expected} in shipped dependencies`); + } const missing = shipped.filter((name) => !LICENSES.some((entry) => covers(entry, name))); assert.deepEqual(missing, [], `add these to LICENSES in licenses.ts: ${missing.join(", ")}`); }); diff --git a/apps/mobile/src/licenses.ts b/apps/mobile/src/licenses.ts index dc83fff..f56ac24 100644 --- a/apps/mobile/src/licenses.ts +++ b/apps/mobile/src/licenses.ts @@ -38,13 +38,13 @@ export const LICENSES: readonly LicenseEntry[] = [ { name: "op-sqlite", license: "MIT", url: "https://github.com/OP-Engineering/op-sqlite", packages: ["@op-engineering/op-sqlite"] }, { name: "SQLCipher", license: "BSD-3-Clause", url: "https://github.com/sqlcipher/sqlcipher" }, // Through Hermit's own packages (cage, core, model, payments, connectors), not the app's package.json. - { name: "noble-curves", license: "MIT", url: "https://github.com/paulmillr/noble-curves" }, - { name: "noble-hashes", license: "MIT", url: "https://github.com/paulmillr/noble-hashes" }, + { name: "noble-curves", license: "MIT", url: "https://github.com/paulmillr/noble-curves", packages: ["@noble/curves"] }, + { name: "noble-hashes", license: "MIT", url: "https://github.com/paulmillr/noble-hashes", packages: ["@noble/hashes"] }, // The testnet wallet's worklet (worklets/wallet/package.json), bundled apart from the app's dependencies. - { name: "WDK wallet for EVM", license: "Apache-2.0", url: "https://github.com/tetherto/wdk-wallet-evm" }, - { name: "bare-crypto", license: "Apache-2.0", url: "https://github.com/holepunchto/bare-crypto" }, - { name: "bare-node-runtime", license: "Apache-2.0", url: "https://github.com/holepunchto/bare-node-runtime" }, - { name: "bip39", license: "ISC", url: "https://github.com/bitcoinjs/bip39" }, + { name: "WDK wallet for EVM", license: "Apache-2.0", url: "https://github.com/tetherto/wdk-wallet-evm", packages: ["@tetherto/wdk-wallet-evm"] }, + { name: "bare-crypto", license: "Apache-2.0", url: "https://github.com/holepunchto/bare-crypto", packages: ["bare-crypto"] }, + { name: "bare-node-runtime", license: "Apache-2.0", url: "https://github.com/holepunchto/bare-node-runtime", packages: ["bare-node-runtime"] }, + { name: "bip39", license: "ISC", url: "https://github.com/bitcoinjs/bip39", packages: ["bip39"] }, ]; export function covers(entry: LicenseEntry, dependency: string): boolean {