Repository navigation
Description
Problem
#16 adds document lineage tokens (stamp-revision, plus lineage support in verify and inspect), but only to the CLI. Neither entry point of the library exports a lineage symbol:
@unicitylabs/proof-cli/verifycan't verify a lineage. Itsverify()only handles timestamp tokens and fails a lineage token on the token type.@unicitylabs/proof-clican't create a lineage or append to one.- Deep imports are refused by the exports map (
ERR_PACKAGE_PATH_NOT_EXPORTED), as intended since Own the library surface: the package already exports one by accident #14: a symbol undersrc/lib/is internal untilsrc/index.tsorsrc/verify.tslists it.
So a project that wants lineages from code has to shell out to the CLI and parse its output.
Proposal
The lineage code in src/lib/ already has library-shaped boundaries, so most of the work is choosing names and documenting them. Names below are as of #16's head (05cc9ef).
@unicitylabs/proof-cli/verify (offline)
LineageVerification.ts and LineagePayload.ts import only SDK modules and modules already behind /verify: no aggregator client, no JSON-RPC transport, no Node builtin.
verifyLineage,describeLineageLINEAGE_TOKEN_TYPE,LINEAGE_TOKEN_TYPE_HEXLineageFormatErrorLineageIssuanceVerifierandcreateLineageVerificationContext, matchingTimestampIssuanceVerifierandcreateVerificationContext, for callers who compose with the SDK's owntoken.verify- types:
ILineageDescription,ILineageRevisionDescription,ILineageVerificationResult,ILineageVerifyOptions
ILineageVerifyOptions.expectedTokenId should be prominent in the docs. Only the token id identifies a lineage; see the discussion on #13.
@unicitylabs/proof-cli (adds stamping through a gateway)
LineageClient.ts needs StateTransitionClient, the same as stamp.
createOrRecoverLineage(returnsrecovered), and possiblycreateLineageas the simple formappendRevision, plus the split stepsprepareRevision,certifyRevisionandrecoverRevision(see below)findSuccessor,currentProducerKey,isFinalizedLineageError, whosecodevalues become public API:ALREADY_CERTIFIED,FINALIZED,INVALID_TOKEN,SUPERSEDED,WRONG_KEY- types:
ILineageGenesis,IPreparedRevision,SuccessorLookup
Whether to also export the format classes (LineageRevision, LineageGenesisReason) is open. They're only needed to build or parse lineage payloads without the client.
Crash recovery is a CLI feature today
This is the part that needs design rather than just exports.
Append journal. The journal that makes an interrupted append recoverable is in src/commands/revisionJournal.ts, and the durable file write is in src/commands/durableFile.ts. Both use node:fs, and PublicApiTest asserts that no proof-cli module reachable from the library imports a Node builtin ("imports no Node builtin from any module in this package"). So code calling appendRevision gets no journal. If it's interrupted after certification, nothing records which transaction was certified. The aggregator keeps only its hash, so the revision can't be completed without the inputs.
Superseded check. The CLI's check that refuses a recovered genesis whose lineage has moved on (assertNotSuperseded in stampRevision.ts) is also in the command. A library caller gets recovered: true from createOrRecoverLineage and has to call findSuccessor itself.
Options, not exclusive:
- Document the protocol. Call
prepareRevision, persistIPreparedRevision.transactiondurably, then callcertifyRevision. On restart, callrecoverRevisionwith the persisted transaction before preparing anything new. AftercreateOrRecoverLineagereturnsrecovered: true, callfindSuccessor. - Move the logic into the library behind a storage interface. Something like
IRevisionJournal { read(); write(pending); remove() }, with the CLI's file journal as one implementation. The append-with-recovery flow now inappendJournaledwould then be a library function, the CLI and library callers would share it, and the library would stay free ofnode:imports.
Option 2 avoids two copies of the recovery logic. Either way, the library flow has to get the two journal cases from the #16 review right. First, "not certified yet" doesn't mean "never submitted": a request can still be waiting for its round, and aggregator-go accepts a second request for the same state with SUCCESS and then silently drops whichever one loses the round. Second, a journal is removed only by the run that created it.
Done when
- The names above (or the agreed subset) are exported from the stated entry point, and
PublicApiTest's pinned lists are updated. -
PublicApiTest's module-graph check still passes:/verifyreaches no aggregator client, JSON-RPC transport or Node builtin. - A package-level test imports by package name, verifies a lineage fixture through
/verify(with and withoutexpectedTokenId), and creates and appends through the root against the test aggregator. - Crash recovery for library callers is either provided (option 2) or documented step by step (option 1), including the superseded check after a recovered genesis.
- README's "Library" section covers lineages: which entry point,
expectedTokenId, what "latest in this file" does and doesn't prove, and the caller's recovery responsibilities.
Notes
- Depends on Revision history #16 landing first.
- Purely additive: no existing export changes.
Activity