Repository navigation
Revision history - #16
Conversation
New `stamp-revision` command that creates a document lineage token for an initial revision, or appends the next revision to an existing one, as designed in issue #13. - Genesis: a mint of the lineage token type (SHA-256 of "unicity-document-lineage") with a random salt, auxData CBOR[0, H(doc_0)], and a mint reason (CBOR tag 39200) carrying the issuer's signature over the token id, token type and auxData. The recipient is P_sig on the next producer's key. - Revisions: transfers with data CBOR[i, H(doc_i)], signed under the P_sig named by the previous revision. The state mask is derived from the signer's key and the source state, so a crashed run can be replayed and recovers the same transaction. - Verification: SDK token verification with a fail-closed lineage issuance policy, plus chain rules the SDK does not check (indices increase by one, reference times never decrease). The producer key and token validity are checked before contacting the gateway. - Writing: a new lineage is created exclusively; an existing one is replaced via a temporary file and rename. On write failure the full token is printed as hex, which --token-file accepts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`verify` and `inspect` now recognise lineage tokens by their token type and show them revision by revision: hash, signer, next producer, certification time and round. Every other token is handled as a timestamp, exactly as before. - verify runs the lineage verification (SDK checks with the lineage issuance policy, plus the chain rules) against the same trust base selection as for timestamps. - With --file or --hash, a lineage passes if any revision carries the digest; the output names the matching revisions and whether a later revision supersedes them. A digest no revision carries is a failure. - The signer of revision 0 is the issuer from the genesis reason; of each later revision, the key the previous revision passed to. - JSON output for a lineage has "tokenType": "lineage", a revisions array and matchingRevisions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`stamp-revision --finalize` certifies the final revision of a document as a seal and burns the lineage token, as designed in issue #13: the revision's auxData is b_seal = CBOR["seal", i, H(doc_i)] and its recipient is P_burn(H(b_seal)), so no successor can ever be certified and the burn commits to the final digest. - Exactly one of --recipient-key, --recipient-key-file and --finalize is required; any other combination is a usage error. - Appending to a finalized lineage fails before contacting the gateway. On a new lineage, --finalize mints revision 0 as a seal. - Verification requires a revision to be burned exactly when it is a seal, with the burn reason committing to the seal payload, and a seal to be the last revision. - verify and inspect mark the seal "(final)" and report the lineage as finalized; JSON output gains "finalized" and per-revision "sealed", and stamp-revision reports "finalized" with a null nextProducer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/lib/lineage/* moves to src/lib/, so the library code behind `stamp` (Timestamp*.ts) and `stamp-revision` (Lineage*.ts) sits side by side. Imports updated; no behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches the timestamp tests, which are named after the module they test (TimestampClientTest for TimestampClient); the top-level describe follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LineageClientTest keeps creating, appending and finalizing. LineagePayloadTest takes the CBOR encodings, the token type pin and the genesis reason, plus a new check of sealPredicate. LineageVerificationTest takes the hand-built genesis and seal tokens that verification must reject, now sharing one minting helper, and describeLineage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- resolveStampRevisionConfig and parsePublicKey move to ConfigTest, next to resolveStampConfig and parsePrivateKey. - writeRevisionToken moves to StampRevisionWriteTest, the counterpart of StampWriteTest. - StampRevisionTest keeps stampRevisionWith. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lineage cases of `verify` join VerifyTest and those of `inspect` go to a new InspectTest, so each command's tests live in one file. The finalized lineage case, which checked both commands, becomes one test in each. The shared lineage (three revisions, plus a finalized copy) is built by tests/support/LineageFixtures.ts, next to TimestampFixtures.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OutputTest keeps the shared helpers (time and network labels, line, the not-a-token envelope, warnings, the result tree). Each command's views move to that command's tests: keygen output to KeygenTest, the timestamp verify and inspect views to VerifyTest and InspectTest, and the stamp views to a new StampTest, the counterpart of StampRevisionTest. The stamped token they use comes from createTimestampToken in TimestampFixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each command's output tests sit with that command, as for timestamps: - StampRevisionTest: revisionText and revisionJson for an ordinary, a new and a final revision, and revisionRecoveryLines. - VerifyTest: lineageVerifyText and lineageVerifyJson for every expected hash label (none, latest, superseded, several, final, mismatch), the trust base naming, and failures with and without a result tree. - InspectTest: lineageInspectText, lineageInspectJson and lineageDescriptionJson, including unreadable revisions, a wrong claimed index, an unreadable issuer, a recipient that is not P_sig, a burn that is not a seal, and an unrepresentable time. The lineage fixture now also exposes the sealed token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MastaP
left a comment
There was a problem hiding this comment.
Checked at 6449713, after the module move and the test split; those commits don't change source behaviour. Lint, typecheck and the full suite pass locally.
The chain rules from the sketch are all implemented: index equals position, reference time never decreases, the seal comes last, and a revision is burned exactly when it is sealed. The deterministic state mask makes an identical re-run replay cleanly, and (the final) is sound because the seal is a burn.
Three things I'd want fixed before merging:
- An interrupted append can strand the lineage (
LineageClient.ts:249). Nothing records what was certified, and a re-run with any different input fails with an unexplainedTRANSACTION_HASH_MISMATCH. (the latest)claims a tip that offline verification can't know (output.ts:582).- There's no way to pin the origin (
cli.ts:108). Uniqueness holds per token id, but the random genesis salt lets one issuer start any number of lineages for the same first document.
The rest are smaller: no tests for the time rule or the index rule after genesis, the README recovery promise for revision 0, network selection on append, and some file-handling edge cases. Details are inline.
Two points concern the sketch itself rather than this implementation: the issuer signature doesn't cover the first producer, and pinning by issuer key + H(doc_0) isn't unique. I've raised both on #13: #13 (comment)
Review on issue #13: the issuer signed (id, ty, auxData), so it endorsed the origin document but not who produces revision 1. In a delegated mint the submitter could name any first producer and verification would still report the issuer signature as valid, so the chain of custody started with a link the issuer never named. The signed message is now SHA-256(CBOR["unicity-document-lineage", 1, id, ty, recipient, auxData]), with the recipient in the predicate's own tagged CBOR encoding, byte for byte as the mint carries it. The verifier takes the recipient from the mint transaction, so it is not repeated in the reason, whose format is unchanged. For a lineage finalized at genesis the signed recipient is the burn, so the issuer also endorses that it is final. The format changes in place, keeping version 1: no lineage has been released, and lineage tokens made before this commit no longer verify. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on issue #13: pinning a lineage by issuer key and H(doc_0) is not unique. One issuer can start any number of certified lineages from the same document, and verification cannot tell them apart; only the token id identifies one, so verifiers need it through a trusted channel. - verify --token-id <hex> asserts which lineage the token is. A different id fails (exit 1) with "Token id mismatch", reported before a hash mismatch. The text output gains a "Lineage id" line that says when the id was not checked, and the JSON gains expectedTokenIdMatches. The option is a usage error for tokens that are not lineages. verifyLineage takes the id as expectedTokenId. - stamp-revision marks the token id of a new lineage as the thing to give to verifiers. - The genesis salt is derived from the issuer's private key, the encoded recipient and revision 0, like the state mask of later steps. Re-running an interrupted genesis recovers the same lineage instead of starting a parallel one, and nobody without the issuer's key can compute the id before the genesis is certified. Tests that shared an aggregator now get one each, since equal inputs now continue the same lineage. - README and the skill say that the token id, and nothing else, identifies a lineage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MastaP
left a comment
There was a problem hiding this comment.
Re-checked at 825e059.
Thanks, 556402d and 825e059 address both points from #13 and three findings from the earlier review:
- Issuer signature covers the genesis recipient (
LineagePayload.ts). The tests fail if the recipient is dropped from the signed message, and also if the verifier skips the check. - Origin pin (
cli.ts:108).verify --token-idand theLineage idline close it. - Genesis recovery (
README.md:136). With the derived salt, the recovery claim now holds for revision 0 too. The reason for keying the salt on the private key rather than on public inputs holds: the mint's state id depends only on the token id, so if the id could be computed publicly, someone else could mint into its slot first.
The derived salt brings one new issue: re-running a genesis after the lineage has moved on silently writes a file with only revision 0. Details are inline on LineageClient.ts.
Still open from the earlier review:
- Interrupted append with different inputs (
LineageClient.ts):STATE_ID_EXISTSends in a plainTRANSACTION_HASH_MISMATCHerror. Must-fix. (the latest)(output.ts:594, unchanged). Must-fix. It's now also reachable through the genesis re-run below.- Time rule and post-genesis index rule are untested (
LineageVerification.ts). Ifrevision.referenceTime >= previous.referenceTimeis replaced withtrueand the index check is limited to position 0, the suite still passes (260/260). - Append checks the token against
--network, not against the token's own network (stampRevision.ts:79). - The token file is replaced with no fsync, and a symlink or file mode isn't preserved (
stampRevision.ts:49). - The EEXIST advice names
--force/--out, andstamp-revisionhas neither option (stampRevision.ts:46). - A truncated file left by a failed genesis write isn't cleaned up (
stampRevision.ts:54).
@ahtotruu, are more fixes planned in this PR? 1 and 2 are the ones I'd want before merge, and 3 is cheap. 4–7 could be follow-up issues if you'd rather keep this PR focused. Either way, please reply on each of the existing review threads, saying whether it's fixed (with the commit), deferred (with the issue), or disputed, and resolve the ones you've dealt with. That way we can see what's left at a glance.
An append certified by the aggregator but never written to the token file could strand the lineage: the aggregator keeps only the transfer's hash, and a re-run with any different input ended in a bare TRANSACTION_HASH_MISMATCH. - stamp-revision records each append in .<name>.pending next to the token file before submitting it (exclusive create, fsync), echoes it to stderr unless --quiet, and removes it once the token file holds the revision. - The next run recovers a journaled revision the aggregator certified, whatever inputs it is given; with other inputs it writes the recovered revision and refuses the request with ALREADY_CERTIFIED (exit 1). - STATE_ID_EXISTS is now a known answer: a replay of the same transaction completes without the "unknown status" warning, and a slot taken by another transaction is reported only once that proof authenticates against the trust base. Without a journal, the taken slot is reported as ALREADY_CERTIFIED and the attempted revision is echoed regardless of --quiet. - The test aggregator answers STATE_ID_EXISTS for a state id it already holds, as aggregator-go does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…moved on Re-running a genesis whose token file is elsewhere, or meaning to start a second lineage from the same document and first producer, silently produced revision 0 of the existing lineage, presented as a new one even after it had moved on. - createOrRecoverLineage looks for the mint's proof before submitting, and counts STATE_ID_EXISTS for the same mint as a recovery too. - A recovered genesis is marked "(existing lineage, recovered)", with a note on stderr, regardless of --quiet, on how to start a separate lineage. - Before writing it, findSuccessor asks the aggregator whether revision 1 exists. An authenticated proof means the lineage has moved on: nothing is written, and the command exits 1 (SUPERSEDED) with the token id, when revision 1 was certified and by whom. A failed lookup or an unverifiable proof writes the file with a warning. - stamp-revision output gains "recovered", also for appends replayed or recovered from the journal; onAlreadyCertified reports replays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… match `verify` labelled a match on the last revision of an unsealed lineage "(the latest)", a claim offline verification cannot back: every earlier state of a lineage is itself a valid token, so an old copy, or one with trailing revisions dropped, still verifies. The label is now "(the latest in this file)"; "(the final)" after a seal is unchanged. The README and the agent skill say that only --finalize proves no later revision exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rules the protocol does not provide had no tests past genesis: replacing the time check with `true`, or checking the index at position 0 only, left the suite passing. New tests build transfers by hand, past the checks appendRevision makes: - a transfer claiming index 5 at position 1, and one repeating index 1 at position 2; - a revision certified before the one it follows, and before the genesis, by certifying precomputed states out of order; - a seal followed by a revision, which SealIsLast rejects alongside SealBurned; - an in-order chain built the same way, as the control. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The configured network was used to verify the token, so a valid testnet2 lineage appended without --network testnet2 failed as an invalid token (exit 1). The network is still not taken from the token, since it also picks the gateway the API key goes to; instead the mismatch is caught before the journal is read or anything is submitted, as a usage error that names both networks and the setting to change: --network, or --trust-base when the token's network has no bundled trust base or a trust base file is configured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the exclusive create of a new lineage's token file failed with EEXIST (a file appeared during the proof wait, or --token-file was a dangling symlink), the advice was "pass --force or another --out", and stamp-revision had neither option. The error now says which case it is, that the genesis is certified, and that running the same command again recovers it: with another --token-file, or, for a dangling symlink, with --force, which creates the file the symlink points to. --force makes the new-lineage write non-exclusive. It never applies to an existing token file, which is appended to, not replaced; combining the two is a usage error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new lineage's token file was created in place, so a write that failed partway (ENOSPC, EIO, a kill) left a truncated file; the next run took the append path and failed with "is not a token". An append, and keygen --force, renamed a temporary into place without fsyncing it or the directory, so a power loss could leave an empty file, and the rename replaced a symlink with a regular file and reset the file mode. writeFileDurably writes to a sibling temporary at 0600 when its final mode is to be set, fsyncs it, publishes it, and fsyncs the directory: `create` links it into place, atomic and as exclusive as O_EXCL, with EEXIST naming the target; `replace` renames it over the old file and keeps that file's mode unless one is given. Where hard links are unsupported, `create` falls back to an exclusive create of the name and removes it if the write fails. Symlinks can be followed, so the file at the end of the chain is written and the links kept. stamp-revision uses it for every token write. An append, and --force for a new lineage, write through a symlink at --token-file; a plain new lineage still refuses one. keygen uses it with mode 0600, and never writes through a symlink. An undecodable token file now says to move it away and run the same command again, which recovers the lineage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the re-check. Everything on your list is now fixed in this PR rather than deferred: 1 and 2 (the must-fix items), 3, the new genesis re-run issue, and 4–7 as well. Each review thread now has a reply with its commit, including the two earlier ones you already confirmed. Two fixes deliberately differ from what you suggested; the reasons are on their threads:
|
MastaP
left a comment
There was a problem hiding this comment.
Re-checked at 05cc9ef. Thanks for the thorough round. All eight items that were still open are fixed, and each fix is covered: reverting it, or disabling the rule, fails tests (time rule 2, index rule after genesis 2, SealIsLast 1, superseded check 3, network check 3, mode preservation 3, (the latest in this file) 3, trusting a conflicting proof without verifying it 1). I agree with both deliberate deviations: the API key is the right reason not to infer the network on append, and --force should never mean replacing the only copy of a lineage.
Two new issues in the journal, both inline. Each can lose the one record this feature exists to keep:
- An earlier run's journal is deleted before its outcome is known (
stampRevision.ts:249, with the cause inTimestampClient.ts:191). Reproduced: a re-run with different inputs, made while the interrupted run's request is still waiting for its round, deletes that run's journal and fails with the oldTRANSACTION_HASH_MISMATCHerror. writeJournalremoves a journal it didn't create (revisionJournal.ts:108), which loses a concurrent run's journal.
Two minor points, also inline: the conflict check passes this run's expiresAt (TimestampClient.ts:107), and keygen now stages the key in a temporary file on the non---force path too (keygen.ts:41).
I'd merge once 1 and 2 are fixed; both look like a few lines.
…SUCCESS Review on PR #16: - aggregator-go answers SUCCESS to a repeat for a state whose first request is still waiting for its round, then certifies the first and drops the repeat. certifyTransaction looked up a conflict only after STATE_ID_EXISTS, so the repeat failed with the SDK's plain TRANSACTION_HASH_MISMATCH. It now looks after any failure but a timeout, so the result is ALREADY_CERTIFIED. - A re-run deleted an earlier run's journal as soon as its revision was not certified yet, although its request could still be. Journals are now one per transfer, `.<name>.<tag>.pending`, and one is removed only once its outcome is known: the token file holds its revision, or a verified proof shows its slot holds another transfer. Open ones are listed on stderr even with --quiet, and recovered when their revision turns out to be certified. - writeJournal removed the file on any failure, including the EEXIST of a journal another run had created. It now removes only what it created, and accepts an existing journal for the same transfer. - The conflict check verified the other transaction against this one's expiresAt; it now uses the deadline recorded in the proof. - keygen staged even a fresh key in a temporary file, which a crash could leave as a hidden second copy. A fresh key is again written in place, now through writeFileDurably's createInPlace, with an fsync. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MastaP
left a comment
There was a problem hiding this comment.
Re-checked at d54593c. All five threads from the last round are fixed, and each fix is covered: reverting it fails tests (keeping earlier journals at start 3, removing them after a certification 1, dropping one whose slot is taken 1, looking them up again after ALREADY_CERTIFIED 1, listing them despite --quiet 3, the conflict lookup after SUCCESS 1, leaving a journal alone on EEXIST 1, refusing a same-named journal with other content 1, the other transaction's expiresAt 1). The queueing client reproduces the three-run scenario faithfully, and the variant where run 2 also times out is a good addition. The two journal issues that were holding the merge are resolved.
Two new issues, both inline:
keygenwithout--forcecan delete an existing key (durableFile.ts:220). The in-place create removes the target after any open failure other than EEXIST, including EMFILE, which Linux returns even when the file exists. Small fix; I'd like it before merge.- A slower concurrent run can roll the token file back (
stampRevision.ts:342). Reproduced: a revision certified and written by another run disappears from the file, and its journal is already gone. This also happens at 05cc9ef, so it isn't from this commit; fine as a follow-up issue if you'd rather not hold the PR for it.
A nit, also inline: the new conflict lookup isn't bounded by --timeout (TimestampClient.ts:202).
Smaller test gaps: removing any of these leaves the suite green: the created guard before removing the journal on a StampError, removeKept() in settle, and the tolerant branch in recoverKept. Each one's effect is small, but a test apiece would pin the intent.
Review on PR #16: createInPlace removed the target after any failure from writeNew other than EEXIST, taking it to have come after the create. But the open itself can fail with EMFILE, ENFILE or ENOMEM even when the file exists, since Linux allocates the descriptor before it looks up the path, so `keygen --out existing.key` could delete an existing private key, and the token file's no-hard-link fallback could delete the file in its way. The injected file system now offers a plain exclusive openNew, and the create-write-clean-up sequence lives in durableFile.ts as writeExclusive: a failed open removes nothing, whatever the error; a failed write, fsync or close after it removes the file this call created. createInPlace removes the file only after a failed chmod. Tests cover EMFILE, ENFILE and ENOMEM on an existing file for both paths, and each step failing after the open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on PR #16: the lookup after a failed wait got only the caller's abort signal, not the deadline handed to waitInclusionProof, so after a prompt failure a stalled gateway could keep the command running past --timeout until fetch gave up. certifyTransaction now builds one deadline right after submission and uses it for the lookup after STATE_ID_EXISTS, the wait, and the conflict lookup after a failed wait. A lookup cut off by the deadline ends with the SleepError a timed-out wait gives (exit 3), so stamp-revision keeps every journal, as for a timeout. A test client whose lookups stall until their signal aborts covers both lookups, and a stamp-revision run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on PR #16: an append replaced the token file with the token it read at start plus its revision, without checking that the file had not moved on, so a slower concurrent run could write over a revision another run had certified and written, whose journal was already gone. The write in settle had the same exposure. - An append takes a lock file, `.<name>.lock` next to the token file after symlinks are resolved, before it reads any journal, and releases it when it ends. A second append meanwhile exits 2 before submitting, naming the holder. Release removes only this run's lock. Under the lock the token file is re-read; if it changed since configuration, the run exits 2 before submitting. - writeFileDurably's replace takes `ifUnchanged`, and fails with ECHANGED instead of renaming over a file that no longer holds those bytes. Both append writes pass the bytes the run started from. When the file changed but already holds this run's revision (same lineage, verified, same transfer by hash), the run notes it and completes; otherwise it prints its token as hex, keeps its journal, and exits 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on PR #16: three lines could be removed with the suite still green. - The `created` guard before removing the journal on a StampError: a re-run with the same inputs reuses an earlier run's journal, and its own refused request must not remove it. Plus the other side: a run refused after creating its journal removes it. - removeKept() in settle: journals are tried in name order, so an uncertified one could be removed by the ALREADY_CERTIFIED branch before settle ran. The test names the journals so the uncertified one sorts last, leaving settle to remove it. - The tolerant branch of recoverKept: a client certifies a rival transfer on the run's submission and then fails every lookup, so the kept journal's lookup after ALREADY_CERTIFIED fails; the run keeps the journal and still exits 1 with ALREADY_CERTIFIED. Removing each line now fails exactly its test. findJournals says that a journal's name is matched by pattern only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the re-check. All of it is addressed at 8036630, each with a reply on its thread: the The three test gaps from your summary are covered in 8036630; removing each line now fails exactly one test:
|
MastaP
left a comment
There was a problem hiding this comment.
Re-checked at 8036630. Everything from the last round is addressed, and each fix is covered: reverting it fails tests (removing after a failed open 4, the comparison before the rename 5, the lock 1, releasing it 24, locking the resolved path 1, mapping a cut-off lookup to a timeout 3). Thanks for taking the rollback into this PR rather than a follow-up; the lock plus the re-check under it is the right shape.
Approving. Three nits inline, none blocking:
- The README's "never rolled back" is a little stronger than a check-then-rename can guarantee (
README.md:145). - A lock whose setup fails is left behind (
tokenLock.ts:79). - The verification in
fileHoldsRevisionisn't covered by a test (stampRevision.ts:183).
On the lookups outside certifyTransaction that are still bounded only by fetch's defaults: leaving them is fine, and a follow-up issue sounds good.
… the README Review nits on PR #16: - The lock is now created with writeExclusive, so a lock whose contents cannot be written, or whose close fails, is removed again instead of refusing every later append. - A same-lineage file with the same transfers, certified on another aggregator, must not count as holding this run's revision: the run prints its token as hex, keeps its journal and exits 2. Replacing the verification with `true` fails it. The transfer-hash comparison is commented as a cheap pre-check, redundant once the file verifies. - README: the lock is what keeps other stamp-revision runs from rolling the token file back; the compare-before-replace catches a program that ignores the lock too, unless it writes between the check and the replace, since there is no atomic compare-and-replace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Checked 38915f9, all three are fixed:
Thanks for opening #18. The PR is approved and CI is green, so feel free to merge. |
Adds
stamp-revisioncommand to resolve #13 according to the scheme suggested by @ristik in #13 (comment)