Metadata-Version: 2.4
Name: nano-settlement-verify
Version: 2.0.0
Summary: Verify that a Nano (XNO) send block really settled, without running a node client.
License-Expression: MIT
Project-URL: Source, https://github.com/dhyabi2/nano-settlement-verify
Keywords: nano,xno,x402,payments,settlement,receipt,audit
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# nano-settlement-verify

Prove a Nano (XNO) payment really settled — without running a Nano node client, and
without taking anyone's word for it.

If you sell per call (x402, pay-per-call, metered API), this answers the question every
maintainer asks first: *how do I check the payment actually arrived?* You hand it a block
hash, the amount you quoted, and the account you expected to be paid. It asks a public
Nano node and hands back a receipt.

- Python 3.11, **standard library only** — no third-party dependency.
- Raw amounts are integers throughout. 1 XNO is `10**30` raw; a float loses the low digits,
  so raw is parsed with `int()` and never with `float()`. A float `expect_raw` is refused
  with `TypeError` rather than compared — written as `1e30`, 1 XNO would otherwise "match"
  an amount 19884624838656 raw short of it.
- Every node call sends its own User-Agent (`USER_AGENT`). Cloudflare-fronted RPCs,
  `rpc.nano.to` among them, answer urllib's default one with 403 "error code: 1010",
  which reads exactly like a bad node.
- The node call is bounded by `RPC_TIMEOUT_S` (30s). Verification sits on a seller's request
  path, so a node that accepts the connection and then goes quiet fails instead of hanging it.
- The account checked is the account **paid** — the block's link, which a node reports as
  `contents.link_as_account` on a state block and `contents.destination` on a pre-state one.
  It is not `block_account`: that field is the chain the block sits on, which for a send is
  the *payer*. And only a `send` settles anything, so a receive, open, change or epoch block
  is refused however well its amount matches.
- The account is compared as an account, not as the string that spells it. One Nano
  account has two spellings — the modern `nano_` form and the legacy `xrb_` form, whose
  60 characters after the prefix are identical — and a node always answers the `nano_`
  one. Pass `account` in either; a stranger is still refused in either. The receipt
  records the account as the node spelled it, so it always carries the `nano_` form.
- No signing, no sending, no wallet or seed handling of any kind. It only reads.

Install it from PyPI:

```
pip install nano-settlement-verify
```

## First five minutes

The Canon, five lines, from [the-unowned-rail](https://github.com/dhyabi2/the-unowned-rail) (copy them, pass them on):

1. Every rail an agent can be paid on today is owned by somebody who can switch it off.
2. A balance in someone else's database is a receivable, not revenue.
3. We are not selling cheap. Nobody ever refused us over fees.
4. A rail is adopted the moment it is needed, never the moment it is explained.
5. One outside agent paying in XNO for something real beats a thousand messages.

Lines 1, 2, 4 and 5 are positions, not measurements. Line 3 is one: on 2026-11-02 a keyword scan of the
4,521 conversations in [agent-conversations](https://github.com/dhyabi2/agent-conversations) found no outside
agent declining because of fees (the objections were compliance and identity, receipts, and the cost of getting in).
A scan is not proof of absence; if you have been refused over fees, open an issue and it changes the line.

**Make a key offline (receives only if you never hand out the seed).** No network call is made; the seed stays in a file only you can read:

```
git clone https://github.com/dhyabi2/nano-wallet-xno && cd nano-wallet-xno && git checkout 6420e935816c && ( umask 077; python3 cli.py new > nano-key.json )
python3 -c "import json;print(json.load(open('nano-key.json'))['address'])"     # the only thing you ever share
```

**Check the address** (checksum, exit 0 if valid): `python3 cli.py check nano_...`

**Verify one payment with no code of ours** (any public node; this block is a real 0.0005 XNO send):

```
curl -s -H 'Content-Type: application/json' -d '{"action":"block_info","json_block":"true","hash":"B749B757EE750FC9AEA72F33CB429EACCD2ABEC9F2CCF59BF17AFAC304C9A58F"}' https://rpc.nano.to | python3 -c "import sys,json;d=json.load(sys.stdin);print(d['confirmed'],d['subtype'],d['amount'],d['contents']['link_as_account'])"
# true send 500000000000000000000000000 nano_1yo6c1t64ahfjdw1dxizmbbnpdmbrckwhw9phbg5pdkeubrizga4qhnjmnx7
```

Confirmed, a send, the amount you quoted in raw (1 XNO = 10^30 raw), and the account you expected: that is the whole check.

**Pin what you run.** Read the code once, then pin the commit (a commit id is a hash of the code; `git rev-parse HEAD` must print it):

| repo | reviewed commit |
|---|---|
| nano-wallet-xno | `6420e935816c6984e916305465ff22a3e63498bb` |
| nano-invoice | `58b8181498de6b67a4e4afbf76d85420889bd85c` |
| nano-settlement-verify | `f2daf334bb490aed5629c1965957477096b8a953` |
| dual-rail | `e1d3ec721c57c300f65e47b3e8d5e62802269fb9` |

Those four are the state this block was written against (2026-11-02); `git checkout <id>` always gives you exactly that code, whatever happens to the repo later.
An operator who will not let the agent hold a key: see [OPERATORS.md](https://github.com/dhyabi2/the-unowned-rail/blob/main/OPERATORS.md).

## Install

```
pip install nano-settlement-verify
```

Then `import nano_settlement_verify`. From a clone of this repository, `pip install .`
installs the same package.

Or copy `nano_settlement_verify/__init__.py` into your project as `nano_settlement_verify.py`:
`verify` and everything it needs are in that one file, standard library only (the skill
bundle ships exactly that file). The other modules (`quorum`, `payers`, ...) need the package.
Do not keep that copy beside an installed 2.0.0: a local `nano_settlement_verify.py` shadows the package, and
`import nano_settlement_verify.quorum` then fails.

### 2.0.0: one package

Up to 1.3.0 the distribution installed 13 top-level modules and two top-level packages,
`node_set` and `links`. From 2.0.0 everything is inside the one package
`nano_settlement_verify`, so the import paths of every module but the main one changed.
The behaviour did not change; only where it lives. One addition: the wheel now ships
`nano_settlement_verify/node_set/NODES.json`, which the 1.3.0 wheel left out, so `fallback_urls()` returns the
public node list after a pip install instead of an empty list.

| 1.3.0 | 2.0.0 |
|---|---|
| `import nano_settlement_verify` | `import nano_settlement_verify` (unchanged) |
| `from nano_terms import ...` | `from nano_settlement_verify.terms import ...` |
| `from nano_independence import ...` | `from nano_settlement_verify.independence import ...` |
| `from nano_quorum import ...` | `from nano_settlement_verify.quorum import ...` |
| `from nano_payers import ...` | `from nano_settlement_verify.payers import ...` |
| `from nano_claim import ...` | `from nano_settlement_verify.claim import ...` |
| `from nano_five_fields import ...` | `from nano_settlement_verify.five_fields import ...` |
| `from nano_two_node import ...` | `from nano_settlement_verify.two_node import ...` |
| `from nano_funding import ...` | `from nano_settlement_verify.funding import ...` |
| `from nano_recount import ...` | `from nano_settlement_verify.recount import ...` |
| `from nano_period_counts import ...` | `from nano_settlement_verify.period_counts import ...` |
| `from nano_offline import ...` | `from nano_settlement_verify.offline import ...` |
| `from nano_stated_payer_test import ...` | `from nano_settlement_verify.stated_payer_test import ...` |
| `from node_set import ...` | `from nano_settlement_verify.node_set import ...` |
| `from links import public_check` | `from nano_settlement_verify.links import public_check` |
| `python3 nano_quorum.py ...` (any module) | `python3 -m nano_settlement_verify.quorum ...` |
| `python3 node_set/probe.py ...` | `python3 -m nano_settlement_verify.node_set.probe ...` |
| `python3 -m links.public_check ...` | `python3 -m nano_settlement_verify.links.public_check ...` |

`nano_settlement_verify.__version__` is new and reads `2.0.0`. Stored records keep their
schema names (`"nano_quorum.corroboration/5"` and the rest): those are data, not import paths.

The skill's CLI (`skills/nano-settlement-verify/verify_cli.py`) asks the node in
`$NANO_RPC_URL` when no `RPC_URL` argument is given - so if you export that variable for
another tool, the CLI's verifications go there too; an empty or blank value means the
default, `https://rpc.nano.to`. The CLI asks only `http` and `https` URLs, and refuses any
URL containing an `@` anywhere - so a URL with credentials (`http://user:password@host/`) is
never sent, and is reported as `node_unreachable` (exit 4) with a fixed message that quotes no
part of it. An `@` that belongs in a path or query is written `%40`
(`http://host/?key=a%40b`, `/v1/acct%40zone/rpc`), which is sent as written; a `%40` or
`%3A` in the host part (`http://user:pw%40host/`) is a credential and is refused like an `@`; a
URL whose port is not a number from 0 to 65535 (`https://host:key:443/`, which the URL check
and `http.client` would split at different colons, or `:99999`), a URL with no host
(`http:///x`), a URL with a control character anywhere in it, a host that is not plain ASCII
letters, digits, `-`, `.` and `_` or an IP address, and a URL that cannot be parsed at all are
refused the same way, each with its own fixed message. The host rule is there because urllib
percent-decodes the host before it connects, and a TLS error then names the decoded host:
`https://localhost%2FKEY/` would have been reported as `'localhost/KEY'`. So no `%` is allowed
in the host (except a bracketed IPv6 zone id, `[fe80::1%25eth0]`), and an international name
is refused rather than IDNA-mapped: write it in its `xn--` form. These
refusals are configuration errors: retrying will not fix them. Whitespace around the URL,
as the argument or the variable, is ignored; a blank argument is refused, not replaced.

To give the CLI a fallback node, list it after the first, comma-separated, in the argument or
in `$NANO_RPC_URL`: `python3 verify_cli.py BLOCK EXPECT_RAW ACCOUNT "https://rpc.nano.to,https://<your second node>"`.
No node and no budget? `FREE-VERIFY.md`: three verdicts (`settled`, `unknown`, `mismatch`, never "unpaid"), one command, $0.
Three public nodes that answered `block_info` for the same block identically on 2026-11-02 (read-only probe, no key):
`https://node.somenano.com/proxy`, `https://nanoslo.0x.no/proxy`, `https://rainstorm.city/api`; so a ready list is
`"https://rpc.nano.to,https://node.somenano.com/proxy,https://nanoslo.0x.no/proxy"` (see `FALLBACK-NODES.md`;
failover is not agreement, and some public RPCs proxy the same node).
The next node is asked only when the one before could not be reached or read (exit 4); any
answer from a node - settled, not yet, mismatch, no such block - is final and is not retried.
Every URL is checked before any is asked, a URL listed twice or an empty entry is refused (exit 4),
and with more than one URL the verdict names the node that answered as `"rpc_index"` (0-based).
Failover is not agreement: to need two nodes to agree, use `nano_settlement_verify.quorum` ([One node's word, or two?](#one-nodes-word-or-two)).

**Two-node usage from the pinned list.** `nano_settlement_verify/node_set/NODES.json` is the measured list (5 usable, 1 unusable on 2026-11-02; re-measure with `nano_settlement_verify/node_set/probe.py`). Build the CLI argument from it, first two usable nodes, and run (checked on 2026-11-02, exit 0, `"settled": true`, `"rpc_index": 0`):
`python3 skills/nano-settlement-verify/verify_cli.py B749B757EE750FC9AEA72F33CB429EACCD2ABEC9F2CCF59BF17AFAC304C9A58F 500000000000000000000000000 nano_1yo6c1t64ahfjdw1dxizmbbnpdmbrckwhw9phbg5pdkeubrizga4qhnjmnx7 "$(python3 -c 'from nano_settlement_verify.node_set import fallback_urls;print(",".join(fallback_urls()[:2]))')"`
That is failover (the second node is asked only if the first cannot be reached). For both nodes to agree before you ship, use `python3 -m nano_settlement_verify.two_node` or `nano_settlement_verify.quorum`. Some listed RPCs may sit in front of the same node, so two URLs are not proof of two operators.

When the node cannot be reached or read, the detail is chosen by the error's class alone,
from parts of it that cannot hold the URL - the URL itself is never consulted:

- an HTTP error status: `HTTP Error <code>` only (`HTTP Error 401`). The server's reason
  phrase is dropped, because a node can repeat the URL, or one piece of it, in that phrase;
  main showed it (`HTTP Error 401: Unauthorized`);
- a connection, DNS or timeout failure: `[Errno N] strerror`, inside `<urlopen error ...>`
  when urllib wrapped it - exactly main's text for connection refused
  (`<urlopen error [Errno 111] Connection refused>`), a DNS failure
  (`<urlopen error [Errno -2] Name or service not known>`) and a timeout (`timed out`, or
  the ssl module's `The handshake operation timed out`, with the `_ssl.c:NNN: ` prefix
  Python 3.12 adds);
- a proxy that refuses the `CONNECT` tunnel: `<urlopen error Tunnel connection failed: 407>`,
  the status code only - the proxy's reason phrase is its own text and is dropped;
- a TLS failure: its reason code, and for a certificate its verify message
  (`<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname
  mismatch, certificate is not valid for 'host'.>`), which may name the host;
- a reply that is not a node's reply, not JSON or not UTF-8: the library's or the parser's
  own text about the reply, cut at 200 characters, as main printed it;
- anything else - `http.client.InvalidURL` (a space in the URL), any
  other `http.client` error, any other `ValueError`, a `TypeError` raised while the request
  is made - by its class only:
  `the request to the RPC URL failed (InvalidURL)`.

A node you give a key to (in its path or query) can still repeat it in its reply, and the CLI
prints what the reply says - the `got` of a mismatch, or the keys named in a "not a node's
block_info reply" detail - as main does. Put a key only in a URL whose node you trust with it.

Called in-process (importing `verify_cli` and calling `main`), the CLI holds a module-wide
lock for each verification, network call included, because it swaps the library's
`post_json` for the length of the call: two threads calling `main` at once take turns, so a
slow node delays every other in-process caller. The lock is re-entrant, so a `post_json` that
calls `main` again on the same thread does not deadlock. Running the CLI as its own process,
the documented use, is unaffected: each process has its own lock.

## Use it

```python
from nano_settlement_verify import verify, NotFound, Mismatch

RPC = "https://rpc.nano.to"          # any Nano node RPC endpoint

try:
    receipt = verify(
        block_hash="B2EC1E2A1F2C3D4E5F60718293A4B5C6D7E8F9012345678901234567890ABCDE",
        expect_raw=10**24,            # the amount you quoted, in raw
        account="nano_3abc",          # the account you expected to be paid
        rpc_url=RPC,
    )
except NotFound as error:
    print(f"no such block: {error.block_hash}")       # nothing settled — do not serve
except Mismatch as error:
    print(f"expected {error.expected}, got {error.got}")  # underpaid, or paid elsewhere
except (OSError, ValueError) as error:
    # The node did not answer: refused, timed out, HTTP 500, a body that is not
    # JSON, or JSON that is not a node reply. This is NOT "the payment is bad" —
    # it is "we could not check".
    # Retry or hold the call; do not refuse a payment that may well have
    # settled. Catch it: this sits on your request path, and without this arm
    # the first hiccup of a public node raises straight through it.
    print(f"node unreachable, nothing was checked: {error}")
else:
    if receipt.settled:
        print(receipt.to_json())
        # {"settled": true, "amount_raw": 1000000000000000000000000, "height": 42, "account": "nano_3abc"}
        serve_the_call()
    else:
        print("node has the block but has not confirmed it yet — wait and ask again")
```

## What comes back

`verify(block_hash, expect_raw, account, rpc_url) -> Receipt`

| field | meaning |
| --- | --- |
| `settled` | `True` only when the node reports the block confirmed |
| `amount_raw` | the block's amount, as an integer number of raw |
| `height` | the block's height in its account chain |
| `account` | the account the node reports the block paid |

`Receipt.to_json()` gives you that as a JSON string, with `amount_raw` as an unquoted
integer — so it survives a round trip that a float would have truncated.

Four outcomes when the node answers:

| the node says | you get |
| --- | --- |
| confirmed, right amount, right account | `Receipt(settled=True, ...)` |
| `"confirmed": "false"` | `Receipt(settled=False, amount_raw=0, height=0, account="")` |
| `{"error": ...}` | raises `NotFound(block_hash)` |
| a different amount, a block that is not a send, or a different payee | raises `Mismatch(got, expected)` |

And one for when it does not answer at all. There is no retry and no wrapper
exception, so the transport failure reaches you as itself:

| what went wrong | what `verify` raises |
| --- | --- |
| connection refused, DNS failure, or `RPC_TIMEOUT_S` elapsed | `urllib.error.URLError` (an `OSError`) |
| an HTTP error status — 403, 429, 500 | `urllib.error.HTTPError` (also an `OSError`) |
| a body that is not JSON — an HTML error or maintenance page | `json.JSONDecodeError` (a `ValueError`) |
| a body that **is** JSON but is not a node reply — a proxy's status page, a rate-limit envelope | `NotANodeReply` (also a `ValueError`) |
| a body that is JSON but not an object — `"error"`, `["error"]`, a bare number | `NotANodeReply` too: hold and retry. It used to come out as `NotFound`, or a `TypeError` |
| a reply whose `amount` is a JSON float — `1.9`, or an integral one like `1000.0` — or a `true`/`false` | `NotANodeReply` too: a node sends raw as an integer string, and `int()` would have read another number. A JSON integer amount is still read |

A replacement `post_json`, such as a test stub, must return a plain `dict`: a mapping that
is not one, such as `UserDict` or `MappingProxyType`, is refused as `NotANodeReply`. Real
nodes are unaffected, because `json.loads` returns a `dict`.

The proxy's status page and rate-limit envelope row is the one worth knowing about, because a public RPC behind a proxy
answers 200 with its own JSON at least as often as it answers with HTML, and
none of those bodies carries `confirmed`. It used to raise a bare `KeyError`,
which is neither an `OSError` nor a `ValueError`, so it went straight through
the arm below and out of the seller's request path.

**These are not `NotFound`.** "The node has no such block" and "the node did not
answer" are different facts, and only the first one means the payment is not
there. A seller that treats an unreachable node as a missing block refuses a
call the buyer already paid for, and XNO does not come back. Catch `OSError`
and `ValueError` around `verify` and retry or hold — the example above does.

### An order's expiry: `not_after`

`verify(..., not_after=unix_seconds)` also refuses a payment that arrived with the right
amount and account but after the order expired: it raises `Late(seen_at, not_after, receipt)`
(the receipt is kept, the money did move), and settles when `seen_at <= not_after` -
exactly at the deadline is on time. `parse_not_after` reads unix seconds or ISO-8601 with an
offset (`2026-10-09T18:00:00Z`). It is the same single `block_info` read.

**The time is not the sender's.** A Nano block carries no sender-signed time; `seen_at` is
the node's `local_timestamp`, the moment *that* node first saw the block on its own clock,
and another node can differ by seconds. Very old blocks report `0`; missing or `0` raises
`UnknownTime`, never "on time". The deadline is checked against the node you chose - read
it on two nodes if seconds matter.

**What a deadline can be.** `not_after` is `None` (no deadline - pass that if you want none)
or a number of unix seconds: an `int`, a `float`, a `Decimal`, a `Fraction`, or a numpy
integer or `float64`. A deadline that is not a whole number is floored to whole seconds,
exactly - `seen_at` is whole seconds, so that decides every payment as the value itself
would, and `1790150109.9999999` is never rounded up across the second. These raise
`ValueError` before the node is called: a string or a bool (read a string through
`parse_not_after` first), NaN, `inf` or `-inf`, a numpy float narrower than `float64`
(`float32`, `float16` - too coarse to hold a unix time to the second), and anything beyond
2\*\*63 seconds either side of 1970.

**A late payment has still landed.** A seller reading this code pointed out that the README
said why `Late` is raised but not what happens to the money. `Late` is a verdict for you, the
seller, not a refusal the network enforces: the send is confirmed and receivable by your account
(your wallet takes it in by publishing its receive block), and the payer cannot undo a confirmed send. So a seller that gets `Late` should not keep the
money and serve nothing. In order of preference:

1. **Serve anyway** - the default. The block is confirmed, the amount is exact, and it was sent
   to your account. But, like serving any payment, it needs you to record the block hash once
   and refuse a hash already used: `verify` keeps no record of the hashes it accepted, so a
   seller that keeps none could be paid with an old confirmed send of the same amount, again
   and again. The lateness is one node's first-seen
   `local_timestamp` read against your own clock, a weak reason to hold a paid call.
2. **Keep it as credit against that block hash** - for a seller that keeps state and sells
   something that cannot simply be served twice (a one-time asset, a metered run): record the
   hash and let the payer re-present it. This library only reads, so it has nowhere to keep
   that credit; your own store has to. pursekeeper's x402 door holds a hash for its payer,
   but for a different case than lateness, and it does not call that credit (on its door
   "credit" is an X-Nano-Payment balance whoever presents first can spend): a block the door
   broadcast that did not confirm within eight seconds answers 402 naming the hash, nothing
   charged, with a single-use X-Nano-Represent token; it is held for its payer for thirty days
   and served when the payer re-presents the same payload with that token (the hand-back
   paragraph of pursekeeper.dev/api). That is their description of their door; we
   have not tested it.
3. **Send it back** - the last resort. It costs you a signed send block and its work, from
   your own wallet; this library sends nothing.

`exc.receipt` carries what any of those needs: `exc.receipt.amount_raw`, `exc.receipt.account`
(your account, which was paid) and `exc.receipt.settled`; the payer is the block's own account,
which you read from the block, not from the receipt. `UnknownTime` carries the same `receipt`.
The time is the chosen node's first-seen `local_timestamp`, so a different node may give another
time, or none (`UnknownTime`). A deadline that is meant to matter has to be enforced before the
payer broadcasts - as an expiry in your 402 that the payer checks - because after the broadcast
nothing on Nano returns the money by itself. For a Nano send, x402's `maxTimeoutSeconds` is not
such an expiry: it bounds how long the seller waits to settle, and nothing in the send itself
carries it, so a payer's client need not read it. (On x402's EVM `exact` scheme it does bind:
the EIP-3009 authorization the payer signs carries its own `validBefore`, which the x402
reference client sets to the time of signing plus `maxTimeoutSeconds`.) Nor does a fresh `payTo`
for every quote bind the payer or stop a late send. What it gives you is attribution: a payment
to that `payTo` is known to belong to that quote, so a send that arrives after the quote's
window is still that quote's money, to be served or credited as above, not a stranger's.
pursekeeper reports Subnano's door as built that way, a new `payTo` per GET, and quotes
Subnano's own pages for the window: five minutes ("New Nano allocations and USDC quotes last five
minutes for every anchor", subnano.me/llms.txt), with `maxTimeoutSeconds` 300 in a quote read on
2026-11-06 (an earlier quote, from 2026-10-08, carried 60). The window is a duration with no start
time on the wire: the 402 has no expires-at field. What makes it bind is the house's own rule, as
quoted from docs.subnano.ai/v1/api/payments.md: "Once an empty expired checkout address has been
retired, new sends receive no automatic fulfillment or refund", and an expired unbroadcast quote
"can be re-quoted under the same spending policy". These are pursekeeper's quotes, not something
we have measured: neither page answers from where we run.

pursekeeper reports its own x402 door as the other case. Its 402 carries `maxTimeoutSeconds` 60
and nothing else about time: a duration with no start. pursekeeper reports that its door
measures no lateness: a block presented after sixty seconds is verified and served like any
other. Separately, a block the door broadcast that did not confirm within eight seconds is held
for its payer on its hash and served when the payer re-presents the same payload with the represent
token from that 402; after thirty days the hash is marked not spendable. pursekeeper points to the
hand-back paragraph on pursekeeper.dev/api and the live 402 on /v1/echo as the source (read by
pursekeeper on 2026-11-07 and again on 2026-11-08). So on that door the
window is echoed and does not bind. Unlike Subnano's, its `payTo` is fixed, one address for every quote, so there
is no checkout address to expire; this too is pursekeeper's report, not something we have
measured, and that page does not answer from where we run either.

Checked after the fact, `not_after` can only tell you that you were paid late. Pick it with that
slack, or pass `not_after=None` to have no deadline.

**Changes from the previous release.** Code that relied on the old behaviour sees these:

- A deadline beyond 2\*\*63 seconds - such as a huge "never expires" sentinel like `1e300` -
  now raises `ValueError` instead of settling. Pass `None` for no deadline.
- A `-inf` deadline now raises `ValueError` instead of `Late`.
- A reply whose `amount` is a float or a bool - including an integral float like `1000.0` -
  is now `NotANodeReply` instead of being read as raw.
- `Receipt.not_after` and `Late.not_after` are now a plain `int` or `float`: an `IntEnum` or
  a float subclass passed as the deadline comes back as the plain type. The JSON is unchanged.
- In `balance_corroborated`, any node error other than `"Account not found"` now counts as a
  failed endpoint, a figure that is not an ASCII digit string or a plain non-negative JSON
  integer is refused, and a malformed address raises `ValueError` before any node is asked.
- In `verify_corroborated`, each `Corroboration` now carries `observations`, one per
  configured endpoint (after duplicates are folded), in the order given, and each observation
  carries `read_at`, the UTC time its answer was read. Two
  identical calls therefore write different `to_json()` text. `==` and `hash()` leave
  `read_at` out: two calls whose nodes said the same things are still equal and hash alike.
- `Corroboration.to_json()` is larger: it now embeds the `observations` list, the full
  `node_states` table (each state with its meaning) and `node_states_sha256`.
- `to_json()` now starts with a new key, `"schema"` (`"nano_quorum.corroboration/5"`). Code
  that compared the record as text, or read keys by position, sees a different string. (`/2`
  existed only on an unreleased branch.) `verify_receipt_vocabulary` accepts exactly three
  schemas: `"nano_quorum.corroboration/3"`, `"nano_quorum.corroboration/4"` and
  `"nano_quorum.corroboration/5"`. All three carry the same node-state vocabulary, so a stored
  `/3` record written by main still returns True when its `"node_states"` table hashes to its
  own `"node_states_sha256"` and to `NODE_STATES_SHA256`; a `/3` record predates
  `"stop_reasons"`, so that table is checked only for `/4` and `/5`. Any other schema (`/2`,
  a later `/6`, a missing or non-string `"schema"`), and any record whose table or hash
  differs from the pinned one, still returns False.
- `to_json()` writes every endpoint URL with any `user:pass@` replaced by `***@`, and does
  the same to a URL quoted in an observation's `detail` or `error.message`. The `agreed`,
  `answered` and `failed` tuples and the observations in memory still hold the text as given.
  `Disagreement.record()` is not redacted: as before, it writes each `rpc_url` as given,
  credentials included (its `node_observations` redact only through `to_dict()`).
- `observations` is part of `Corroboration` equality. A `Corroboration` built by hand from
  the four old fields (`receipt`, `agreed`, `answered`, `failed`) has no observations, so it
  no longer compares equal to the result of a live call. `dataclasses.asdict()` of a
  `Corroboration` gains an `observations` key.
- A node that answers `confirmed` with block contents that hash to a different block than the
  one asked for now raises `Disagreement`. It used to count toward agreement when its amount,
  payee and height matched. Two confirmed answers that each name a valid, different payer
  chain (`block_account`) also raise `Disagreement` now. An answer with no `block_account`,
  or one that is not a valid address, names no payer chain and is compared as before. When
  `nano_settlement_verify.verify` has been replaced (stubbed or wrapped), `verify_corroborated`
  still calls it for each endpoint, as before; it then has no reply in hand, so neither of
  these two checks is made.
- A `confirmed` observation whose reply named a valid payer chain now carries it as
  `payer_account` (a nano_ address, also written by `to_dict()` and part of equality), and
  a payer-chain `Disagreement`'s `answers` name the chains as nano_ addresses, not key hex.
- An endpoint the check ended before - the quorum was reached, or a `Mismatch` or
  `Disagreement` stopped it - is listed in `observations` with the state `not-asked`,
  `read_at` null and a `detail` saying why. A settled `Corroboration` from three endpoints
  whose first two agreed therefore has three observations. `NotCorroborated` and `Mismatch`
  raised by `verify_corroborated` gain `.observations`, and `Disagreement` gains
  `.node_observations`, with the same per-endpoint entries; `Disagreement.observations` is unchanged.
- `to_json()` writes `"refusal": false` and `"ask_again"` (true exactly when the receipt is
  unsettled) after `"settled"`, so a cached unsettled receipt says in itself that it is
  "not yet, ask again" and not a rejection. A refusal is never a receipt: it raises.
- An `Observation` in any state but `not-asked` now raises `ValueError` when its `read_at`
  is empty or is not a UTC time of the one shape a record carries: extended date, `T`,
  hours, minutes and seconds, an optional fraction of 1 to 6 digits, and `Z` or `+00:00`
  (`2026-11-09T12:00:00.123Z`). A time without seconds, a week or ordinal date, the basic
  no-separator form, a longer fraction or any other offset is refused; `attempted_at`,
  `returned_at` and `stop.at` follow the same rule. `+00:00` is accepted because an
  `Observation` written before this check took any text, and it is UTC; the module itself always writes `Z`.
  So every asked node in a stored receipt says when it was read. `verify_corroborated`
  already wrote one for every asked node, so this check changes none of its records (the
  schema string is now `/5`, for the reasons below); only an `Observation` built by hand
  without a read time, or with another shape of time, is refused. `node_states_sha256` hashes the state vocabulary, not the
  observations: two receipts read at 12:00 and at 12:30 carry the same hash, are `==`, and
  differ in `to_json()` by each node's `read_at`.
- Schema `/4`: each observation gains `"attempted_at"` (UTC, the moment the request to that
  node started) and `"returned_at"` (UTC, the moment its answer came back), written after
  `"read_at"`. Both are null for `not-asked`; `returned_at` is null for `unreadable`, since
  no answer came back, while its `read_at` is still the moment the failure was recorded. For
  an answered node `returned_at` equals `read_at`. `verify_corroborated`'s `clock` is now
  called twice per node asked (before the request, and after it returns or fails), not once.
  An `Observation` built by hand with `read_at` alone is still accepted and writes both as
  null. Neither field (nor `read_at`) is part of a `Corroboration`'s `==` or hash; all three
  are part of an `Observation`'s own `==` and hash, as every field of that dataclass is.
  A wall clock that steps backwards between the two reads (NTP, a resumed VM, a test clock)
  never changes a verdict: an attempt that reads later than its return is recorded with
  `attempted_at` equal to `read_at` (clamped), so the check decides, and raises, exactly as
  with a fixed clock. An `Observation` built by hand with `attempted_at` after `read_at` is
  still refused. A test clock written for one read per node (main's) still works: when the
  clock raises `StopIteration` after it has given at least one moment, that read reuses the
  last moment it gave - on the return read, the node's own `attempted_at`; on a later node's
  attempt read, the previous node's last moment - so the verdict is unchanged and only the
  recorded times repeat. A clock that raises `StopIteration` on its very first read still
  raises, and any other exception from the clock (an `IndexError` from a list that ran dry,
  say) propagates as before. To get a distinct time on each read, yield two per node asked.
- Schema `/4` also writes `"stop"` after `"ask_again"`: why the loop over the endpoints
  stopped, and the quorum rule in force, as `{"reason", "quorum": {"k", "n"}, "at"}` - `k`
  the endpoints that had to agree, `n` the distinct endpoints configured, `at` the `read_at`
  of the last endpoint asked. `reason` is one of the four ways the loop ends, and only those:
  `quorum-reached` (settled), `exhausted` (every endpoint asked without a quorum: an
  unsettled receipt, or `NotCorroborated`), `mismatch` and `disagreement` (both raise). The
  check has no deadline and no budget, so neither is a reason. The table of reasons and their
  meanings is written inline as `"stop_reasons"` with `"stop_reasons_sha256"` (computed like
  `node_states_sha256`, pinned as `nano_settlement_verify.quorum.STOP_REASONS_SHA256` =
  `10cd1fcb6b1e1d6d8c3669184a2be0d47697364bd6b13b246ad33cae8c1e1342`), and
  `verify_receipt_vocabulary` now checks it too. `Corroboration.stop` holds it (null in the
  JSON for one built by hand; not part of `==`), and a raised `Mismatch`, `Disagreement` or
  `NotCorroborated` carries it as `.stop`.
- `"ask_again"` keeps its boolean (true exactly when unsettled), and schema `/4` writes
  beside it `"ask_again_not_before"`: when to ask again, as UTC ISO-8601, null when the
  receipt is settled. The rule is `stop.at + retry_after` seconds, and the record writes the
  delay as `"retry_after_s"`, so a reader can recompute it. `retry_after` is a new keyword of
  `verify_corroborated` (default 0, a finite number from 0 to 10\*\*9, refused before any
  call otherwise). The library still waits for nothing and retries nothing: it does not know
  when a node will confirm a block, so with the default the earliest time is the moment this
  check stopped, and any longer wait is the caller's to set. `NotCorroborated` raised by
  `verify_corroborated` carries the same time as `.not_before`. A `Corroboration` built by
  hand refuses the same delays (`TypeError` for a non-number or a bool, `ValueError` for NaN,
  an infinity, a negative or one over 10\*\*9), so its `to_json()` is always strict JSON, and
  `stop` must be a `Stop` or None (`TypeError`). `not_before` is written to the millisecond
  and a sub-millisecond remainder rounds up, so a nonzero delay never writes the stop moment
  itself; a sum past the year 9999 is written as `9999-12-31T23:59:59.999Z` instead of
  raising `OverflowError`.
- `Observation.from_dict(entry)` reads a `to_dict()` entry back (unknown or missing keys
  are refused; so are an `"error"` on any state but `unreadable`, and `""` where `to_dict()`
  writes null for an empty `read_at`, `attempted_at` or `returned_at` - nothing is dropped
  silently, an entry is read only if `to_dict()` could have written it), and `nano_settlement_verify.quorum.canonical_json` is the sorted, whitespace-free form
  `node_states_sha256` hashes. Three per-node fixtures in `tests/fixtures/observations/` -
  `not_asked.json`, `asked_returned.json` (asked, answer came back with its time) and
  `asked_no_return.json` (asked, unreadable, no `returned_at`) - must round-trip
  (bytes, parse, `from_dict`, `canonical_json` plus a newline) to the same bytes and stay
  three distinct records; their SHA-256 are pinned in `tests/test_observation_fixtures.py`.
  To compare with your own run:
  `python -m pytest tests/test_observation_fixtures.py && sha256sum tests/fixtures/observations/*.json`.
- Schema `/5` records the ask order. Once the loop stops early, who went first decides which
  nodes made up the k and which ended up `not-asked`, so the receipt now says it:
  `"configured_order"` (the endpoints after duplicates are folded), `"ask_order"` (every
  endpoint in the order it was planned to be asked, the `not-asked` ones included),
  `"order_rule"` and `"order_seed"`. Each observation gains `"ask_index"`, its 0-based place in
  `ask_order`; a `not-asked` node keeps its planned place, so it is never null in a live
  record (null only in an `Observation` built by hand without one). `Observation.to_dict()`
  (and so each entry of `"observations"` in `to_json()`) now puts `"ask_index"` first, before
  `"rpc_url"`; code that read an observation's keys by position sees a different order. Observations are listed in
  ask order. The order was, and by default still is, the order the caller gave
  (`"order_rule": "as-given"`, `"order_seed": null`); nothing in the module shuffled it.
  `verify_corroborated(..., order_seed=N)` (an int from 0 to 2\*\*64 - 1) asks in
  `"seed-sha256"` order instead: ascending SHA-256 hex of `str(N) + "\n" + url` (the URL as
  written in the record), ties in configured order, so anyone can recompute it from the
  record, and the same seed and nodes give the same order. `nano_settlement_verify.quorum.replay_receipt(record)`
  re-runs the stop from the record alone - recomputes `ask_order` from the rule, checks each
  observation's `ask_index`, walks the answers with the k of n in `"stop"`, and checks the
  stop reason and moment, `settled`, `agreed` and which nodes are `not-asked` - and returns
  `{"verdict": "match" | "mismatch", "problems", "expected_stop", "expected_not_asked"}`.
  From a shell: `python3 -m nano_settlement_verify.quorum --replay receipt.json` (exit 0 on a match, 1 on a
  mismatch). It checks order and stopping, not amounts and not whether a node told the truth.
  Neither vocabulary changed, so both pinned hashes are as in `/4`; the three per-node
  fixtures gained `ask_index` and their pinned SHA-256 changed with it.

An unsettled receipt is not a failure — it means *not yet*. Ask again later; this library
deliberately has no retry loop and no cache, so the waiting is yours to decide.

## Check it without running our code

You should not have to run the seller's code to believe the seller's receipt. Everything
`verify` decides comes from one public node call, which you can make yourself:

```
curl -s -A 'my-check/1' -H 'Content-Type: application/json' \
  -d '{"action": "block_info", "json_block": "true", "hash": "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"}' \
  https://rpc.nano.to
```

Send both headers. `rpc.nano.to` answers a body without `Content-Type: application/json`
with `{"error":"Action not provided"}`, and curl's or urllib's default User-Agent may be
refused with 403 - either reads like a missing block when it is not.

Then read four fields, which are the only ones `verify` reads:

| field | a payment to you has |
| --- | --- |
| `confirmed` | the string `"true"` (anything else is *not yet*, not *no*) |
| `subtype` (state block) or `contents.type` (older block) | `send` - a receive, open, change or epoch block pays nobody |
| `amount` | exactly the raw amount you quoted, compared as an integer, never as a float; one raw over is a `Mismatch` too, never "at least" |
| `contents.link_as_account` (state) or `contents.destination` (older) | your account; `nano_` and `xrb_` spellings of the same 60 characters are one account |

The hash above is the genesis account's open block. It is confirmed, but its
`contents.type` is `open`, so it settles nothing - which is the answer `verify` gives too
(`Mismatch`). Ask a second node you chose, not one the seller named, if one node's word
is not enough; the next section does that in code.

For a verdict an outside agent can audit field by field - block hash and confirmed,
source not destination and not excluded, exact amount, invoice issued before the block,
nodes read - with any missing field answered `unknown` and never `settled`, see
[FIVE_FIELDS.md](https://github.com/dhyabi2/nano-settlement-verify/blob/HEAD/FIVE_FIELDS.md): the same check as two `curl` calls and a local hash
recompute, and `nano_settlement_verify.five_fields.five_field_verdict` for callers who want it in code.
`settled` there means work may start; it is not buyer acceptance.

## Check a block offline (the payer's own signature)

A Nano block carries a signature made by the account's own key over the block hash
(ed25519, with blake2b-512 in place of sha512). The hash is recomputed from the block's
contents, so given the contents and the signature anyone can check, without asking any
node, that the holder of that account's key signed exactly those contents. Change one
digit of the balance or the destination and the check fails.

It does not prove the block is on the ledger or confirmed. A key holder can sign a block
that never lands, or one that loses a fork. Inclusion still needs nodes: `nano_settlement_verify.quorum`.

Carrying the previous block's hash adds nothing by itself, because `previous` is already
inside the signed contents. What the previous block's full contents add is the amount: a
state block only states the new balance, so the amount sent is the previous balance minus
this one. Given those contents, the check also confirms they hash to this block's
`previous` and are a state block of the same account (`previous_same_account`) before it
reports the change (`amount_raw`, and `balance_change_raw`, negative for a send). With an
invalid signature, a mismatched previous, another account's previous, or a legacy (non-state)
previous block, both are null: it fails closed rather than report an amount nobody signed.
Small-order public keys and R points (such as the identity key `nano_11a1...6iq5p4i8`, with
which a forged signature would verify any contents) and non-canonical encodings are refused.

```
python3 -m nano_settlement_verify.offline B749B757EE750FC9AEA72F33CB429EACCD2ABEC9F2CCF59BF17AFAC304C9A58F
```

The node (default rpc.nano.to) is only used to fetch the two blocks; the check runs on the
fetched bytes. In code: `nano_settlement_verify.offline.offline_check(contents, signature, previous_contents)`.

## One node's word, or two?

`verify` above asks one node. That is the right default for a seller's request path, but
it means the receipt is exactly as good as that one endpoint — and public Nano RPC is
thin: `rpc.nano.to` wants a key and rate-limits a burst, Nanswap throttles, and a proxy
in front of any of them can answer HTTP 200 with something that is not a node reply at
all. An agent with no node of its own has no second opinion to fall back on.

`nano_settlement_verify/quorum.py` (same package, standard library only) is that second opinion. It is run as
`python3 -m nano_settlement_verify.quorum`, not as a file: since 2.0.0 the package modules use relative imports.

```python
from nano_settlement_verify.quorum import verify_corroborated, Disagreement, NotCorroborated

NODES = ["https://rpc.nano.to", "https://my-other-node.example/proxy"]

try:
    out = verify_corroborated(block_hash, expect_raw=10**24, account="nano_3abc",
                              rpc_urls=NODES)          # agree=2 by default
except Mismatch:
    refuse()            # a node has it confirmed, and it did not pay you
except Disagreement:
    refuse()            # two nodes, two different stories — one of them is wrong
except NotCorroborated:
    hold_and_retry()    # too few endpoints answered; NOTHING was checked
else:
    if out.receipt.settled:
        serve_the_call()        # out.agreed names the endpoints that concurred
    else:
        wait_and_ask_again()    # answered, but not confirmed by enough of them yet
```

The rules it holds to, each of which is a way of failing closed:

- **A repeated endpoint is one witness.** `["https://rpc.nano.to", "https://rpc.nano.to/"]`
  is refused with `ValueError` before any call, rather than quietly counting one node
  twice. Being *distinct* still does not make endpoints *independent* — several public
  Nano RPCs are proxies in front of the same node, and nothing here can see that.
  Agreement is only worth what your endpoint list is worth.
- **It does not break ties.** Two nodes that each report the block confirmed, with
  different contents, cannot both be right, and nothing here can tell you which is
  lying. A third vote would only make a guess look like a quorum, so it raises.
- **An answer about another block is not a witness.** When a node's confirmed reply has
  contents complete enough to recompute the block hash, and that hash is not the one you
  asked for, it raises `Disagreement` at once, even if amount, payee and height all match.
  Two confirmed answers that each name a valid payer chain (`block_account`), and name
  different ones, also disagree; an answer that names none, or names something that is not
  an address, is not compared on it. Contents too sparse to hash are not a hash checked;
  they are compared on amount, payee and height as before, and on the payer chain only
  when both answers name one.
- **One `Mismatch` refuses at once.** A node that has the block *confirmed* and says it
  paid a different amount or a different account is reporting something a later node
  cannot overturn — a confirmed block's contents are fixed by its hash.
- **Silence is never a "no".** An endpoint that is refused, times out, or serves an HTML
  maintenance page has told you nothing. Fewer than `agree` endpoints answering raises
  `NotCorroborated`, which means *hold the call*, not *refuse the buyer*. Refusing a call
  that was paid for costs the sale, and XNO does not come back. An endpoint whose reply
  is not a JSON object (a proxy's `"error"`, a bare number) is silence too: it counts as
  failed, not as answered. It used to count as a "not seen" answer, so a quorum that
  returned an unsettled `Corroboration` can now raise `NotCorroborated` instead.
- **It does not retry.** A failed endpoint is skipped, not asked again. Waiting is yours
  to decide, as it is for `verify`.
- **It never sends.** `process` is deliberately absent; this reads, like the rest of the
  package.

Every `Corroboration` also carries `observations`: one entry per configured endpoint, in the
order asked - the order given, unless an `order_seed` was passed; the record's `ask_order`
says which, each entry's `ask_index` is its place in it, and `replay_receipt` re-checks it
(an endpoint the check ended before is `not-asked`, with `read_at` null), each with `rpc_url`, `state` and `read_at` (the UTC ISO-8601 time its answer
was read), and a `detail` string: what went wrong for an endpoint that could not be read,
the two figures or two block hashes for a `mismatch`, and empty otherwise. `state` is
`confirmed`, `unconfirmed` (the node has the block but has not confirmed it), `not-seen`
(the node has no such block), `mismatch` (the node has the block confirmed and it is not
the expected payment, or its contents hash to another block), `unreadable`, or
`not-asked` (configured, but never queried because the check had already ended). An
unsettled receipt therefore says which
node had not seen the block and which had seen it unconfirmed, rather than one "not
settled". `to_json()` includes the list; `NotCorroborated` raised by `verify_corroborated`
carries it as `.observations`, and `Disagreement` as `.node_observations` (its
`.observations` is the mapping described below); no decision depends on it.
`not-seen` is an answer (the node has no such block); `unreadable` is the absence of one
(the node errored, timed out or sent something that is not a node reply), and an
`unreadable` entry carries `"error": {"kind", "message"}` that no other state has. The
record pins this itself: `to_json()` writes `"schema": "nano_quorum.corroboration/5"` and
`"node_states"`, the full state vocabulary (`nano_settlement_verify.quorum.NODE_STATES`) with a one-line
meaning for each, so a stored receipt can be read without this code. Beside them it
writes `"node_states_sha256"`: the SHA-256 hex of
`json.dumps(node_states, sort_keys=True, separators=(",", ":"), ensure_ascii=False)`
encoded as UTF-8. For schema `/5` (and `/4` and `/3` before it: the state table did not change) that is
`3db25e35737038c4d04d16d1306184d7b70746ab726794e6473bf4c51ad4448c`
(`nano_settlement_verify.quorum.NODE_STATES_SHA256`; the module refuses to import if the table and this
value disagree). `nano_settlement_verify.quorum.verify_receipt_vocabulary(record)` recomputes it from a
stored record's own table and returns True only if it matches both the record's field
and the pinned value, so an edited table, or a `/5` record with a different vocabulary,
is caught.

`node_states_sha256` covers the `node_states` table and nothing else. It does not protect
`settled`, `amount_raw`, `account`, the endpoint lists or the observations: someone who
edits any of those in a stored record leaves the hash valid, and
`verify_receipt_vocabulary` still returns True. It shows which vocabulary a record was
written in. It is not a signature over the receipt.

Two `Corroboration`s compare equal, and hash alike, when the receipt, the endpoint
tuples and each node's state, detail and error are the same. `read_at` is left out, so
two identical calls a second apart are equal, while their `to_json()` text differs.
`to_json()` writes endpoint URLs with any `user:pass@` replaced by `***@`. It does not
recognise a key carried in the path or query string. Exception messages still name each
URL as given.

**On disagreement, both observations are kept.** `Disagreement.answers` and the message are
unchanged for any `agree`: the first endpoint that settled and the endpoint that contradicted
it, each with its answer as text. The rest is additive. `Disagreement.observations` maps
every endpoint that answered before the contradiction, and the contradicting one, to the whole
thing it returned - the `Receipt` a `Corroboration` would have carried (amount, height, payee,
settled, `seen_at`), the confirmed balance figure, or the payer report - in the order asked,
and `Disagreement.observed_answers` maps the same endpoints to their answers as text. For
`verify_corroborated` that includes an endpoint that answered it has not seen the send or not
confirmed it yet, with None as what it returned; an endpoint that could not be read did not
answer and is not in it. For a
dispute log, `Disagreement.record()` returns them as a JSON-ready dict:
`{"verdict": "disagreement", "observations": [{"rpc_url", "answer", "payload"}, ...], "served": None}`.
The record is always strict JSON and `record()` does not raise on what the values hold: a
dataclass is written field by field under its own field names (`seen_at` included), a mapping
whose keys are all strings is an object keyed by each key's text (one with any non-string key,
or with two distinct keys that share a text, becomes a list of `[key, value]` pairs, so `1` and
`"1"` stay apart and no key is merged into another), a value with no JSON form (bytes, a
Decimal, NaN, an object whose attributes raise) is written as its `repr`, and amounts stay
exact integers. Each endpoint's entry is bounded on its own (10,000 values for its answer and
again for its payload; a container that reaches the limit writes one marker for the rest, such
as `"<omitted 2990001 of 3000000 items>"` or an `"<omitted>"` entry, not one per element, and a
string or `repr` over 1,000 characters is cut there and marked with its original length, as in
`"...<truncated str of 1000000 chars>"`; an int too long for `str()` is written in hex,
`"<int 0x...>"`, and cut the same way, as `"...<truncated int of N chars>"`) and always carries its
`rpc_url`, so a first endpoint with thousands of payers cannot hide the endpoint that
contradicted it. The one refusal is a `TypeError` when `answers`, `observations` or
`observed_answers` is not a mapping at all. Building one does not raise on what the values
hold either: each answer's text in the message is cut at 1,000 characters and marked with its
original length, as in the record; an int too long for `str()` is written there as
`"<int 0x...>"` (hex, cut the same way), a
dict is copied without hashing its keys again, and a key another kind of mapping cannot hash
is kept under the placeholder `"<unhashable TYPE #i>"`. That is a behaviour change for code that builds a
`Disagreement` itself: an `answers` with no `.items()` used to fail with `AttributeError`.
Nothing in this package builds one that way, so no verification outcome changes.
Nothing is served on a disagreement; the record only says what each node said.

Two more functions come with it:

```python
from nano_settlement_verify.quorum import balance_corroborated, post_json_failover

balance_raw, receivable_raw = balance_corroborated("nano_3abc", NODES)   # integers of raw
reply, which_node = post_json_failover(NODES, {"action": "account_info", ...})
```

`balance_corroborated` compares only the **confirmed** figures. An endpoint that answers
without them — a proxy that drops `include_confirmed` — counts as not having answered,
rather than being read for its unconfirmed `balance`, which is precisely the number that
differs between nodes. Confirmed figures still move, so two honest nodes a block apart
will disagree here; the remedy is to ask again, not to take the larger number.

`post_json_failover` is **failover, not corroboration**: it returns the first endpoint
that answers, for reads where one node's word is enough. Do not decide that money
arrived with it.

## Pay against terms, not against a claim

`nano_settlement_verify/terms.py` (same package, standard library only; a library with no command line - import it as `from nano_settlement_verify.terms import ...`) is for two agents that trade once
and need to agree, before any XNO moves, on what is paid, to whom, and what counts as
delivered.

- **The terms are addressed by the sha256 of their own bytes.** Both sides hold the bytes
  and re-derive the hash, so checking a cited hash needs no registry and nobody else
  online.
- **The schema is pinned:** `version` (`"1"`), `payee`, `amount_raw` (a decimal string of
  raw), `task` (what is bought, in words) and `acceptance`. An unknown field, a missing
  one or a duplicated key is refused, not ignored.
- **The payee must be an address XNO can actually reach.** A Nano address carries a
  blake2b checksum of its own public key, and `load_terms` checks it — not only the
  `nano_`/`xrb_` prefix. A Nano send is irreversible, so terms that pin a mistyped or
  truncated payee are money that leaves and never arrives; that is refused here, with
  `TermsRefused("invalid_payee", ...)`, rather than discovered afterwards.
  `is_valid_account(address)` is public if you want the same check yourself.
- **Acceptance is a check a program runs**, written in before payment: `{"sha256": hex}`
  of the deliverable, or `{"json_keys": [...]}` that a JSON object must carry non-empty.
- **Settlement is checked against the payee and amount the terms pinned**, through
  `verify` above, never against what the seller says afterwards.

```python
from nano_settlement_verify.terms import load_terms, accept, settle, terms_sha256

terms = load_terms(terms_bytes, cited_sha256)   # TermsRefused on any mismatch
done = accept(terms, deliverable_bytes)         # offline; NotAccepted if it fails
# the buyer's own wallet pays terms.amount_raw to terms.payee here
deal = settle(terms, done, block_hash, RPC)
print(deal.to_json())
# {"terms_sha256": "...", "deliverable_sha256": "...", "block_hash": "...",
#  "settled": true, "amount_raw": 1000000000000000000000000, "payee": "nano_3..."}
```

The `Deal` record cites the terms, the deliverable and the block by hash, so anyone
holding the bytes can check it offline, and anyone can check the block on a public node.
Like `verify`, it never signs or sends, and spending one block hash once is yours to
enforce.

## Tests

```
pip install pytest
python -m pytest -v
```

1227 tests: for `verify`, the four acceptance cases, the amount compared exactly (one raw over or under is a `Mismatch`, never "at least"), the two ways it fails closed kept apart (a readable reply that names another amount, payee or operation is a `Mismatch` and refuses the sale; a reply that names no operation or no payee at all is a `NotANodeReply` and holds, so one endpoint that ignored `json_block` cannot accuse a buyer who paid or override the endpoints after it), the order's expiry (on time, late, exactly at the deadline, a missing or 0 `local_timestamp` as unknown time, unix and ISO deadlines, a deadline that is not a number at all, or is NaN or infinite, refused before the node is called, in the family a seller's own handler catches, and a Decimal or numpy deadline accepted and decided by its value, floored exactly, and a numpy float narrower than float64 or a deadline beyond 2**63 seconds refused), the error paths around them, the
a reply that is not a JSON object at all - a proxy's `"error"`, `["error"]`, a bare
number - refused as `NotANodeReply` rather than read as a verdict by the `in` test, with an
object reply and a real `error` answer as controls, and the same reply as exit 4 through the
CLI and a failed endpoint in a quorum; a wall clock that steps back between the two reads
of a node, or jitters over 600 scenarios, giving exactly the fixed-clock verdict and never
raising; the one UTC time shape a record carries, `Observation.from_dict` refusing entries
`to_dict()` never writes, and a hand-built `Corroboration` refusing a NaN, infinite,
negative or out-of-range `retry_after`, with `not_before` rounded up and never overflowing;
the integer-raw guarantee, the receipt's JSON shape, the exact request put to the node and
the User-Agent it carries; for the skill bundle, that SKILL.md's exit table, the CLI's usage docstring and the
codes `verify_cli.py` actually returns are the same set in all three directions, and that
every environment variable SKILL.md declares is read by the bundle - `NANO_RPC_URL`
selects the node that decides the payment, with an explicit `RPC_URL` argument winning
over it, the default unchanged when neither is set or the variable is empty or blank, a
padded value stripped, a padded `RPC_URL` argument stripped too, an empty or blank `RPC_URL` argument refused rather than replaced, and a URL with credentials (percent-encoded or carrying `/`, `?` or
`#` in the password, user-only, `%40` or `%3A` in the host part, or any `@` at all, in the path or query too) or a scheme other
than http/https (`file://`, `ftp://`, none) or a URL that cannot be parsed (an unclosed or
non-address bracketed host, a fullwidth solidus in the host) or a port that is not a number up
to 65535 or no host at all (`http:///x`) or a control character anywhere or a host urllib would
percent-decode or IDNA-map (`%2F`, `%3F`, `%23`, `%20`, `%25`, `%3B`, `%C2%AD`, a unicode
name) refused as `node_unreachable`
(exit 4) before any request, with a fixed detail and no piece of the URL in stdout or stderr,
an `@` written `%40` in a path or query asked as written, and against a loopback node a
non-numeric port, a reply cut short of its Content-Length, a reply that is JSON but not an
object (`"error"`, `"no error here"` and `["error"]` included, which the library's `"error" in
reply` would otherwise read as no such block), one with a field of the wrong type, an amount of
`1e999`, `Infinity` or `-Infinity`, one nested too deeply, and any other exception, each
answered as `node_unreachable` (exit 4) with a fixed detail, never a traceback - while the
detail of a failed request is chosen by the error's class alone (each class tested: an HTTP
status without its reason phrase, `[Errno N] strerror` identical to main's text for connection
refused, a DNS failure and a timeout, an SSL reason and verify message, the library's own
reply text - shown in full at a path named `/api/node` - and the class name for `InvalidURL`
and everything else), a node echoing the URL, a path segment or one value of it in a 401
reason phrase never prints the key, a proxy refusing the tunnel with 407 or 403 prints its
status code without its reason phrase, Python 3.12's `_ssl.c:NNN:`-prefixed timeouts keep
their text, a `TypeError` from the transport is named as a failed request rather than a reply
problem, an uppercase `HTTP://` is asked, a long `<urlopen error ...>` is cut at 200, a URL with a control character or both kinds of quote
never prints it either, and two overlapping callers of the CLI in one process, or one that
calls it again from inside `post_json`, leave the library's `post_json` as they found it;
for `nano_settlement_verify.terms`, the hash check, the pinned schema, both
acceptance checks, the payee checksum (including a one-character-off address, a
character outside Nano's alphabet, and both spellings of one account) and settlement
against the pinned payee and amount; for
`nano_settlement_verify.independence`, the funding chain and the independent-payer grouping; for
`nano_settlement_verify.quorum`, agreement, contradiction, a confirmed answer whose contents hash to another block than the one asked for, the node-state table (only the table) pinned by hash in the record, the duplicate endpoint and every way an
endpoint can say nothing - including, for `balance_corroborated`, which reads a reply
directly rather than through `verify`, a reply that is not a JSON object counted as
failed rather than as an answer of nothing (the `in` test on a string is a substring
test, so a proxy body carrying the word `error` used to corroborate a balance of
nothing), a node's "Account not found" still read as a balance of nothing while any other
`error` (a rate limit, a refused API key, an `error` of null) counts as failed, and a balance
or receivable sent as a JSON number, or as a string `int()` reads but a node never sends
("-5", "1_000", " 7 ", "+9"), refused rather than put through `int()`, which
reads 1e30 as 19884624838656 raw above one XNO and an infinite one as an
`OverflowError` outside the family a caller catches; for `nano_settlement_verify.payers`, both x402 document shapes, every refusal in
the payee table, and what the payer count will not include - an unconfirmed receive, the
seller's own sends, a receive from itself, one account written two ways, a chain read only
half way; for `nano_settlement_verify.claim`, claimed, still receivable to an opened and an unopened
account, a non-send and a malformed hash refused, and every read that fails - a node error, a
receive not found within the bound - coming back as `unknown` with a nonzero exit, each
`unknown` carrying its reconcile path (same send hash, no re-send, next check, escalation
after the read or time limit), each not-found scoped to the nodes and instant read, and a
not-found on one node yielding to a found answer on another; for `nano_settlement_verify.five_fields`, the
block hash recomputed locally and matched against two real blocks pinned as the network
returned them, each of the five fields missing in turn coming back `unknown`, nodes that
disagree, one node, the same node twice and a failed node all `unknown`, an amount over or
under by one raw, an invoice issued at or after the block, a source that is the destination
or on the exclusion list all `refused`, a missing field outranking a failing one, all five
present `settled`, and FIVE_FIELDS.md's two curl bodies pinned to what `read_nodes` sends
with nothing piped into an interpreter; for the quorum's ask order, that `ask_order` is the
sequence the nodes were called in, that on an early quorum the not-asked nodes are its tail,
that one seed gives one order, and that `replay_receipt` passes two orders of the same answers
and fails a receipt whose order was edited; and for the README itself, that the curl body in *Check it without running our
code* is the payload `verify` really sends, so the two cannot drift, and that the count at the head of this
paragraph is the count the suite collects; for the skill bundle, that its vendored library is the
library and that its CLI answers the exit codes SKILL.md documents; for the package, that the
wheel ships the one package `nano_settlement_verify` and its node list, that every module imports
from inside it, that `__version__` is the version in pyproject.toml, and that a patched
`post_json` is the one its modules call. None of them touch the network — the node reply is stubbed,
and a fixture fails any test that tries to open a socket; the skill-bundle CLI tests that
need a real socket use a throwaway server on loopback.

There is also a hand check that exercises the real `urllib` path against a throwaway HTTP
node stub on loopback:

```
python e2e_check.py
python e2e_quorum_check.py
python e2e_payers_check.py
```

The second one stands up several loopback nodes that disagree with each other — one
honest, one lagging, one contradicting, one serving a maintenance page, one dead — and
then, when the network allows it, repeats the decisive case against a real confirmed
block on the live ledger.

The third audits a real x402 seller the same way: it fetches the seller's own document,
derives the account that document says to pay, and counts off the public ledger who has
paid it.

## Link check before you send

`python3 -m nano_settlement_verify.links.public_check --url URL [URL ...]` fetches each link with no credentials and says `send`, `strip` or `refuse` for a message. A non-200 (or an auth wall, or a timeout) is never public; a 200 only proves it from here.

## Three more checks a stranger can reproduce

- **Two nodes, five fields:** [TWO-NODE-CHECK.md](https://github.com/dhyabi2/nano-settlement-verify/blob/HEAD/TWO-NODE-CHECK.md) is the check as two curl calls and a table; `python3 -m nano_settlement_verify.two_node --block HASH --amount-raw RAW --invoice-id ID --invoice-issued-at T --payee ACCT --json` is the same thing in one command (exit 0 settled, 2 unknown, 4 refused). `settled` is not buyer acceptance.
- **Who funded the payer:** [FUNDING-PROVENANCE.md](https://github.com/dhyabi2/nano-settlement-verify/blob/HEAD/FUNDING-PROVENANCE.md); `python3 -m nano_settlement_verify.funding --block HASH --json` returns `unsubsidised`, `sponsor_funded`, `dispenser_funded`, `self_funded` or `unknown`, with the receive that decides it. Payment time is the payer's send block.
- **Recount an address on either rail:** `python3 -m nano_settlement_verify.recount --address nano_... --json`, or `--address 0x... --from-block N` for USDC on Base. Distinct payers and payments, no clustering; a truncated read refuses (exit 3) instead of printing a smaller number.

## Scope

It verifies. It does not sign, send, hold a key, retry or cache, and `verify` itself has no
command line. That is on purpose: a verifier that never touches a secret is one you can read
in a sitting and drop into a seller's request path. (`nano_settlement_verify.payers` does have one, because an
audit is something a stranger runs once from a shell, not something on a request path. It
reads the same way: no key, no send. So does `nano_settlement_verify.claim`.)

It also keeps no record of what it has seen, so **spending a block hash once is yours to
enforce**. A settled receipt says this block paid you that amount; it does not say the block
has not already been spent on an earlier call. Store the hash with the call it paid for and
refuse it the second time, or one payment buys every call the buyer cares to make.

## Licence

MIT — see [LICENSE](https://github.com/dhyabi2/nano-settlement-verify/blob/HEAD/LICENSE).

## Is anybody actually paying this seller?

`verify` answers *did this payment settle?*. Before a buyer has paid anything at all it
asks something earlier: **is this seller real, and is the account it advertises the account
that gets paid?**

`nano_settlement_verify.payers` answers that from two places the seller does not control the reading of — the
seller's **own** x402 document, and the **public ledger**. So a stranger holding nothing but
a URL can re-derive every number, and a seller claiming traffic it has not got is
contradicted by the ledger rather than argued with.

```
python3 -m nano_settlement_verify.payers https://extract.paypercall.dev/.well-known/x402
```

```python
import json, urllib.request
from nano_settlement_verify.payers import payees_from_manifest, payers

doc = json.load(urllib.request.urlopen("https://seller.example/.well-known/x402"))
for payee in payees_from_manifest(doc):     # offline: it parses, it does not fetch
    report = payers(payee.account, ["https://rpc.nano.to"])
    print(payee.account, payee.prices_raw)
    print(report.distinct_payers, report.payments, report.received_raw)
    print(report.repeat_payers, report.repeat_rate)
```

`distinct_payers` cannot tell an account that paid once from one that pays every week, so
each report also carries `repeat_payers` (accounts with two or more confirmed payments) and
`repeat_rate` (`repeat_payers / distinct_payers`, four places, `0` when nobody has paid);
per payer, `payments` and `first_timestamp`/`last_timestamp` (when the payee's receive was
seen, i.e. when the money was collected). Both are recomputed by `outside_payers`.
A repeat is any second payment, including one seconds after the first: read `repeat_rate`
together with each payer's first and last timestamps before calling it returning custom.

Both x402 shapes are read, because they are different documents: a **catalogue**
(`resources[]`, what a seller serves at `/.well-known/x402`) and a single **challenge**
(`accepts[]`, what one resource answers a 402 with). An entry on another rail is skipped —
a seller taking USDC beside XNO is doing nothing wrong — but a Nano entry that cannot be
paid is refused and named: `payee_checksum` (an address XNO would vanish into),
`network_unspecified` (a bare `nano`, which names the family and not the network, and
Nano's test networks share the `nano_` prefix), `not_mainnet`, `amount_not_raw` (a price
written `1e26` or `0.0001`, or as a JSON number, which cannot carry 30 digits exactly).
Skipped entries are not dropped silently: the CLI's output, including a `no_nano_payee`
refusal for a USDC-only document, lists them under `other_rails` (network, asset, `pay_to`,
resource) with `counted: false`, because this tool reads the Nano ledger only.

What the count will **not** include, each because including it overstates what a seller has
been paid:

- a **send** on the payee's chain — that is money leaving, not income;
- an **unconfirmed** receive — it can still be rolled back, so it is reported separately
  and never counted;
- a receive **from the payee itself** — moving your own money is not a customer;
- the same account in both spellings — `nano_` and `xrb_` are one payer, counted once;
- a chain the node did not read back to its open block — that raises `HistoryIncomplete`
  rather than reporting a smaller business, which is the one error a caller cannot see.

An endpoint that serves a reply this cannot read, an amount that is not an integer, or half
a chain is one `payers` walks away from and asks the next node about — failing over on a
*usable answer*, not on an HTTP 200. The report names the node it was read from, and it is
still one node's word; `payers_corroborated` requires several to name the **same set** of
paying accounts, and raises `Disagreement` with the accounts each one named when they do
not. Amounts and timestamps are deliberately not compared across nodes: `local_timestamp`
is when each node saw a block and legitimately differs.

**It cannot tell a customer from the seller funding itself.** The ledger records that an
account sent XNO, never why. `outside_payers(report, our_accounts)` takes that judgement
out of the count and puts it where it belongs — with whoever knows which accounts are
theirs — and nothing here infers ownership from the size of a number:

```python
from nano_settlement_verify.payers import outside_payers

real = outside_payers(report, ["nano_<our own funding account>"])
real.distinct_payers       # accounts that are not us
real.repeat_rate           # the share of them that paid more than once
```

Measured against a live seller on 2026-10-08 — `extract.paypercall.dev`, whose document
advertises one payee across 24 resources priced from `100000000000000000000000000` raw:
**10 distinct accounts have paid it, 27 confirmed payments, 71618000000000000000000000000000
raw**, of which 5 accounts paid only whole multiples of the advertised per-call price.

### Witness: what a reading is true as of

A payer count, and any "this payer is our own money" attribution, is true as of a block,
not forever. Each payer report therefore carries `read_at` (UTC, when the read started) and
`witness`: `frontier`, the newest block of the payee's chain the history was read down from,
and `block_count`, its height. A partial read witnesses nothing (`frontier` and
`block_count` are `null`), and a corroborated report carries a frontier only when every node
read from the same one. `independence` does the same per payer: for each hop, the account's
`checked_at_frontier` and `block_count`, its `open_block`, and the `funding_send` the
attribution rests on. The re-read rule: compare frontiers before comparing counts. A later
read whose frontier is the same read the same chain; one whose frontier differs has seen
that account move, and may flip an attribution - a payer once funded only by its operator
can since have been paid from elsewhere, and the reverse.

## How many independent payers?

Counting paying keys is not counting buyers: one operator can pay from ten accounts.
`nano_settlement_verify.independence` groups payer accounts by where their money came from - the send that
opened each account - and counts each group once. Read-only; same bounded node call.

`nano_settlement_verify.payers.payers` produces exactly the list it wants, so the two compose into the whole
question: from a seller's URL to how many independent payers it has. On the live seller
above, the 10 paying accounts group into **7** independent payers - three of the small
per-call payers were funded from one account, and so are one operator however separately
they paid.

```python
from nano_settlement_verify.independence import independence

report = independence(payers, "https://rpc.nano.to", seller="nano_<your account>",
                      ignore=["nano_<an exchange hot wallet>"])
report.independent      # groups sharing no funder, and not funded by you
report.funded_by_seller # your own money coming back in a circle
```

It is a lower bound on common control, not proof of independence: keys funded from
different exchange withdrawals read as separate payers. `hops` (default 1) follows the
funding chain further back; pass hub accounts in `ignore` so strangers who withdrew from
one exchange are not merged.

Nor can it see collusion. Two parties with money of their own who agree to pay each other
read as two independent payers, because they are: the ledger shows where money came from,
never why it moved. A count of independent payers says the payers do not share a funder; it
does not say the payments were for real work. That needs a delivery record the buyer signed,
which lives outside the ledger.

To apply one stated test instead - "funded by neither us nor you, one hop back, exchange
hot wallets set aside" - with one verdict and witness per payer:
`python3 -m nano_settlement_verify.stated_payer_test --payee nano_... --excluded nano_... --exchange nano_... --payer nano_...`.
By default "one hop back" is the seller's amended reading (2026-11-10): the source of the
largest receive into the payer before the payment (ties: the earliest; no payment yet: all
receives to date, said in `before`). `--hop opening-send` keeps the reading as first stated,
where every `independent` is **opener only**: the funder tested is the account whose send
opened the payer, and later receives are not tested, so each such verdict carries a `caveat`
and the opener's amount, the count and total of later receives and the opener's share.
A send from the payer to itself is never the largest receive, and a history with change or
epoch blocks left out (as rpc.nano.to gives it) is checked block by block rather than refused.
Schema change: the JSON tag is now `stated-payer-test-v3` (was `stated-payer-test-v1`); the
`why` of `independent` now ends "or only a shared hot wallet"; the text output names
`hop rule X` and each payer's `(hop depth N)`; library callers of `stated_test()` get the
new default `hop_rule="largest-receive"` (pass `hop_rule="opening-send"` for the old one).
Verdicts, limits and a real read: [STATED-PAYER-TEST.md](https://github.com/dhyabi2/nano-settlement-verify/blob/HEAD/STATED-PAYER-TEST.md).

## Was the send claimed?

A Nano send does not land in the destination by itself: the account it paid has to publish
a receive block naming it, and an account that has never received anything does not exist
on the ledger yet. `nano_settlement_verify.claim` reads one send hash off the public chain once and says which
of those it is:

```
python3 -m nano_settlement_verify.claim <send-block-hash> [rpc-url] [--nodes URL ...]
```

```json
{"send_hash": "243AF6BFC56A199CB2C40C0ABFF4C583B905615E68F54D6CBCCD1A5F0D0DF57C",
 "from": "nano_1434j1n4sin4cefs5njibag4tsmo596fmg3s6bdogtod3ndmdfez5yuebrh9",
 "to": "nano_3rra4cwps4w6oh8sfctde3tt1g3tjgh39tgxbxdkbn8kmu5yykmgtqaehp6p",
 "amount_raw": "10000000000000000000000000", "send_confirmed": true,
 "outcome": "receivable", "receive_hash": null, "to_account_opened": false,
 "read_at": "2026-10-08T22:30:14Z", "source": "https://rpc.nano.to", "error": null}
```

(That reading was taken before `absence_scope` and `reconcile` existed; the same read now also
carries `"reconcile": null` and an `absence_scope` for the unopened destination.)

`outcome` is one of four words. `claimed`: a confirmed receive on the destination's chain
links this send, and `receive_hash` is that block. `receivable`: the node still holds the
send for the destination; `to_account_opened` says whether that account exists yet. Both
exit 0. `unknown` (exit 2): the read did not settle it - a node call failed or answered
something that is not a node reply, the receive was not among the destination's newest 500
blocks, or the facts disagree; `error` says which. `refused` (exit 3): a malformed hash or a
block that is not a send. A read that could not run never comes back as `claimed` or
`receivable`.

`unknown` is not "wait forever". Every `unknown` carries a `reconcile` object: `operation_id`
(the send hash - look it up again under that identity), `resubmit: false` (do not re-send
because a read was unknown), `nodes_checked`, `checked_at`, `retry_after_s` and
`next_check_at`, and `escalate_after` - after 12 unknown reads or 24 hours since the first,
whichever comes first, `escalate` is true, `action` is `"escalate"`, `next_check_at` is null,
and the caller stops re-checking and takes it to a person. The caller passes `--attempt N`
and `--first-unknown-at T` from its previous read; `--retry-after` (default 300 s),
`--escalate-reads` and `--escalate-hours` change the defaults. Answered reads have
`reconcile: null`.

Not found is not never sent. Absence on the nodes read, at the instant read, is not proof
the send never happened: a node can be behind, and a receive can be older than the history
read. So wherever the tool did not find the send, the receive or the destination account,
the output carries `absence_scope` - `not_found`, `nodes`, `at`, `window` (for a receive,
the destination's newest 500 blocks) and `proves_absence: false` - and the outcome stays
`unknown` (or, for an unopened destination, `receivable`, which needs no receive). With
`--nodes A B ...` the nodes are asked in order: a node that finds the send outranks one
that did not, and not found on all of them stays `unknown`, scoped to all of them. This
answers a condition an outside agent set on Moltbook: unknown needs a reconciliation path,
and absence from one node or one instant must not read as absence from the ledger.

It makes three kinds of read call - `blocks_info`, `account_info`, `account_history` - and
nothing else. The outcome field was asked for by an agent on Moltbook.

## Pinned node set

`nano_settlement_verify/node_set/NODES.json` lists the public Nano RPC nodes that answered `block_info` for a known block with the
exact ledger amount, measured by `python3 -m nano_settlement_verify.node_set.probe --out nano_settlement_verify/node_set/NODES.json --probed-from <label>`
(read-only). `from nano_settlement_verify.node_set import fallback_urls` returns them in file order; a missing or malformed file gives `[]`.
The committed file was measured from a Mac with open egress on 2026-11-02: five usable, one connect-rejected.
Re-run the probe before relying on it; node availability changes.

## External counterparties per period

`python3 -m nano_settlement_verify.period_counts --address nano_... --period month --json` counts, per UTC period, the distinct payers that are neither the address itself nor in the set of accounts it has ever funded. Rule, limits and a real read: [EXTERNAL-COUNTERPARTIES.md](https://github.com/dhyabi2/nano-settlement-verify/blob/HEAD/EXTERNAL-COUNTERPARTIES.md). Tests: `python3 -m unittest tests.test_period_counts`.
