fix(witness): probe workspace packages for @noble/ed25519 (pnpm isolated linker)

CI-only failure: signature verification returned all-false because
verify.mjs couldn't load @noble/ed25519. Locally it worked because
v3/node_modules/@noble/ed25519 happened to exist as a flat copy from
an earlier non-pnpm install. Fresh CI runners get pnpm's default
isolated linker, which only exposes a transitive dep at workspace
root if a workspace member declares it directly — and no v3 root
member declares ed25519 (only @claude-flow/cli and
@claude-flow/plugin-agent-federation do).

Fix: expand the probe paths in both verify.mjs and lib.mjs to also
look inside the workspace packages that DO declare @noble/ed25519.
Now resolution succeeds on:
  - flat npm install (probes repoRoot/node_modules)
  - pnpm hoist install (probes v3/node_modules)
  - pnpm isolated install (probes v3/@claude-flow/cli/node_modules)

Verified locally by removing v3/node_modules/@noble/ed25519 (the
stale flat copy) and re-running verify.mjs — signature valid,
82/82 fixes pass.

Also: verify.mjs now prints the probed paths + last error when
ed25519 can't be located, instead of silently returning all-false
signature flags. The diagnostic visibility (via the v3-ci.yml
update in 19867b339) surfaced this in CI as "manifestHashOk: false"
across all three signature checks — the tell that ed25519 wasn't
loaded at all rather than the manifest being tampered with.

Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
ReuvenandRuFlo committed 2026-05-08 22:47:31 -04:00
1 parent 19867b339f
commit b289c009e9
2 files changed
+32 -5

No files matched your search

+14 -2
View File
@@ -21,8 +21,19 @@ import { createRequire } from 'node:module';
// install roots so the toolkit works in ruflo's monorepo layout *and*
// a user's flat node_modules.
function loadEd25519(probeRoots) {
// Expand caller-supplied roots with workspace-package locations so
// pnpm's isolated layout (where transitive deps don't hoist to the
// workspace root) still resolves @noble/ed25519. Callers don't need
// to know about this — the function just probes more places.
const expanded = [
...probeRoots,
...probeRoots.flatMap(r => [
join(r, 'v3/@claude-flow/cli'),
join(r, 'v3/@claude-flow/plugin-agent-federation'),
]),
];
let lastErr;
for (const root of probeRoots) {
for (const root of expanded) {
try {
const req = createRequire(join(root, 'noop.js'));
const ed = req('@noble/ed25519');
@@ -37,7 +48,8 @@ function loadEd25519(probeRoots) {
throw new Error(
"Could not locate '@noble/ed25519'. Install it in your project " +
"(npm i @noble/ed25519) or pass a node_modules root via the " +
"WITNESS_ED25519_ROOT env var. Last error: " + (lastErr?.message ?? '?')
"WITNESS_ED25519_ROOT env var. Probed: " + expanded.join(', ') +
". Last error: " + (lastErr?.message ?? '?')
);
}
+18 -3
View File
@@ -83,11 +83,26 @@ process.exit(ok ? 0 : 1);
// ─── ed25519 helpers ─────────────────────────────────────────────
async function verifySignature(witness, repoRoot) {
// Probe multiple plausible install roots — pnpm's isolated linker
// doesn't hoist transitive deps to v3/node_modules, so we also check
// workspace packages that declare @noble/ed25519 directly. A user's
// flat npm install satisfies the first probe; pnpm satisfies the latter.
let ed;
for (const root of [repoRoot, join(repoRoot, 'v3')]) {
try { ed = createRequire(join(root, 'noop.js'))('@noble/ed25519'); break; } catch { /* try next */ }
let probeErr;
const probes = [
repoRoot,
join(repoRoot, 'v3'),
join(repoRoot, 'v3/@claude-flow/cli'),
join(repoRoot, 'v3/@claude-flow/plugin-agent-federation'),
];
for (const root of probes) {
try { ed = createRequire(join(root, 'noop.js'))('@noble/ed25519'); break; }
catch (e) { probeErr = e; }
}
if (!ed) {
console.error(`verify.mjs: could not load @noble/ed25519 from any of:\n ${probes.join('\n ')}\n last error: ${probeErr?.message ?? '?'}`);
return { manifestHashOk: false, publicKeyReproducible: false, signatureValid: false };
}
if (!ed) return { manifestHashOk: false, publicKeyReproducible: false, signatureValid: false };
ed.etc.sha512Sync = (...m) => { const h = createHash('sha512'); for (const x of m) h.update(x); return h.digest(); };