Skip to content

feat(cli): keep your own copy of a receipt (anchor --save, cid) - #429

Merged
M0nsxx merged 1 commit into
mainfrom
feat/cli-keep-receipt
Nov 21, 2026
Merged

M0nsxx merged 1 commit into
mainfrom
feat/cli-keep-receipt

Conversation

@Eras256

@Eras256 Eras256 commented Nov 21, 2026

Copy link
Copy Markdown
Member

A receipt lives on IPFS only while someone pins it, and Nirium can't promise to pin forever. The CID is the hash of the document, so any byte-identical copy brings it back with the same CID. This PR makes keeping that copy one flag. It's the client side of core-private#232, which adds a second pinned copy on Filebase and returns the exact document from POST /api/audit/log.

CLI

  • nirium anchor --save <file> writes the exact anchored document, byte for byte, and only after checking that those bytes give back the anchored CID. It uses the document the node returns; on nodes that don't return it yet, it fetches the same bytes from the gateway. If the copy doesn't match, nothing is written and the command exits 1 (the anchor itself still succeeded).
  • nirium cid <file> [--expect <cid>] recomputes a file's CIDv0 locally, with no IPFS node and no new dependency. A receipt is a single dag-pb/UnixFS block, so its CID is base58btc(0x12 0x20 || sha256(node)), the same as ipfs add with default settings. I checked it against three real mainnet receipts (QmSSZdtt…, QmS5q2Nv…, QmVWZM1i…).

SDK: AuditAnchor.document? typed (optional, so older nodes are fine).

Docs: CLI README "Keep your own copy" and a "If IPFS Loses a Receipt" section in docs/verify-audit-cid.md: save, check with nirium cid, re-add with ipfs add --cid-version=0, and don't reformat the file.

Tests: 6 new in test/keep-receipt.test.js, with two real mainnet receipts as fixtures: CIDs recomputed, mismatch exits 1, one changed byte fails, --save from the response, --save from the gateway fallback, and a mismatched copy refused. Locally: verify and keep suites 60/60, anchor 17/17, SDK tsc clean.

🤖 Generated with Claude Code

A receipt lives on IPFS only while someone pins it. The CID is the hash
of the document, so any byte-identical copy brings it back with the same
CID. This makes keeping that copy one flag:

- `nirium anchor --save <file>` writes the exact anchored document, byte
  for byte, only after checking those bytes give back the anchored CID.
  It uses the `document` the node returns (core-private#232) and falls
  back to the gateway on nodes that don't return it yet.
- `nirium cid <file> [--expect <cid>]` recomputes a file's CIDv0 locally,
  no IPFS node or library: a receipt is one dag-pb/UnixFS block, so the
  CID is base58btc(0x12 0x20 || sha256(node)). Checked against three real
  mainnet receipts (QmSSZdtt, QmS5q2Nv, QmVWZM1i).
- SDK: `AuditAnchor.document` (optional) typed.
- CLI README and the verify guide explain how to re-add a lost receipt.

Tests: 6 new (real receipts as fixtures; one changed byte fails; --save
from the response, from the gateway, and refusing a mismatched copy).
CLI verify/keep suites 60/60, anchor 17/17, SDK tsc clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Eras256
Eras256 requested a review from M0nsxx as a code owner November 21, 2026 08:40

@M0nsxx M0nsxx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review (Claude)

Read the diff. anchor --save writes the exact anchored document only after it recomputes to the anchored CID (from the response, or the gateway on older nodes); new cid command recomputes CIDv0 locally with no dependency, checked against three real mainnet receipts. SDK types the optional document; README and verify guide explain re-adding a lost receipt. 6 new tests, verify and anchor suites pass. LGTM.

@M0nsxx
M0nsxx merged commit 8d2516f into main Nov 21, 2026
23 checks passed
@M0nsxx
M0nsxx deleted the feat/cli-keep-receipt branch November 21, 2026 08:41
M0nsxx pushed a commit that referenced this pull request Nov 21, 2026
Version bump only, for what merged since the last release:
- nirium-cli 3.2.7: anchor --save and nirium cid (#429).
- nirium-mcp 0.6.10: env fallbacks, readable error when the signer
  can't start, exported createNiriumMcpServer, tool test suite (#388).
  #388 had no changelog entry; written here from the diff.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
M0nsxx pushed a commit that referenced this pull request Nov 21, 2026
…PI 0.12.8 (#431)

Same local CIDv0 check the CLI got in #429, for SDK users: recompute a
kept receipt's CID with no IPFS node and no new dependency.

- TypeScript: export receiptCid(bytes | string | document object).
- Python: nirium.receipt_cid(bytes | str | dict); a dict is serialized as
  compact JSON with UTF-8 kept, which is what the node pinned.
- READMEs: "Keep your own copy" next to the Audit Trail section.
- 6 tests each, with two real mainnet receipts as fixtures. Cross-checked
  CLI, TS, Python and ipfs-only-hash on ASCII and non-ASCII input: same CID.
- Versions: nirium 0.19.6 -> 0.19.7 (npm), nirium 0.12.7 -> 0.12.8 (PyPI:
  pyproject, setup.py, __version__), changelogs.

SDK: tsc clean, jest 108/108. Python: 62 passed (langchain test needs the
test extras, as in CI).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants