diff --git a/.env.example b/.env.example index c0c861a..4c3985f 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # Copy to .env and fill in. .env is gitignored. # --- CLI runtime ------------------------------------------------------------- -# Gateway API key used by `unicity-timestamp stamp`. Get one at https://sphere.unicity.network/ +# Gateway API key used by `unicity-proof stamp`. Get one at https://sphere.unicity.network/ UNICITY_API_KEY=sk_your_gateway_key # mainnet | testnet2 UNICITY_NETWORK=mainnet diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml index c2e79cf..eaab067 100644 --- a/.github/workflows/npm.yml +++ b/.github/workflows/npm.yml @@ -12,10 +12,14 @@ name: Release # restriction rather than anything written in this file. # * The package exists on the registry and names this workflow as its trusted # publisher (npmjs.com > the package > Settings > Trusted Publisher; -# repository `unicitynetwork/timestamp-cli`, workflow `npm.yml`, environment +# repository `unicitynetwork/proof-cli`, workflow `npm.yml`, environment # `npm-publish`). npm will not accept a trusted publisher for a package that # has never been published, so the first release is published by hand and # every release after it runs from here. +# * That configuration permits direct publishing under "Allowed actions". +# Configurations created after 3 September 2026 allow only +# `npm stage publish` by default, and the publish step below runs +# `npm publish`, so a default configuration refuses it. on: workflow_dispatch: inputs: @@ -157,8 +161,8 @@ jobs: - name: Refuse a version that is already published run: | version='${{ steps.version.outputs.version }}' - if npm view "@unicitylabs/timestamp-cli@${version}" version >/dev/null 2>&1; then - echo "@unicitylabs/timestamp-cli@${version} is already on the registry." >&2 + if npm view "@unicitylabs/proof-cli@${version}" version >/dev/null 2>&1; then + echo "@unicitylabs/proof-cli@${version} is already on the registry." >&2 exit 1 fi @@ -192,5 +196,5 @@ jobs: fi gh release create "v${version}" \ --title "v${version}" \ - --notes "https://www.npmjs.com/package/@unicitylabs/timestamp-cli/v/${version}" \ + --notes "https://www.npmjs.com/package/@unicitylabs/proof-cli/v/${version}" \ --verify-tag $prerelease diff --git a/README.md b/README.md index 6a3d2e5..dde74f9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Unicity Timestamp CLI +# Unicity Proof CLI -Timestamping service on Unicity network. Tokens are standard Unicity tokens produced with the [state transition SDK](https://github.com/unicitynetwork/state-transition-sdk-js). +Proof-of-existence service on the Unicity network. Tokens are standard Unicity tokens produced with the [state transition SDK](https://github.com/unicitynetwork/state-transition-sdk-js). ## Requirements @@ -10,23 +10,23 @@ Timestamping service on Unicity network. Tokens are standard Unicity tokens prod ## Installation ```bash -npm install -g @unicitylabs/timestamp-cli -unicity-timestamp --help +npm install -g @unicitylabs/proof-cli +unicity-proof --help ``` Or run it without installing: ```bash -npx @unicitylabs/timestamp-cli --help +npx @unicitylabs/proof-cli --help ``` To work from a checkout instead: ```bash -git clone https://github.com/unicitynetwork/timestamp-cli.git -cd timestamp-cli +git clone https://github.com/unicitynetwork/proof-cli.git +cd proof-cli npm install # builds through the prepare script -npm link # optional: puts `unicity-timestamp` on your PATH +npm link # optional: puts `unicity-proof` on your PATH ``` ## Configuration @@ -59,12 +59,12 @@ as the table says. ### Stamp ```bash -unicity-timestamp stamp # hash supplied -unicity-timestamp stamp --file # hash computed locally -unicity-timestamp stamp --file document.pdf --out document.cbor -unicity-timestamp stamp --file document.pdf --network testnet2 -unicity-timestamp stamp --file document.pdf --timeout 120 -unicity-timestamp stamp --file document.pdf --json > stamp.json +unicity-proof stamp # hash supplied +unicity-proof stamp --file # hash computed locally +unicity-proof stamp --file document.pdf --out document.cbor +unicity-proof stamp --file document.pdf --network testnet2 +unicity-proof stamp --file document.pdf --timeout 120 +unicity-proof stamp --file document.pdf --json > stamp.json ``` A stamp prints a summary and writes the token to `--out`, by default `token_.cbor` in the current directory. The token file is the receipt; keep it with the document. @@ -96,8 +96,8 @@ that text recovers the stamp in full; there is no need to stamp again. By default a stamp proves only that the hash existed. To also prove that *you* stamped it, sign with a key: ```bash -unicity-timestamp keygen --out my.key # once; mode 0600, 64 hex characters -unicity-timestamp stamp --file document.pdf --key-file my.key +unicity-proof keygen --out my.key # once; mode 0600, 64 hex characters +unicity-proof stamp --file document.pdf --key-file my.key ``` `keygen --out -` prints the private key to stdout instead of writing a file, as @@ -115,10 +115,10 @@ The signer's compressed public key is printed on every `stamp` and `verify`, as ### Verify ```bash -unicity-timestamp verify document.cbor # is this a valid Unicity timestamp? -unicity-timestamp verify document.cbor --file document.pdf # ...and is it for this file? -unicity-timestamp verify document.cbor --hash 2cf24dba…9824 # ...or for this digest? -cat document.cbor | unicity-timestamp verify - # from stdin; binary or hex +unicity-proof verify document.cbor # is this a valid Unicity timestamp? +unicity-proof verify document.cbor --file document.pdf # ...and is it for this file? +unicity-proof verify document.cbor --hash 2cf24dba…9824 # ...or for this digest? +cat document.cbor | unicity-proof verify - # from stdin; binary or hex ``` ``` @@ -140,7 +140,7 @@ The `Trust base` line says which root of trust produced that verdict — `bundle ### Inspect ```bash -unicity-timestamp inspect document.cbor +unicity-proof inspect document.cbor ``` Prints the same fields as `verify` without checking anything, under an `UNVERIFIED` banner. Useful for looking at tokens from other networks or other token types. @@ -150,7 +150,7 @@ Prints the same fields as `verify` without checking anything, under an `UNVERIFI Every command accepts `--json` and prints one JSON object on stdout; everything else goes to stderr. Large integers are decimal strings. `referenceTimeIso` is null when the token carries a reference time no date can represent; `referenceTime` always holds the raw value. ```bash -unicity-timestamp verify document.cbor --file document.pdf --json | jq -r .referenceTimeIso +unicity-proof verify document.cbor --file document.pdf --json | jq -r .referenceTimeIso ``` | Exit code | Meaning | @@ -164,9 +164,9 @@ unicity-timestamp verify document.cbor --file document.pdf --json | jq -r .refer ### Testnet and custom gateways ```bash -unicity-timestamp stamp --file document.pdf --network testnet2 --api-key sk_ddc3cfcc001e4a28ac3fad7407f99590 -unicity-timestamp stamp --file document.pdf --gateway https://gateway.example --trust-base ./bft-trustbase.json -unicity-timestamp stamp --file document.pdf --gateway http://localhost:3000 --allow-insecure # local aggregator only +unicity-proof stamp --file document.pdf --network testnet2 --api-key sk_ddc3cfcc001e4a28ac3fad7407f99590 +unicity-proof stamp --file document.pdf --gateway https://gateway.example --trust-base ./bft-trustbase.json +unicity-proof stamp --file document.pdf --gateway http://localhost:3000 --allow-insecure # local aggregator only ``` The testnet2 key above is the shared public demo key published in the [sphere-sdk README](https://github.com/unicity-sphere/sphere-sdk/blob/main/README.md#api-key), where it is documented as public rather than secret; capacity is shared, so get your own key for sustained use. Trust bases for mainnet and testnet2 ship inside the package. The CLI never downloads a trust base at run time. diff --git a/docs/plans/2026-10-14-rename-to-proof-cli.md b/docs/plans/2026-10-14-rename-to-proof-cli.md index 213b39a..752d5ee 100644 --- a/docs/plans/2026-10-14-rename-to-proof-cli.md +++ b/docs/plans/2026-10-14-rename-to-proof-cli.md @@ -27,7 +27,7 @@ **Files:** - Modify: `package.json` (name, bin, description, keywords, repository, homepage, bugs) -- Modify: `package-lock.json` (name at the root and in the `""` package entry) +- Modify: `package-lock.json` (name at the root and in the `""` package entry, and the `bin` map inside that entry) - Modify: `src/lib/constants.ts:6-12` (the comment on `TIMESTAMP_TAG`) **Interfaces:** @@ -127,10 +127,27 @@ git commit -m "Rename the package to @unicitylabs/proof-cli" In `tests/e2e/CliOfflineTest.ts`, add to the existing `prints help and version` test, after the `-v, --version` assertion: ```ts -// The installed command name and the name the help prints have to agree, -// or the help tells the reader to run something not on their PATH. -expect(help.stdout).toContain('unicity-proof'); -expect(help.stdout).not.toContain('unicity-timestamp'); +// The installed command name and the name the help prints have to agree, or +// the help tells the reader to run something that is not on their PATH. The +// whole usage line is asserted rather than a substring, so a stale name cannot +// hide in it — and the old name is deliberately absent from this file, because +// Task 4 and Task 5 grep the tree for it. +expect(help.stdout.split('\n')[0]).toEqual('Usage: unicity-proof [options] [command]'); +``` + +The `--out` default is a separate string in a different help screen, so it gets +its own assertion. Add this test next to the one above: + +```ts +it( + 'names the default key file in the keygen help', + async () => { + const keygenHelp = await runCli(['keygen', '--help'], { cwd }); + expect(keygenHelp.code).toBe(0); + expect(keygenHelp.stdout).toContain('unicity-proof.key'); + }, + TIMEOUT, +); ``` - [ ] **Step 2: Write the failing test for the default key file** @@ -163,7 +180,7 @@ expect(sink.stderr()).toContain('`unicity-proof verify` accepts hex text'); - [ ] **Step 4: Run the three tests to verify they fail** Run: `npm run build && npx jest tests/e2e/CliOfflineTest.ts -t 'prints help and version'` -Expected: FAIL — `Expected substring: "unicity-proof"` +Expected: FAIL — equality mismatch: received `Usage: unicity-timestamp [options] [command]` Run: `npx jest tests/e2e/CliOfflineTest.ts -t 'names the default key file'` Expected: FAIL — received `["unicity-timestamp.key"]` @@ -272,9 +289,19 @@ Expected: the digest from Step 1. If the line numbers moved, the appendix was ed - [ ] **Step 5: Verify no stale brand references remain outside the appendix** -Run: `head -214 README.md | grep -n 'unicity-timestamp\|timestamp-cli'` +Run: `head -214 README.md | grep -nI 'unicity-timestamp\|timestamp-cli\|Timestamp CLI\|Unicity Timestamp'` Expected: no output. +The last two patterns matter: the H1 title reads `# Unicity Timestamp CLI`, +which is Title Case and space-separated, so Step 2's substitutions do not touch +it and a check using only their patterns cannot see it. Change the title to +`# Unicity Proof CLI` as part of Step 2. + +Do **not** broaden this to a case-insensitive search for `timestamp`. The README +uses the English word legitimately throughout — "round timestamp", "A timestamp +is an attestation", "classic timestamp authority" — and all of it stays. Only +the product name is being renamed. + - [ ] **Step 6: Commit** ```bash @@ -338,14 +365,17 @@ Run: `python3 -c "import yaml,sys; yaml.safe_load(open('.github/workflows/npm.ym Expected: `yaml ok` Run: `grep -rnI 'timestamp-cli\|unicity-timestamp' .github .env.example scripts tests` -Expected: no output. `-I` skips `tests/fixtures/*.cbor`, which carry the tag in -their burn reason by design; without it grep reports them as binary matches and -the check looks failed when it passed. +Expected: no output. Two things make that achievable: `-I` skips +`tests/fixtures/*.cbor`, which carry the tag in their burn reason by design and +would otherwise be reported as binary matches; and Task 2's assertions were +written without the old name in them, so no test file contains it. If this grep +returns a hit inside `tests/`, a test embedded the literal — fix the test +rather than loosening this check. - [ ] **Step 5: Run the suite and lint** Run: `npm run lint && CI= npm test` -Expected: PASS, same test count as before the rename plus the one new keygen test. +Expected: PASS, same test count as before the rename plus the two new keygen tests. - [ ] **Step 6: Commit** @@ -384,7 +414,7 @@ Expected: `OK` twice. These tokens were certified before the rename; this is the - [ ] **Step 3: Confirm the old name survives only where it must** -Run: `grep -rlnI 'unicity-timestamp' src tests README.md | sort` +Run: `grep -rlI 'unicity-timestamp\|Timestamp CLI\|Unicity Timestamp' src tests README.md | sort` Expected exactly these three files: ``` @@ -396,7 +426,8 @@ src/lib/constants.ts Any other file is a missed rename. `-I` is required: the two `tests/fixtures/*.cbor` files contain the tag in their burn reason — which is the whole point of keeping them — and `grep -l` reports binary matches rather -than skipping them, so without `-I` this check can never pass. +than skipping them, so without `-I` this check can never pass. `-l` also +suppresses line numbers, so `-n` is not used here. - [ ] **Step 4: Confirm the package would publish correctly** @@ -468,13 +499,39 @@ gh pr create --title "Rename the CLI to @unicitylabs/proof-cli" --body-file ../p --- -## Operator steps after merge - -These need registry or organisation credentials and are not part of the code change. They are migration steps 2 through 8 of the spec, in order: - -1. `npm version 0.2.0-rc1 --no-git-tag-version`, then `npm publish --access public --tag next`. Discard the local bump. **`--tag next` is required** — npm points `latest` at whatever it publishes, prerelease or not. -2. Configure the new package's trusted publisher: repository as currently named, workflow `npm.yml`, environment `npm-publish`. -3. Run the release workflow with `0.2.0` as the explicit version input. -4. `npm deprecate @unicitylabs/timestamp-cli "Renamed to @unicitylabs/proof-cli"`. -5. Optionally `npm dist-tag rm @unicitylabs/proof-cli next`. -6. Rename the repository on GitHub, then re-point the trusted publisher at the new repository name. +## Operator steps + +Most of these need registry or organisation credentials; none is part of the +code change. Step 2 is the merge of this branch. **The repository rename comes +first**, because this branch points `repository`, `homepage` and `bugs` at +`unicitynetwork/proof-cli`, and npm requires a package's `repository` to +match, case-sensitively, the repository it publishes from. Publishing from a +repository still named `timestamp-cli` with those URLs in the manifest fails. + +1. Rename the repository on GitHub to `proof-cli`. Organisation admin. Update + the remote in any working copy. +2. Merge this branch. +3. `npm version 0.2.0-rc1 --no-git-tag-version`, then + `npm publish --access public --tag next`. Discard the local bump. + **`--tag next` is required** — npm points `latest` at whatever it publishes, + prerelease or not. +4. Configure the new package's trusted publisher: repository + `unicitynetwork/proof-cli`, workflow `npm.yml`, environment `npm-publish`, + and under "Allowed actions" permit direct publishing with `npm publish`. + Configurations created after 3 September 2026 default to `npm stage publish` + only, and this workflow publishes directly. +5. Run the release workflow with `0.2.0` as the explicit version input. + **Within two days of step 4.** A new trusted-publisher configuration has to + complete its first successful publish inside that window; after it, the + configuration expires and can no longer be used or edited, and has to be + recreated. Do not configure the publisher until ready to release. +6. `npm deprecate @unicitylabs/timestamp-cli "Renamed to @unicitylabs/proof-cli"`. +7. Optionally `npm dist-tag rm @unicitylabs/proof-cli next`. +8. Optionally restrict token publishing on the new package — npm Settings, + Publishing access, "Require two-factor authentication and disallow tokens". + Configuring a trusted publisher does not do this on its own, and the + bootstrap token from step 3 keeps working until it is done. + +Step 4's binding is to the repository's immutable identity, not its name. npm +does not document what a later rename requires of it; under this ordering the +repository is not renamed again afterwards, so the question is moot. diff --git a/docs/specs/2026-10-14-rename-to-proof-cli.md b/docs/specs/2026-10-14-rename-to-proof-cli.md index e360e2c..a89a61d 100644 --- a/docs/specs/2026-10-14-rename-to-proof-cli.md +++ b/docs/specs/2026-10-14-rename-to-proof-cli.md @@ -84,7 +84,8 @@ Brand and user-visible surface: - `package.json`: `name`, `bin`, `description`, `keywords`, `repository`, `homepage`, `bugs` -- `package-lock.json`: the package name at the root and in the `""` package entry +- `package-lock.json`: the package name at the root and in the `""` package + entry, and the `bin` map inside that entry, which mirrors the manifest - `src/cli.ts`: `.name()`, `.description()` — the sentence `--help` prints — and the `--out` help text naming the default key file - `src/output.ts`: the recovery hint printed when a certified stamp cannot be @@ -109,61 +110,70 @@ frozen; `proof` means the product and is free to change. ## Migration -The package rename and the repository rename are separable. The package rename -needs no organisation admin and carries no redirect risk; the repository rename -needs both. The new package needs its own trusted publisher either way — only -its repository value differs — so neither rename avoids that step. - -### Package rename - -npm's trusted publishing cannot create a package name the publisher does not -already own, so one publish has to happen by hand. That publish is a -prerelease whose only purpose is to make the name exist, which keeps the real -0.2.0 on the audited path. - -1. Land the rename. The release workflow owns versions, so the rename commit - carries no bump and stays at 0.1.2. -2. Bootstrap the name by hand: `npm version 0.2.0-rc1 --no-git-tag-version`, +**The repository rename comes first.** npm requires a package's `repository` to +match, case-sensitively, the repository it publishes from, so a manifest +naming `unicitynetwork/proof-cli` cannot publish from a repository still named +`timestamp-cli`. The two renames remain separable in principle — a +package rename alone needs no organisation admin, and would keep the old +repository URLs in the manifest — but when both are being done, this is the +order that works. + +1. Rename the repository on GitHub to `proof-cli`. Requires organisation admin. + Update the remote in any working copy. +2. Land the rename: code, docs and workflow strings, reviewed as one change. + The version stays 0.1.2; the release workflow owns the bump. +3. Bootstrap the package name by hand: `npm version 0.2.0-rc1 --no-git-tag-version`, which regenerates `src/version.ts` through the `version` lifecycle script and keeps `VersionTest` green, then `npm publish --access public --tag next`. - Discard the local bump afterwards. + Discard the local bump afterwards. npm's trusted publishing cannot create a + package name the publisher does not already own, so this one publish cannot + come from CI. **`--tag next` is required.** npm points `latest` at whatever it publishes, prerelease or not, so without it a plain `npm install @unicitylabs/proof-cli` would hand everyone a release candidate. The workflow derives the same tag from the version itself; this publish is the one that does not go through it. -3. Configure the new package's trusted publisher: the repository as it is named - at the time, workflow `npm.yml`, environment `npm-publish`. -4. Run the release workflow with `0.2.0` as the explicit version input. It - bumps, builds, tests, publishes to `latest`, pushes the bump with its tag and - creates the release. -5. `npm deprecate @unicitylabs/timestamp-cli "Renamed to @unicitylabs/proof-cli"`. +4. Configure the new package's trusted publisher: repository + `unicitynetwork/proof-cli`, workflow `npm.yml`, environment `npm-publish`, + and under "Allowed actions" **permit direct publishing with `npm publish`**. + Configurations created after 3 September 2026 allow only `npm stage publish` + by default, and this workflow publishes directly, so a configuration left on + the default refuses the release — which would also spend the two-day window + in step 5 on a publish that cannot succeed. +5. Run the release workflow with `0.2.0` as the explicit version input, **within + two days of step 4**. A new trusted-publisher configuration must complete its + first successful publish inside that window; afterwards it expires and can no + longer be used or edited, and has to be recreated. Do not configure the + publisher until the release is ready to go out. +6. `npm deprecate @unicitylabs/timestamp-cli "Renamed to @unicitylabs/proof-cli"`. The old versions stay installable. Unpublishing would break existing lockfiles. -6. Optionally `npm dist-tag rm @unicitylabs/proof-cli next` once 0.2.0 is on +7. Optionally `npm dist-tag rm @unicitylabs/proof-cli next` once 0.2.0 is on `latest`. +8. Optionally restrict token publishing on the new package — npm Settings, + Publishing access, "Require two-factor authentication and disallow tokens". + Configuring a trusted publisher does not do this by itself, so the bootstrap + credential from step 3 keeps working until it is done. -Publishing 0.2.0 from the workflow rather than by hand is what earns it a -provenance attestation: 0.1.2, released through the workflow, carries an SLSA -predicate, and 0.1.0, published by hand to bootstrap the current name, carries -none. Under this order the unattested artifact is a release candidate on a tag -nothing resolves by default. +Step 4's configuration binds to the repository's immutable identity, not its +name, once step 5 succeeds. npm does not document what a later rename requires +of that binding; under this ordering the repository is not renamed again +afterwards, so the question is moot. -### Repository rename +Publishing 0.2.0 from the workflow rather than by hand is what earns it a +provenance attestation: 0.1.1 and 0.1.2, released through the workflow, carry an +SLSA predicate, and 0.1.0, published by hand to bootstrap the current name, +carries none. Under this order the unattested artifact is a release candidate on +a tag nothing resolves by default. -7. Rename the repository on GitHub. Requires organisation admin. Update the - remote in any working copy. -8. Re-point the new package's trusted publisher at the new repository name, if - step 3 ran before the rename. +Steps 1, 3, 4, 6, 7 and 8 need registry or organisation credentials. GitHub redirects the old paths only until a repository with the old name is created in the organisation, so the redirect is not a permanent guarantee. Every published 0.1.x tarball carries `repository`, `homepage` and `bugs` URLs naming the old repository for as long as anyone installs those versions. -Steps 2, 3, 5, 6, 7 and 8 need registry or organisation credentials. - ## Verification The regression that matters is that a token certified before the rename still @@ -204,12 +214,15 @@ from the user's side. ## Risks -| Risk | Mitigation | -| -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| The frozen tag is renamed later for consistency | A sentence at the constant, the frozen-section list above, and `ConstantsTest` | -| The README appendix is caught by a file-wide replace | Both sections named as frozen above; review the README diff line by line | -| `latest` ends up on a release candidate | The bootstrap publish passes `--tag next`; 0.2.0 reaches `latest` only through the workflow, which derives the tag from the version | -| Releases break after the repository rename | Step 8 | -| Users on the old package never learn of the move | Step 5's deprecation message appears on install | -| 0.2.0 ships without a provenance attestation | Only the bootstrap prerelease is published by hand; 0.2.0 comes from the workflow | -| The old repository name is recreated, breaking redirects | Do not create a repository named `timestamp-cli` in the organisation | +| Risk | Mitigation | +| --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | +| The frozen tag is renamed later for consistency | A sentence at the constant, the frozen-section list above, and `ConstantsTest` | +| The README appendix is caught by a file-wide replace | Both sections named as frozen above; review the README diff line by line | +| `latest` ends up on a release candidate | The bootstrap publish passes `--tag next`; 0.2.0 reaches `latest` only through the workflow, which derives the tag from the version | +| A provenance publish is attempted from the old repository name | The repository rename is step 1, before any publish | +| Users on the old package never learn of the move | Step 6's deprecation message appears on install | +| 0.2.0 ships without a provenance attestation | Only the bootstrap prerelease is published by hand; 0.2.0 comes from the workflow | +| The old repository name is recreated, breaking redirects | Do not create a repository named `timestamp-cli` in the organisation | +| The trusted publisher allows only staged publishing | Step 4 permits direct `npm publish`; the default for configurations created after 3 September 2026 does not, and the workflow publishes directly | +| The trusted-publisher configuration expires unused | Step 4 happens only when the release is ready, and step 5 follows within two days | +| The README's install command 404s between the merge and the bootstrap publish, because the package does not exist yet | Run the bootstrap publish immediately after merging | diff --git a/package-lock.json b/package-lock.json index cbd7607..0272bd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@unicitylabs/timestamp-cli", + "name": "@unicitylabs/proof-cli", "version": "0.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@unicitylabs/timestamp-cli", + "name": "@unicitylabs/proof-cli", "version": "0.1.2", "license": "MIT", "dependencies": { @@ -13,7 +13,7 @@ "commander": "15.0.0" }, "bin": { - "unicity-timestamp": "lib/cli.js" + "unicity-proof": "lib/cli.js" }, "devDependencies": { "@babel/core": "8.0.1", diff --git a/package.json b/package.json index a3dfbf9..6191b9a 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { - "name": "@unicitylabs/timestamp-cli", + "name": "@unicitylabs/proof-cli", "version": "0.1.2", - "description": "Timestamp a SHA-256 hash on the Unicity Network and verify the resulting token offline", + "description": "Create and verify Unicity proofs: certify a SHA-256 hash on the Unicity Network and verify the token offline", "type": "module", "bin": { - "unicity-timestamp": "lib/cli.js" + "unicity-proof": "lib/cli.js" }, "exports": { ".": { @@ -33,22 +33,24 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/unicitynetwork/timestamp-cli.git" + "url": "git+https://github.com/unicitynetwork/proof-cli.git" }, "keywords": [ "unicity", - "timestamp", + "proof", + "attestation", "timestamping", "proof-of-existence", + "agent", "cli" ], "license": "MIT", "publishConfig": { "access": "public" }, - "homepage": "https://github.com/unicitynetwork/timestamp-cli#readme", + "homepage": "https://github.com/unicitynetwork/proof-cli#readme", "bugs": { - "url": "https://github.com/unicitynetwork/timestamp-cli/issues" + "url": "https://github.com/unicitynetwork/proof-cli/issues" }, "engines": { "node": ">=22" diff --git a/scripts/update-trust-bases.mjs b/scripts/update-trust-bases.mjs index d87c93f..55b320c 100644 --- a/scripts/update-trust-bases.mjs +++ b/scripts/update-trust-bases.mjs @@ -14,7 +14,7 @@ const NETWORKS = [ const targetDirectory = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'src', 'trust-bases'); async function fetchText(url) { - const response = await fetch(url, { headers: { 'User-Agent': 'unicity-timestamp-cli' } }); + const response = await fetch(url, { headers: { 'User-Agent': 'unicity-proof-cli' } }); if (!response.ok) { throw new Error(`GET ${url} failed with HTTP ${response.status}`); } diff --git a/src/cli.ts b/src/cli.ts index 36afa75..4937011 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -23,8 +23,8 @@ process.once('SIGINT', () => { const program = new Command(); program - .name('unicity-timestamp') - .description('Timestamp a SHA-256 hash on the Unicity Network and verify the resulting token offline.') + .name('unicity-proof') + .description('Certify a SHA-256 hash on the Unicity Network and verify the resulting proof offline.') // Commander defaults the version option to `-V`, keeping `-v` free for a // `--verbose` this CLI does not have. `node -v` and `npm -v` are what people // reach for, so the short flag is lowercase here. Commander refuses two short @@ -100,7 +100,7 @@ program program .command('keygen') .description('generate a secp256k1 private key for signed stamps') - .option('--out ', 'key file; default unicity-timestamp.key; "-" prints the key to stdout') + .option('--out ', 'key file; default unicity-proof.key; "-" prints the key to stdout') .option('--force', 'overwrite the key file') .action(async (flags: IKeygenFlags) => { process.exitCode = await runKeygen(flags, context()); diff --git a/src/commands/keygen.ts b/src/commands/keygen.ts index 2283b75..1008027 100644 --- a/src/commands/keygen.ts +++ b/src/commands/keygen.ts @@ -14,7 +14,7 @@ export interface IKeygenFlags { readonly out?: string; } -const DEFAULT_KEY_FILE = 'unicity-timestamp.key'; +const DEFAULT_KEY_FILE = 'unicity-proof.key'; /** * Write a private key to a path that already holds a file. diff --git a/src/lib/constants.ts b/src/lib/constants.ts index a5f103f..07f01f6 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -8,6 +8,11 @@ import { HexConverter } from '@unicitylabs/state-transition-sdk/lib/util/HexConv * reason is its UTF-8 bytes, and it is the domain tag of the payload signature. * It carries no version on purpose: the payload has its own version field, so * this identifier stays stable while the payload format evolves. + * + * It is also not the product name, and must never be changed to match it. + * Renaming it gives every later stamp a different token type, recipient and + * signature domain, and nothing already certified would verify. The CLI is + * `unicity-proof`; the format is `unicity-timestamp` and stays so. */ export const TIMESTAMP_TAG = 'unicity-timestamp'; diff --git a/src/output.ts b/src/output.ts index 97c371b..0cb72c3 100644 --- a/src/output.ts +++ b/src/output.ts @@ -145,7 +145,7 @@ export function warningLine(message: string): string { export function recoveryLines(bytes: Uint8Array): string { return [ 'error: the stamp was certified but could not be written.', - 'Save the token below; `unicity-timestamp verify` accepts hex text.', + 'Save the token below; `unicity-proof verify` accepts hex text.', HexConverter.encode(bytes), '', ].join('\n'); diff --git a/tests/e2e/CliNetworkTest.ts b/tests/e2e/CliNetworkTest.ts index f047593..df90869 100644 --- a/tests/e2e/CliNetworkTest.ts +++ b/tests/e2e/CliNetworkTest.ts @@ -14,7 +14,7 @@ const TIMEOUT = 180_000; const describeNetwork = TEST_API_KEY ? describe : describe.skip; const itWritesFixtures = process.env.UNICITY_E2E_WRITE_FIXTURES === '1' ? it : it.skip; -describeNetwork(`unicity-timestamp against ${TEST_NETWORK}`, () => { +describeNetwork(`unicity-proof against ${TEST_NETWORK}`, () => { let cwd: string; const env = { UNICITY_API_KEY: TEST_API_KEY ?? '', UNICITY_NETWORK: TEST_NETWORK }; const digest = HexConverter.encode(crypto.getRandomValues(new Uint8Array(32))); @@ -23,7 +23,7 @@ describeNetwork(`unicity-timestamp against ${TEST_NETWORK}`, () => { let signedToken: string; beforeAll(async () => { - cwd = await tempDir('timestamp-cli-net-'); + cwd = await tempDir('proof-cli-net-'); anonymousToken = path.join(cwd, 'anonymous.cbor'); signedToken = path.join(cwd, 'signed.cbor'); }); diff --git a/tests/e2e/CliOfflineTest.ts b/tests/e2e/CliOfflineTest.ts index aab1599..0cb7818 100644 --- a/tests/e2e/CliOfflineTest.ts +++ b/tests/e2e/CliOfflineTest.ts @@ -7,11 +7,11 @@ import { tempDir, TEST_DIGEST_HEX } from '../support/fixtures.js'; const TIMEOUT = 30_000; const INCLUSION_PROOF_BYTE_OFFSET = 700; -describe('unicity-timestamp (offline)', () => { +describe('unicity-proof (offline)', () => { let cwd: string; beforeAll(async () => { - cwd = await tempDir('timestamp-cli-e2e-'); + cwd = await tempDir('proof-cli-e2e-'); }); it( @@ -30,7 +30,17 @@ describe('unicity-timestamp (offline)', () => { // Read from the manifest rather than written out, so a release bump does // not have to remember to come back and edit this line. - const manifest = JSON.parse(await readFile(path.resolve('package.json'), 'utf8')) as { version: string }; + const manifest = JSON.parse(await readFile(path.resolve('package.json'), 'utf8')) as { + bin: Record; + version: string; + }; + + // The installed command name and the name the help prints have to agree, or + // the help tells the reader to run something that is not on their PATH, so + // the name is taken from the manifest that installs it rather than written + // out here. The whole usage line is asserted, so a stale name cannot hide. + expect(help.stdout.split('\n')[0]).toEqual(`Usage: ${Object.keys(manifest.bin)[0]} [options] [command]`); + expect(version.code).toBe(0); expect(version.stdout.trim()).toEqual(manifest.version); expect(short.code).toBe(0); @@ -45,6 +55,27 @@ describe('unicity-timestamp (offline)', () => { TIMEOUT, ); + it( + 'names the default key file in the keygen help', + async () => { + const keygenHelp = await runCli(['keygen', '--help'], { cwd }); + expect(keygenHelp.code).toBe(0); + expect(keygenHelp.stdout).toContain('unicity-proof.key'); + }, + TIMEOUT, + ); + + it( + 'names the default key file after the command', + async () => { + const directory = await tempDir('proof-cli-default-key-'); + const result = await runCli(['keygen'], { cwd: directory }); + expect(result.code).toBe(0); + expect(await readdir(directory)).toEqual(['unicity-proof.key']); + }, + TIMEOUT, + ); + it( 'exits 2 on usage errors before touching the network', async () => { @@ -79,7 +110,7 @@ describe('unicity-timestamp (offline)', () => { async () => { const envFile = path.join(cwd, 'custom.env'); await writeFile(envFile, 'UNICITY_NETWORK=devnet\n'); - const dotenvDir = await tempDir('timestamp-cli-dotenv-'); + const dotenvDir = await tempDir('proof-cli-dotenv-'); await writeFile(path.join(dotenvDir, '.env'), 'UNICITY_NETWORK=devnet\n'); const args = [ 'stamp', @@ -201,7 +232,7 @@ describe('unicity-timestamp (offline)', () => { async () => { // A token plus a .env naming the trust base that validates it would // otherwise be a complete forgery kit, and the verdict would not say so. - const directory = await tempDir('timestamp-cli-dotenv-'); + const directory = await tempDir('proof-cli-dotenv-'); const mainnetTrustBase = path.resolve('src/trust-bases/bft-trustbase.mainnet.json'); const fixture = path.resolve('tests/fixtures/testnet2-anonymous.cbor'); await writeFile(path.join(directory, '.env'), `UNICITY_TRUST_BASE=${mainnetTrustBase}\n`); diff --git a/tests/support/fixtures.ts b/tests/support/fixtures.ts index d6eb8b6..192a792 100644 --- a/tests/support/fixtures.ts +++ b/tests/support/fixtures.ts @@ -19,7 +19,7 @@ export const TEST_PUBLIC_KEY_HEX = '031b84c5567b126440995d3ed5aaba0565d71e183460 const handedOut: string[] = []; /** Fresh temporary directory under the OS temp root, removed when the file finishes. */ -export async function tempDir(prefix = 'timestamp-cli-'): Promise { +export async function tempDir(prefix = 'proof-cli-'): Promise { const directory = await mkdtemp(path.join(tmpdir(), prefix)); handedOut.push(directory); return directory; diff --git a/tests/unit/ConfigTest.ts b/tests/unit/ConfigTest.ts index 76071e9..7881638 100644 --- a/tests/unit/ConfigTest.ts +++ b/tests/unit/ConfigTest.ts @@ -206,7 +206,7 @@ describe('resolveStampConfig', () => { let directory: string; beforeEach(async () => { - directory = await tempDir('timestamp-cli-out-'); + directory = await tempDir('proof-cli-out-'); }); afterEach(async () => { diff --git a/tests/unit/KeygenTest.ts b/tests/unit/KeygenTest.ts index ca929e4..39e70f5 100644 --- a/tests/unit/KeygenTest.ts +++ b/tests/unit/KeygenTest.ts @@ -13,7 +13,7 @@ describe('runKeygen under a umask that masks owner bits', () => { let previousUmask: number; beforeEach(async () => { - directory = await tempDir('timestamp-cli-umask-'); + directory = await tempDir('proof-cli-umask-'); previousUmask = process.umask(0o477); }); @@ -41,7 +41,7 @@ describe('runKeygen when the staged write cannot complete', () => { let directory: string; beforeEach(async () => { - directory = await tempDir('timestamp-cli-keygen-fail-'); + directory = await tempDir('proof-cli-keygen-fail-'); }); afterEach(async () => { diff --git a/tests/unit/StampWriteTest.ts b/tests/unit/StampWriteTest.ts index 17fcc8d..2b976bb 100644 --- a/tests/unit/StampWriteTest.ts +++ b/tests/unit/StampWriteTest.ts @@ -15,7 +15,7 @@ describe('writeCertifiedToken', () => { let directory: string; beforeEach(async () => { - directory = await tempDir('timestamp-cli-write-'); + directory = await tempDir('proof-cli-write-'); }); it('writes the token and nothing else', async () => { @@ -38,6 +38,9 @@ describe('writeCertifiedToken', () => { // from stderr, and no partial file is left lying around. expect(await readFile(out, 'utf8')).toEqual('existing'); expect(sink.stderr()).toContain('could not be written'); + // The hint is the only instruction a user gets for recovering a stamp they + // have already paid for, so it has to name a command that exists. + expect(sink.stderr()).toContain('`unicity-proof verify` accepts hex text'); expect(sink.stderr()).toContain(HexConverter.encode(TOKEN)); expect(await readdir(directory)).toEqual(['token.cbor']); }); diff --git a/tests/unit/VerifyTest.ts b/tests/unit/VerifyTest.ts index fb1297d..937ddea 100644 --- a/tests/unit/VerifyTest.ts +++ b/tests/unit/VerifyTest.ts @@ -21,7 +21,7 @@ describe('runVerify on a token whose network has no bundled pin', () => { pollIntervalMs: 10, timeoutMs: 2_000, }); - file = path.join(await tempDir('timestamp-cli-verify-'), 'token.cbor'); + file = path.join(await tempDir('proof-cli-verify-'), 'token.cbor'); await writeFile(file, token.toCBOR()); });