Skip to content

Commit c854730

Browse files
fix: scope ledger hashes by organization
1 parent 84f2800 commit c854730

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/server/src/__tests__/attestations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ test("ledger chains are independent for each organization", async (t) => {
175175
const independent = await app.storage.attestations.appendAttestationLedgerEntry({
176176
orgId: "org_chain_b",
177177
entryType: "checkpoint",
178-
payload: { event: "first", org: "org_chain_b" },
178+
payload: { event: "first" },
179179
jws: "test-jws-b1",
180180
createdAt: "2000-01-01T00:00:00.000Z",
181181
});

packages/server/src/db/migrations/0007_attestation_ledger.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS attestation_ledger (
3737
entry_hash TEXT NOT NULL CHECK (length(entry_hash) = 64),
3838
created_at TEXT NOT NULL,
3939
UNIQUE (org_id, org_seq),
40-
UNIQUE (entry_hash)
40+
UNIQUE (org_id, entry_hash)
4141
);
4242

4343
CREATE INDEX IF NOT EXISTS idx_attestation_ledger_org_seq

packages/server/src/storage/sqlite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ const SELECT_ATTESTATION_LEDGER_ENTRY_BY_HASH_SQL = `
478478
seq, org_id, org_seq, entry_type, jti, commit_sha, repo, agent_id,
479479
sponsor_id, payload_json, jws, prev_hash, entry_hash, created_at
480480
FROM attestation_ledger
481-
WHERE entry_hash = ?
481+
WHERE org_id = ? AND entry_hash = ?
482482
LIMIT 1
483483
`;
484484

@@ -2455,7 +2455,7 @@ class SqliteAttestationStorage implements AttestationStorage {
24552455
const stored = hydrateAttestationLedgerEntry(
24562456
db
24572457
.prepare<AttestationLedgerRow>(SELECT_ATTESTATION_LEDGER_ENTRY_BY_HASH_SQL)
2458-
.get(entry.entryHash),
2458+
.get(entry.orgId, entry.entryHash),
24592459
);
24602460
if (!stored) {
24612461
throw new Error("attestation ledger insert did not return a row");

0 commit comments

Comments
 (0)