Skip to content

Export document lineages from the library, not just the CLI #17

Open

Description

@MastaP

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/verify can't verify a lineage. Its verify() only handles timestamp tokens and fails a lineage token on the token type.
  • @unicitylabs/proof-cli can'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 under src/lib/ is internal until src/index.ts or src/verify.ts lists 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, describeLineage
  • LINEAGE_TOKEN_TYPE, LINEAGE_TOKEN_TYPE_HEX
  • LineageFormatError
  • LineageIssuanceVerifier and createLineageVerificationContext, matching TimestampIssuanceVerifier and createVerificationContext, for callers who compose with the SDK's own token.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 (returns recovered), and possibly createLineage as the simple form
  • appendRevision, plus the split steps prepareRevision, certifyRevision and recoverRevision (see below)
  • findSuccessor, currentProducerKey, isFinalized
  • LineageError, whose code values 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:

  1. Document the protocol. Call prepareRevision, persist IPreparedRevision.transaction durably, then call certifyRevision. On restart, call recoverRevision with the persisted transaction before preparing anything new. After createOrRecoverLineage returns recovered: true, call findSuccessor.
  2. 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 in appendJournaled would then be a library function, the CLI and library callers would share it, and the library would stay free of node: 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: /verify reaches 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 without expectedTokenId), 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

Activity

  1. added
    enhancement
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions