@inversealtruism/csd-indexwire
v0.1.0
Published
The csd-indexer REST wire contract: TypeScript types for every served row shape (proposals, attestations, txs/outputs, health, analytics) + runtime guards that mirror the production consumer postures (fail-loud on structure, conservative on values). One s
Readme
@inversealtruism/csd-indexwire
TypeScript types + runtime guards for the csd-indexer REST wire: proposals, attestations,
txs/outputs, and /health. One source of truth for a contract that was previously hand-maintained
in five places (the indexer serializer, the cairnx scanner's local RawProposal, cairn's project
reader, cairn-sdk's untyped IndexerClient, and each repo's test fixtures).
Posture (inherited from the production consumers, verbatim)
- Structure fails loud. A non-array page, a missing txid, a non-ordinal height/pos throws. The CairnX resolver must freeze on last-good state rather than resolve from a malformed feed.
- Values fail conservative. A malformed tx output is skipped, never thrown: dropping an output can only make a payment look smaller, so an uncovered fill/fee gets rejected, and one weird tx cannot DoS a scan.
- Coercions are the resolver feed's. Ids and addresses lowercase; epochs/scores through
Number(); a saturatedexpires_epochstays non-safe on purpose (GRX-WIRE-CLAMP-1: the resolver's ownisSafeIntegergate must fire identically on the indexer and SPV wires).
Do not "tighten" a guard here without reviewing the consumer it was extracted from: several
asymmetries (e.g. confidence clamping to 0 while score passes through) are deliberate.
API
Types: ProposalRow, AttestationRow, TxRow, TxOut, HealthResponse (the snake_case wire
shapes). Guards: requireArrayPage, requireOrdinal, parseProposalRow, parseAttestationRow,
conservativeOutputs (+ MAX_OUTPUTS_PER_TX), parseHealth.
Adoption map (post-publish; each swap is behavior-preserving by construction)
- cairnx
src/scan.ts: replace the localRawProposalinterface withProposalRow/parseProposalRow, the inline attestation coercions withparseAttestationRow,reqOrdwithrequireOrdinal, and the output filter withconservativeOutputs. Acceptance bar: full cairnx suite green,pnpm run audit:allclean on a settled tree,/cairnx/statebyte-equal before/after at an equal tip. - csd-indexer: a serializer conformance test asserting every served row parses with these guards (binds the producer to the contract; no runtime change).
- cairn
src/lib/project.ts: parse indexer rows withparseProposalRow. - cairn-sdk
src/indexer.ts: type theunknownreturns ofproposal()/attestations()/ domainProposals()/health()with these types.
Versioning: additive response fields are a minor bump; renames/removals are a major bump plus a
changelog entry. The indexer's /health.version field (0.2.5+) says what the producer runs.
Tests
pnpm test — guard assertions over verbatim fixtures captured from the live Granus indexer
(2026-07-03) plus adversarial structure/value cases pinning the posture above.
