Files
loki/scripts/test/solon-claims.ts
CatoandClaude Opus 5 2a8aa17d6f feat(solon): found an organization from a project, and attribute it by consent (#759)
Solon can now create organizations (bitbaum/solon#166). This is Loki's half: the
handoff that starts it, and the register join that records the result.

A HANDOFF, NOT A PUBLISH

Publishing to OrangeCat works because Loki holds the user's OIDC token and acts
as them. That does not transfer: founding a Solon organization needs a signature
from the founder's own Bitcoin wallet, and Solon's key custody is "never Solon —
SELF is a human's own wallet". So Loki cannot do this for anyone. It mints a
link, pre-filled with the project, and the owner signs on Solon.

ATTRIBUTION BY GRANT, NOT BY NAME

Founding is permissionless, so a register that paired a project with the
organization of the same name would let whoever founds `loki` appear to govern
Loki. The register now joins on Solon's `claimedProject`, and Solon sets that
only from a grant this signs for the founder's own OrangeCat identity, checked
against their session. Squatting a name costs a vanity slug, never attribution.

The grant is HMAC-SHA256 over a domain-separated line, 30-minute TTL, signed
with SOLON_WEBHOOK_SECRET — which both deployments already hold, and which
cannot collide with a webhook body because that is JSON. Both ports are pinned
to ONE shared vector; drift turns both repos' suites red rather than silently
refusing every founding link with "issued to a different identity".

AND A PROBE THAT COULD ONLY EVER FIND WHAT IT KNEW

solonOrgSlugs() asked `GET /api/orgs/<slug>` per candidate slug — and all three
callers passed no candidates, so it only ever probed `orangecat`. An
organization for any other project could have existed and the register would
never have seen it. It reads Solon's new list endpoint once instead. A fetch
that fails is still UNCHECKED, never "no organisation".

The button renders nothing when Solon is unreachable: the project may already
have an organization we could not see, and offering to found a second one is the
wrong guess. The grant is minted on click, not on page load, so a tab left open
past the TTL does not hand Solon an expired link.

Checked: tsc, eslint, design-system, 191/191 unit test files — including the
shared-vector test and a register test pinning that an organization which merely
shares a project's name attributes nothing.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 02:16:05 -07:00

63 lines
2.1 KiB
TypeScript

// A Solon organisation is attributed to a project only by its claim — never by
// sharing the project's name.
//
// Founding an organisation on Solon is permissionless, so this is the rule that
// keeps "someone founded an organisation called loki" from putting a stranger's
// organisation on Loki's public register. The claim itself is only recorded by
// Solon when the founder carried a grant Loki signed for their own identity
// (scripts/test/solon-grant.ts pins that half). Pure: no DB, no network.
import assert from "node:assert";
import { buildFleetRegister } from "@/lib/register/build";
import { claimsFrom } from "@/lib/register/solon";
const claims = claimsFrom([
{ slug: "orangecat", claimedProject: "orangecat" },
// An organisation may live at a different address from the project it governs
// — e.g. when the obvious name was already taken.
{ slug: "heidi-zh", claimedProject: "heidi" },
// Squatting: an organisation sharing a project's name, claiming nothing.
{ slug: "loki", claimedProject: null },
]);
assert.strictEqual(claims.get("orangecat"), "orangecat");
assert.strictEqual(
claims.get("heidi"),
"heidi-zh",
"an organisation governs the project it claims, whatever its own address",
);
assert.strictEqual(
claims.has("loki"),
false,
"an organisation called loki that claims nothing governs nothing",
);
const rows = buildFleetRegister(
[
{ id: "1", name: "loki", gitUrl: "https://github.com/bitbaum/loki.git" },
{ id: "2", name: "heidi", gitUrl: "https://github.com/bitbaum/heidi.git" },
{
id: "3",
name: "kivvi",
gitUrl: "https://github.com/bitbaum/kivvi.git",
solonOrgSlug: "kivvi-board",
},
],
[],
claims,
);
const by = Object.fromEntries(rows.map((r) => [r.slug, r]));
assert.strictEqual(by.loki.solon, null, "a squatted name does not attribute");
assert.deepStrictEqual(
by.heidi.solon,
{ slug: "heidi-zh" },
"a claim attributes, and to the organisation's real address",
);
assert.deepStrictEqual(
by.kivvi.solon,
{ slug: "kivvi-board" },
"an explicitly stored link still wins",
);
console.log("solon-claims: ok");