# Rightshold Anchor client kit

Keep a small business's books in its own system and still be able to show, years later, that the history is
unbroken and unchanged: when it applies for a loan, sells the business or takes on a partner.

The kit runs on the business's own machine (or in the system its bookkeeper or developer built for it). It keeps
every record in a local journal, chains the records together under a secret salt, and once per period sends
Rightshold one thing: a signed fingerprint (a Merkle root) of that period's records. Rightshold countersigns it,
keeps it in a ledger the business does not control, and folds each day's fingerprints into one daily root that is
timestamped in Bitcoin. Later the owner chooses single records to show to a lender or buyer, who can check them
with a file anyone can run, without trusting Rightshold.

Two files, plain Node 22, no dependencies:

- `anchor-kit.mjs`: the kit (library and command line).
- `check-anchor-bundle.mjs`: the offline checker for the person on the other side of the table.

## What stays on the business's machine

| Stays on the machine | Goes to Rightshold |
|---|---|
| Every record (amounts, dates, references, file hashes) | One root per period, its record count and period dates |
| The secret salt and the stream's signing key | The stream's public key, once, at registration |
| The journal | Only the disclosures the owner chooses to send |

The business owns the Rightshold account, the keys and the data. The account key is read from
`RIGHTSHOLD_API_KEY` and is stored nowhere by the kit. It goes with every request: Rightshold shows a stream's
history in full (its id, the client's signatures, the full receipts) only to the account that registered it, and
`init`, `seal`, `status`, `export` and `disclose --room` all read that history as its owner.

## The five commands

```sh
node anchor-kit.mjs init --stream books-main --name "Books"
node anchor-kit.mjs add entry --json '{"entry_id":"E-1001","type":"invoice_issued","date":"2026-01-31","amount_cents":125000,"currency":"USD","category":"revenue","invoice_number":"1001"}'
node anchor-kit.mjs seal
node anchor-kit.mjs disclose --seq 2 --out for-the-bank.json
node anchor-kit.mjs status
```

and, for the person who will check the history:

```sh
node anchor-kit.mjs export --seq 1,2 --out bundle.json
```

1. **init** creates the key file (`anchor-key.json`, readable only by its owner) holding the stream's Ed25519
   signing key and secret salt, registers the stream with Rightshold, and pins Rightshold's receipt key in the
   journal. Compare the printed key fingerprint with `spki_sha256` on `/.well-known/rightshold-keys.json`.
2. **add** appends one record to the journal (`anchor-journal.json`). Five kinds, with fixed fields so that two
   systems produce the same bytes for the same record: `document` (a file's SHA-256, a label and a kind such as
   invoice, receipt, bank statement, payroll report, tax filing, contract), `entry` (one line of the books, in
   whole cents), `bank_line` (a line from the bank's or payment processor's own export, as received),
   `period_statement` (the figures for a period, every figure optional) and `correction`. A mistake is never
   edited: a correction is a new record that names the record it corrects, says why, and carries the corrected
   content. `add document --file invoice.pdf --label "Invoice 1001" --kind invoice` hashes the file for you; the
   file itself is not stored or sent. `import --entries entries.csv --bank-lines bank.csv` loads a month at once,
   all or nothing.
3. **seal** closes the period: it builds the period's root, chains it to the previous one, signs it, sends it and
   keeps Rightshold's signed receipt. It refuses to seal out of order (an older copy of the journal, or a journal
   that does not match what Rightshold holds). Running it twice does nothing the second time. If the answer is
   lost on the way back, running it again finds or re-sends the same root, so the history never splits.
4. **disclose** writes the proof for chosen records, in the form `POST /v1/anchors/verify-disclosure` accepts.
   `--verify` asks Rightshold to confirm each one; `--room <room id>` shares them into a private checking room
   (the `arm_…` id you got when you opened the room, not the link you send the counterparty), 50 per request,
   linking each correction to the record it corrects, skipping records already there, and saying in plain words
   which records the room refused and why. Each disclosure reveals that record, the salt of its period and
   hashes, nothing about any other record.
5. **status** shows the periods, whether Rightshold holds exactly the journal's chain, the last receipt, and for
   each day whether its Bitcoin timestamp is confirmed yet.

The record fields, file formats and test vectors are in the anchor/1 specification (sections 11 and 12, and 13 for
checking rooms), published at `/business-records/spec` (as text: `/business-records/spec.md`). It is the whole
protocol, so software other than this kit can record into the same streams and be checked the same way.

## Back up the key file and the journal

The key file is the only copy of the stream's signing key and salt.

- **Lose every copy and the history can no longer be extended or disclosed.** Nobody, Rightshold included, can
  recover it.
- **Anyone holding a copy can add records in the business's name.** Keep it as carefully as a bank login.

Copy `anchor-key.json` now to two places the business controls that are not this machine: an encrypted drive
kept somewhere else, and a password manager's secure file store. The journal holds the records themselves, which
Rightshold never receives: back it up after every seal, the same way. If a journal is restored from an older
backup, `seal` refuses to go on until the newest one is back.

## How a lender or buyer checks a bundle

The owner runs `export` and hands over `bundle.json` with the documents in question, or opens a private checking
room, whose page offers the same kind of file for download (`rightshold-room-bundle.json`). Two commands, in this
order, need no account, no network and nothing installed but Node:

```sh
# 1. check the bundle: the records, the chain of periods, Rightshold's receipts and the Bitcoin timestamps
node check-anchor-bundle.mjs bundle.json invoice-1001.pdf --issuer-key rightshold-receipt-key.pem
# 2. then run the forensic checks on the same records (forensic-check.cjs, with forensic-checks.cjs beside it)
node forensic-check.cjs bundle.json
```

The second command runs the published forensic checks (`/forensic-checks`) on the bundle's records and sealing facts:
each test with its method, result and the numbers behind it, and what the results do not show. On a room's bundle it
also checks Rightshold's signature on the report the room showed you and that it gets the same report, byte for byte.
Download `forensic-check.cjs` and `forensic-checks.cjs` from `/cli/` and compare them with
`/cli/forensic-checks.sha256` first. Run the first command first: the forensic checks take the records and their
sealing dates as the bundle gives them, and only the first command shows those are what was sealed.

Get Rightshold's receipt key yourself, not from the bundle: `GET /v1/anchor-service-info` (its
`receipt_public_key_pem`) or `/.well-known/rightshold-keys.json` (pass it with `--trusted-keys`). The checker
then shows, with no network access:

- each disclosed record is exactly what was sealed, in the period it says, and when Rightshold countersigned it;
- the periods form one unbroken chain from the first;
- each period is in its day's root, and the day's OpenTimestamps proof leads to a Bitcoin block;
- which disclosed record each file you name is, or that it is none of them.

It prints the Bitcoin block height and Merkle root to compare with any block explorer or your own Bitcoin node:
that last step needs the Bitcoin chain and is yours. It also says what it did not check, and the main one is
this: the history shows the records were not changed after they were sealed and when they were sealed, not that
the business events happened as recorded. Exit code 0 means every check passed; `--json` gives the full report.

Pin the checker before running it. Its SHA-256 is published at `/cli/check-anchor-bundle.sha256`, on
`/v1/transparency/build` (`anchor_checker_sha256`) and in `SHA256SUMS` beside this file; all must agree with
`sha256sum check-anchor-bundle.mjs`. The download itself is `/cli/check-anchor-bundle.mjs`.
