# Verifying a record

When we post a letter we write a record of it, sign it, and chain it to the previous record of the same account. Anyone holding the record can check it is ours and unchanged, with our public key and no account.

A record is proof of posting, not of delivery: we post letters, we do not see them arrive.

## Where the record is

`get_letter` on a letter `on_record` returns `record`: its id, its public link, its SHA-256 and whether it is signed yet. The record document at that link holds the SHA-256 of the print file and its place in the chain. The `letter.on_record` webhook event carries the same.

## In a browser

Open the record's link (`https://app.atomside.com/r/…`) and press **Check this record**. The browser fetches our keys and checks the record itself. Add the PDF you were given to check it is the file that was printed.

## With the record checker

The checker is one file of plain JavaScript with no dependencies:

```sh
curl -O https://api.atomside.com/records/atomside-verify-record.mjs
node atomside-verify-record.mjs ltr_….record.json --print-file letter.pdf
```

It fetches our keys from `https://api.atomside.com/.well-known/atomside-record-keys.json` (or pass `--keys keys.json`), prints one line per check, and ends with "This record checks out" (exit 0) or "This record does NOT check out" (exit 1). `--previous earlier.record.json` checks the chain; `--json` prints the report as JSON.

## With OpenSSL

This uses nothing of ours but one public key, downloaded from a published address. You need the evidence bundle, which the sender downloads from the record's page in the console (**Download the evidence bundle**) and can pass on; `curl`, `sed` and OpenSSL 1.1.1 or later. Unzip the bundle, open a terminal in its folder, and run these lines as they are:

```sh
kid=$(sed -n 's/.*"kid": *"\([^"]*\)".*/\1/p' record.json)
curl -fsS -o atomside-key.pem "https://api.atomside.com/.well-known/atomside-record-keys/$kid.pem"
openssl dgst -sha256 -verify atomside-key.pem -signature signature.der document.json
openssl dgst -sha256 -r letter.pdf
sed -n 's/.*"print_file_sha256":"\([0-9a-f]*\)".*/\1/p' document.json
```

The first line reads the id of the key that signed the record. The second downloads that key from us as a PEM file. The third must print `Verified OK`: `document.json` is the exact bytes we signed and `signature.der` is our signature over them; change one byte of either and it prints `Verification failure`. The last two lines must print the same 64 characters: the hash of the PDF, and the hash of the print file the record holds (leave them out if the bundle has no `letter.pdf`, which is the case once the letter's contents have been deleted).

The bundle also holds the key as `public-key.pem`, so the check works offline. To be sure that copy is ours, compare it with the one you downloaded: `cmp public-key.pem atomside-key.pem` prints nothing when they are the same. Every key is also listed, as a JSON Web Key Set, at `https://api.atomside.com/.well-known/atomside-record-keys.json`, where each says whether it signs live or test records. Daily checkpoints of every chain are published at `https://api.atomside.com/.well-known/atomside-record-checkpoints.json`.

## Test records

A test letter gets a test record, signed with our test key. Each published key says which kind of record it signs, so a test record can never pass as a live one.
