Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f971f7d
Add stamp-revision: document lineage tokens
ahtotruu Nov 5, 2026
d48dd0a
Verify and inspect document lineage tokens
ahtotruu Nov 5, 2026
b42a627
Finalize a document lineage with stamp-revision --finalize
ahtotruu Nov 5, 2026
c53152f
Move the lineage modules next to the timestamp ones
ahtotruu Nov 5, 2026
28040c4
Rename LineageTest to LineageClientTest
ahtotruu Nov 5, 2026
1518223
Split the lineage tests by module, as for timestamps
ahtotruu Nov 5, 2026
6cb7d6f
Split StampRevisionTest along the lines of the stamp tests
ahtotruu Nov 5, 2026
4eb2762
Split LineageCommandsTest into VerifyTest and InspectTest
ahtotruu Nov 5, 2026
ffee4d9
Split OutputTest by command
ahtotruu Nov 5, 2026
6449713
Test the lineage output functions directly
ahtotruu Nov 5, 2026
556402d
Cover the genesis recipient with the issuer signature
ahtotruu Nov 10, 2026
825e059
Identify a lineage by its token id
ahtotruu Nov 10, 2026
2365d27
Recover interrupted lineage appends from a journal
ahtotruu Nov 16, 2026
16e1458
Recover a re-run genesis as the existing lineage, and refuse it once …
ahtotruu Nov 16, 2026
5dbea61
Say "the latest in this file" instead of "the latest" for an unsealed…
ahtotruu Nov 16, 2026
8fe985e
Test the index, time and seal-is-last chain rules
ahtotruu Nov 16, 2026
a6413b2
Refuse, with exit 2, an append to a token from another network
ahtotruu Nov 16, 2026
6915311
Add --force to stamp-revision, and give its EEXIST advice that applies
ahtotruu Nov 16, 2026
05cc9ef
Write token and key files durably, never leaving a partial file
ahtotruu Nov 16, 2026
d54593c
Keep a journal until its outcome is known, and catch conflicts after …
ahtotruu Nov 16, 2026
0ce949b
Remove a file only once its exclusive create is known to have succeeded
ahtotruu Nov 24, 2026
2654c60
Keep the conflict lookups inside --timeout
ahtotruu Nov 24, 2026
a44e025
Lock appends, and never roll the token file back
ahtotruu Nov 24, 2026
8036630
Test the refusal guard, settle's cleanup and the tolerant lookup
ahtotruu Nov 24, 2026
38915f9
Clean up a failed lock, test fileHoldsRevision's verification, temper…
ahtotruu Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 77 additions & 4 deletions README.md

Large diffs are not rendered by default.

54 changes: 52 additions & 2 deletions skills/unicity-proof/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ Then read `Expected hash matches`. Without `--file` or `--hash` that line tells
you the proof was never tied to anything — a bare `Status OK` on its own
establishes nothing about the file in front of you.

A document lineage token (from `stamp-revision`, `Token type document lineage`)
holds several revisions. With `--file` it passes if **any** revision carries the
file's hash, so read the `Expected hash` line in full: `matches revision 1;
superseded by revision 2` means the file is a genuine but outdated revision.
`matches revision 2 (the final)` means the lineage was finalized with that
revision (`--finalize`); no later revision can exist. `matches revision 2 (the
latest in this file)` does **not** mean the file is current: any older copy of
an unsealed lineage still verifies, and verification is offline, so later
revisions may have been certified since. Only `(the final)` rules them out; if
being current matters, ask whoever holds the lineage for the current file.

A matching hash does not say *which* lineage the file is in: one issuer can
start several certified lineages from the same document. Only the token id
identifies a lineage, so verify with `--token-id <id>`, using the id the
issuer gave you through a channel you trust, and read the `Lineage id` line:
`matches` ties the result to that lineage; `not checked` means the `Issuer`
and `Expected hash` lines are not enough on their own; `differs` means this
is another lineage.

Also read the `Trust base` line. A verdict is only as good as the root of trust
behind it, and `OK` against someone else's trust base means nothing.

Expand All @@ -44,6 +63,37 @@ without it the proof is gone.
- **A failed write after certification is recoverable.** The token is printed to
stderr as hex, and both `verify` and `inspect` accept hex, so save that text.
Do not re-stamp.
- **An interrupted `stamp-revision` append is recoverable; do not improvise.**
Run `stamp-revision` again on the same token file: it recovers the revision
from the `.<name>.<tag>.pending` journals next to the token file. There can be
more than one: a revision an earlier run submitted keeps its journal until its
outcome is known, and stderr lists it as `not certified yet`. Never delete a
journal by hand; until the token file holds the revision, it is the only
record of what was certified. Exit 1 with `already certified with different
content` means an earlier run certified something else for this revision:
only that run's digest and recipient recover it, and they are on stderr from
when it was submitted.
- **Run one `stamp-revision` append per token file at a time.** Exit 2 saying
`Another stamp-revision run is appending` means wait for it. Delete the
`.<name>.lock` file only if no run is active (it holds no data); never delete
a journal.
- **`(existing lineage, recovered)` means no new lineage was created.** The
same issuer key, document and first producer always give the same lineage.
If `stamp-revision` exits 1 saying `the lineage has moved on`, later
revisions exist: get the current token file from whoever holds the lineage
rather than creating it again.
- **A new lineage blocked by a file at `--token-file` is not lost.** Exit 2
saying the file appeared during certification, or is a dangling symlink, means
the genesis is certified: run the same command with another `--token-file` to
recover it. `--force` only overwrites for a new lineage; never use it to
"replace" an existing token file (it refuses).
- **Exit 1 saying the token file `is not a token`, with no lineage yet:** an
earlier run may have failed writing it. Move the file away (don't delete it)
and run the same command again; the lineage is recovered.
- **Every `stamp-revision` append needs the lineage's network.** The network is
not read from the token file, so a testnet2 lineage needs `--network testnet2`
each time. Exit 2 naming two networks means the configuration, not the token,
is wrong: change the setting it names. Do not re-create the lineage.
- `--sign` exits 2 unless a key is configured. Use it in any automated path that
must never silently produce an anonymous stamp. `--anonymous` forces the
opposite.
Expand All @@ -58,8 +108,8 @@ about foresight.

| Code | Meaning |
| --- | --- |
| `0` | Success. For `verify`: valid, and the hash matched if one was given. |
| `1` | Verification failed, hash mismatch, or the input is not a token. |
| `0` | Success. For `verify`: valid, and the hash (and, for a lineage, the token id) matched if one was given. |
| `1` | Verification failed, hash or token id mismatch, or the input is not a token. For `stamp-revision`: the revision was already certified with different content, or a recovered genesis's lineage has moved on. |
| `2` | Usage or configuration error. |
| `3` | Network error, aggregator rejection, or timeout. |
| `130` | Interrupted. |
Expand Down
38 changes: 34 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { ICommandContext } from './commands/context.js';
import { runInspect } from './commands/inspect.js';
import { IKeygenFlags, runKeygen } from './commands/keygen.js';
import { runStamp } from './commands/stamp.js';
import { runStampRevision } from './commands/stampRevision.js';
import { IVerifyFlags, runVerify } from './commands/verify.js';
import { IStampFlags, loadEnvironment } from './config.js';
import { IStampFlags, IStampRevisionFlags, loadEnvironment } from './config.js';
import { describeError, EXIT_USAGE, toExitCode } from './errors.js';
import { warningLine } from './output.js';
import { VERSION } from './version.js';
Expand Down Expand Up @@ -77,12 +78,41 @@ program
process.exitCode = await runStamp(digest, flags, context());
});

program
.command('stamp-revision')
.description(
'certify a document revision, creating a lineage token or appending to an existing one; ' +
'name the next producer, or finalize',
)
.argument('[sha256-hex]', 'digest of the revision; alternatively use --file')
.option('--file <path>', 'hash this file locally instead of passing a digest')
.requiredOption('--token-file <path>', 'lineage token; created for an initial revision, otherwise appended to')
.requiredOption('--key-file <path>', 'secp256k1 private key (64 hex) that signs this revision')
.option('--recipient-key <hex>', "compressed secp256k1 public key (66 hex) of the next revision's producer")
.option('--recipient-key-file <path>', "file holding the next producer's public key; alternative to --recipient-key")
.option('--finalize', 'make this the final revision: seal it and burn the token, so no revision can follow')
.option('--quiet', 'do not echo the pending revision to stderr once its journal file is written')
.option(
'--force',
'for a new lineage, overwrite a file that appears at --token-file meanwhile, or write through a dangling symlink',
)
.option('--network <name>', 'mainnet or testnet2; or UNICITY_NETWORK (default mainnet)')
.option('--gateway <url>', 'override the gateway URL; or UNICITY_GATEWAY_URL')
.option('--api-key <key>', 'gateway API key; or UNICITY_API_KEY')
.option('--trust-base <path>', 'override the bundled trust base; or UNICITY_TRUST_BASE')
.option('--timeout <seconds>', 'wait for the inclusion proof; or UNICITY_TIMEOUT (default 60)')
.option('--allow-insecure', 'permit the API key over plain HTTP (local development only)')
.action(async (digest: string | undefined, flags: IStampRevisionFlags) => {
process.exitCode = await runStampRevision(digest, flags, context());
});

program
.command('verify')
.description('verify a timestamp token offline and print what it proves')
.description('verify a timestamp or document lineage token offline and print what it proves')
.argument('<token-file>', 'token file, or "-" for stdin; raw CBOR or hex text')
.option('--hash <sha256-hex>', 'assert the token is for this digest')
.option('--file <path>', 'assert the token is for this file, hashed locally')
.option('--hash <sha256-hex>', 'assert the token is for this digest (for a lineage: one of its revisions)')
Comment thread
ahtotruu marked this conversation as resolved.
Resolved
.option('--file <path>', 'assert the token is for this file, hashed locally (for a lineage: one of its revisions)')
.option('--token-id <hex>', 'assert the lineage is the one with this token id, as given to you by its issuer')
.option('--network <name>', "use this network's bundled trust base instead of the one matching the token")
.option('--trust-base <path>', 'use this trust base file; or UNICITY_TRUST_BASE')
.action(async (file: string, flags: IVerifyFlags) => {
Expand Down
Loading
Loading