Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions apps/mobile/src/licenses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> };
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<string, string> };
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<string>();
const seenWorkspace = new Set<string>();
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(", ")}`);
});
Expand Down
12 changes: 6 additions & 6 deletions apps/mobile/src/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading