From df32ce465a54923a3347f7858c51a6c2fa8d7d8c Mon Sep 17 00:00:00 2001 From: Monserrat Mendoza <210256392+M0nsxx@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:51:27 -0600 Subject: [PATCH] feat(cli): nirium anchor - anchor a hash or small record to IPFS Adds `nirium anchor --file|--hash|--record` against the Audit Trail node's POST /api/audit/log. --file computes sha-256 locally and sends only the hash, never the file content. --record mirrors the server's 8KB limit client-side. No --network flag: the agent box decides its own network, and the server already rejects a client-supplied one. 17 new tests against a local HTTP server standing in for the agent (no real network, no real IPFS pin), full suite 76/76. Closes #133 Co-Authored-By: Claude Sonnet 5 --- packages/cli/CHANGELOG.md | 4 + packages/cli/README.md | 40 ++++++ packages/cli/bin/nirium.js | 140 ++++++++++++++++++++ packages/cli/package.json | 2 +- packages/cli/test/anchor.test.js | 215 +++++++++++++++++++++++++++++++ 5 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 packages/cli/test/anchor.test.js diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 3b07e19..e1dfe84 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to the `nirium-cli` package are documented here. ## Unreleased +### Added + +- `nirium anchor` ([#133](https://github.com/nirium-protocol/nirium/issues/133)): anchors a sha-256 hash (`--hash`), a file's sha-256 (`--file`, the file itself is never uploaded), or a small JSON record (`--record`, max 8KB, enforced client-side) to IPFS via an Audit Trail node's `POST /api/audit/log`. Optional `--tx`/`--tag`; no `--network` flag by design - the agent box decides its own network. Prints the CID, content hash, gateway URL, and a `nirium verify` suggestion. + ## 3.0.1 - 2026-10-24 ### Fixed diff --git a/packages/cli/README.md b/packages/cli/README.md index 0db7131..58aa02a 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -202,6 +202,46 @@ Each line is pass or fail: `--json` prints the same report (`ok`, `seller`, `network`, `checks`) for CI. +## Anchor a record + +```bash +nirium anchor --file evidence.json +nirium anchor --hash <64-hex-sha256> +nirium anchor --record '{"order":"A-12"}' +``` + +Anchors a sha-256 hash (or a small JSON object, up to 8KB) to IPFS via an +Audit Trail node's `POST /api/audit/log`, and prints back the CID. + +- `--file ` computes the sha-256 of the file locally and sends only + the hash - the file's contents are never uploaded. IPFS cannot delete + anything once pinned, so hashing locally means raw evidence never + leaves your machine. +- `--hash ` sends a sha-256 you already have (64 hex chars, optional + `sha-256:` prefix). +- `--record ` anchors a small JSON object verbatim (max 8KB, + enforced here before the request, not just by the server). Don't put + personal data in it - an anchored record can never be deleted. + +Exactly one of the three is required. `--tx ` and `--tag