Metadata-Version: 2.4
Name: dual-rail
Version: 1.3.0
Summary: Add XNO beside USDC/x402, never instead of it: one appended accepts[] entry, and a verifier that proves both rails still work.
License-Expression: MIT
Project-URL: Homepage, https://github.com/dhyabi2/dual-rail
Project-URL: Source, https://github.com/dhyabi2/dual-rail
Keywords: x402,nano,xno,payments,wsgi,middleware,agent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# dual-rail — add XNO **beside** USDC/x402, never instead of it

**If our rail fails, yours keeps selling.** Every error on the Nano side — an
unreachable node, a timeout, a malformed proof, a block we cannot find — falls
through to your existing rails exactly as if this adapter were not installed.
There is no code path in it that can turn a Nano problem into a 5xx for a
customer paying in USDC. That is enforced by a test, not by this paragraph:
`test_node_outage_falls_through` runs the whole flow with every node call
raising and asserts no 5xx anywhere.

This is not a migration. It appends **one entry** to your `accepts[]` array and
leaves your existing entries byte-identical, in the same order. A client that
takes the first acceptable entry keeps its current behaviour exactly. Deleting
one array element reverts it.

No dependencies, in either language. Python 3.8+ and the standard library; Node
18+ and nothing else.

## 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).

## Quickstart (two minutes, no Nano node, no network)

```bash
git clone https://github.com/dhyabi2/dual-rail && cd dual-rail
python3 -m unittest discover -s tests          # 215 tests, includes the Python/Node conformance run
(cd node && npm test)                           # 81 tests
python3 tests/capture_live_verify.py            # real HTTP server on 127.0.0.1, adapter mounted, 7/7 verify
```

Then point it at your own 402 (read-only, changes nothing):

```bash
python3 -m dual_rail.cli inspect https://your-service.example/.well-known/x402
python3 -m dual_rail.cli add --manifest https://your-service.example/.well-known/x402 \
    --pay-to nano_YOUR_ADDRESS --amount 0.0001 --diff
```

Install the Python package from PyPI:

```bash
pip install dual-rail==1.3.0
```

That gives you the `dual-rail` command (the same CLI as `python3 -m dual_rail.cli`) and the
`dual_rail` package (`from dual_rail import dual_rail`). Since 1.3.0 every module lives inside
`dual_rail/`: code that did `import verify` or `from adapter import dual_rail` against 1.2.0 now
writes `from dual_rail import verify` / `from dual_rail import dual_rail`. The root scripts are
gone too: `python3 cli.py`, `python3 acceptance_kit.py`, `python3 accepts_snippet.py` and
`python3 usd_quote.py` become `python3 -m dual_rail.cli` (or `dual-rail`), `python3 -m dual_rail.acceptance_kit`,
and so on; run them with `-m` from the checkout root, not by file path. The Node middleware is
not on npm yet: `require('./node/dual-rail')` from a checkout.

The `nano_3t6k35gi…` address in the examples is the public Nano **genesis**
account, used only because it is a valid, well-known address. Put your own
account there.

## What changes in your 402

```diff
  {
    "x402Version": 2,
    "accepts": [
      { "scheme": "exact", "network": "base",   "asset": "USDC", ... },
      { "scheme": "exact", "network": "solana", "asset": "USDC", ... },
+     { "scheme": "exact", "network": "nano:mainnet", "asset": "XNO",
+       "maxAmountRequired": "100000000000000000000000000",
+       "maxAmountRequiredFormatted": "0.0001 XNO", "payTo": "nano_3t6k…",
+       "description": "Feeless native-coin settlement. Optional — the entries above are unchanged.",
+       "extra": { "decimals": 30, "adapter": "dual-rail/1" } }
    ]
  }
```

Same status code, same headers, same ordering, same `x-402-version`. One
additional element at the end of `accepts[]`, and nothing else.

New to selling over x402 in XNO? Start with the one-page [`docs/x402-nano-seller-guide.md`](https://github.com/dhyabi2/dual-rail/blob/main/docs/x402-nano-seller-guide.md): the entry, the check, the traps, and a runnable 15-case refusal list (`python3 docs/refusal_checklist.py`, offline).

One real `nano:mainnet` entry followed from the 402 to a confirmed block on the ledger, verified with no facilitator, is in [`docs/x402-nano-end-to-end.md`](https://github.com/dhyabi2/dual-rail/blob/main/docs/x402-nano-end-to-end.md).

`maxAmountRequired` is in **raw**, the asset's atomic unit, which is what
`extra.decimals: 30` declares it to be — 10\*\*30 raw to the XNO, so the
figure above is 0.0001 XNO. That is how every x402 client reads the field
(feeless402's `offer_amount_raw` is `int(offer["maxAmountRequired"])`), and it
is the same convention the USDC entries above use: their `"10000"` is 0.01 USDC
at 6 decimals, not ten thousand dollars. `maxAmountRequiredFormatted` carries
the decimal figure for a human. You still configure the price in XNO
(`amountXno: "0.0001"`); only the wire format is raw.

## Bind each payment to its request, and keep spent blocks across restarts (opt-in, Python)

Two reviewers' objections to Nano-on-x402 code, answered in two constructor options. Both are off
by default, so an existing install changes by nothing.

```python
rail = dual_rail(payTo="nano_YOUR_ADDRESS", amountXno="0.0001",
                 nodeUrl="https://rpc.nano.to",
                 bindingSecret=os.environ["DUAL_RAIL_SECRET"],   # >= 16 random bytes, yours alone
                 replayDb="/var/lib/myapp/nano-spent.db")        # survives restarts, shared by workers
application = rail.wsgi(protected_app, gate=x402_middleware)
```

* **Payment-to-request binding (`nano-block-sig/1`).** A confirmed send block is public, so a proof that is
  only its hash can be presented by anyone who saw it. With `bindingSecret` the 402's Nano entry carries
  `extra.binding = {scheme, nonce, resource}` and the payer must add `payload.binding = {nonce, signature}`:
  an Ed25519-BLAKE2b signature, made with the key of the account that PAID, over
  `"nano-402-binding/1\n" + block_hash + "\n" + nonce + "\n" + resource + "\n" + payTo`. The seller holds no
  state for the nonce (`<expiry_hex>.<HMAC(secret, resource|expiry|payTo)>`, ten minutes). A watcher with only
  the block hash cannot sign; a signature for `/report` is worthless on `/other`; a nonce from another seller or
  for another payee is refused. A bad or missing binding is "unpaid": the request falls through to your other
  rails exactly like any other failed proof. The buyer side is `nano-pay402` in
  [nano-wallet-xno](https://github.com/dhyabi2/nano-wallet-xno), which signs the identical message
  (`tests/test_binding.py` and its tests pin one shared signature vector).
* **Persistent, atomic replay store.** `replayDb` is a SQLite file (mode 0600, WAL). A block is spent once,
  for whichever resource claims it first, with one atomic `INSERT OR IGNORE`: 32 racing threads over four
  connections give exactly one winner (`test_concurrent_claims_have_exactly_one_winner`), and a restarted
  process still refuses a block it served before. Pass `guard=` to supply your own (`seen`, `claim`).

Not done: the Node binding has no equivalent yet, and the binding does not cover the request body.

## Acceptance kit and the paste-in accepts[] generator

Two commands a seller can run. Both read only: no key, no payment, nothing is installed.

**`python3 -m dual_rail.acceptance_kit`** runs five cases a Nano-paid seller should pass, and exits 0 only if all five ran and passed
(5 means a case was skipped, 1 means one failed). The last three need a [nano-invoice](https://github.com/dhyabi2/nano-invoice)
checkout: `git clone --branch v0.2.1 https://github.com/dhyabi2/nano-invoice` and `--nano-invoice PATH`. `refusal-probe` needs a dual-rail checkout (its script is in `docs/`, which pip does not install): from a pip install it is reported skipped, so the kit exits 5 there, never 0.

| case | what passing it proves |
|---|---|
| `refusal-probe` | a check built to say no does say no: 15 offline payments (1 honest, 14 that must be refused for the stated reason) |
| `accepts-shape` | the Nano `accepts[]` entry has every field x402 v1 and v2 require, raw as an integer string, a checksummed `payTo`; `--manifest URL` runs it on yours |
| `duplicate-retry` | one payment presented twice is served once, in memory and after a restart; a second exact transfer is `duplicate` and refunded to its sender |
| `attribution-tests` | exact amount pays and records the chain's sender; off by one raw pays nothing; short is underpaid; after expiry is late |
| `buyer-recovery` | the invoice id re-derives from merchant and order key, the same order key returns the same invoice, a duplicate is refunded |

**`python3 -m dual_rail.accepts_snippet --manifest URL --pay-to nano_... [--usd 0.01 | --amount 0.0001] [--framework python|node]`**
reads your own x402 manifest and prints the exact modified manifest (your entries untouched, one Nano entry appended), its
diff, the server change, and a test that fails if an existing entry changed. With `--usd` the price stays in dollars:
converted to raw at read time from two independent feeds (refused if they differ by more than 2 percent, rounded up), valid
60 seconds, refunds return the same raw. See [`docs/USD-PEGGED-QUOTE.md`](https://github.com/dhyabi2/xno-call-binding/blob/main/docs/USD-PEGGED-QUOTE.md).

## The verifier is the product

The middleware is the implementation detail. This is the artefact that goes in a
message:

```
$ dual-rail verify https://example.dev/report --payment 9F2C0000…

[pass] 402 challenge reachable                HTTP 402, x-402-version: 2
[pass] pre-existing rails intact              2 entries: USDC/base, USDC/solana  (unchanged)
[pass] nano entry present and last            nano:mainnet XNO 0.0001 -> nano_3t6k35g…
[pass] nano payTo passes checksum             valid
[pass] existing rail still settles            2 pre-existing challenges well-formed
[pass] nano rail settles                      block 9F2C0000… -> HTTP 200
[pass] node outage falls through              unverifiable proof -> HTTP 402 with all 3 entries, no 5xx

verify: 7/7 pass - both rails live, existing rails unchanged.
```

Exit 0 only if all seven hold. A captured run against a live endpoint is in
[`tests/verify-against-a-live-endpoint.txt`](https://github.com/dhyabi2/dual-rail/blob/main/tests/verify-against-a-live-endpoint.txt),
whose header says precisely what that run does and does not prove.

`--payment` is spent by the run: one payment buys one call, so verifying twice
needs two payments. That is the replay protection working.

## Install

### Node / Express

```js
const { dualRail } = require('./node/dual-rail');   // from a checkout

app.use(dualRail({
  payTo: 'nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3',
  amountXno: '0.0001',                     // a decimal STRING, never a number
  nodeUrl: process.env.NANO_NODE_URL,
  gate: x402Middleware,                    // your paywall - see "Mounting" below
}));
```

### Python / WSGI (Flask, FastAPI via WSGI, anything)

```python
from dual_rail import dual_rail

rail = dual_rail(payTo="nano_3t6k35gi…", amountXno="0.0001",
                 nodeUrl=os.environ["NANO_NODE_URL"])
application = rail.wsgi(protected_app, gate=x402_middleware)
```

Construction **throws** if `payTo` fails its checksum. A service must not be
able to boot advertising an address nobody can pay. It also throws if
`amountXno` is outside 0.000001–100 XNO, if it is a float rather than a string,
or if `onVerifyError` is anything but `"fallthrough"` — failing closed on our
rail would let our outage cost you a sale on yours, so the option exists only to
be read, never to be changed.

### Mounting, and why `gate` exists

Without `gate` the adapter does the additive half: a 402 written by anything
downstream gets one entry appended on its way out. That needs no cooperation
from your stack at all.

Admitting a Nano-paid request is the other half, and it means bypassing your
paywall — so the adapter has to be shown which middleware that is. `gate` is it.
The adapter never modifies, wraps or reorders anything else, and a request
without a valid Nano payment goes through your gate untouched.

## CLI

There is one CLI, and it is the Python one — `dual_rail/cli.py` (run it as `dual-rail` or `python3 -m dual_rail.cli`, not by file path). The Node package ships
the middleware only; duplicating the verifier in two languages would give two
things to keep in step and no more assurance, and the verifier talks HTTP to
your endpoint rather than into either runtime.

```
dual-rail inspect <manifest-url|file>       # read-only; prints the current rails
dual-rail check   <manifest-url|file> [--json]   # read-only; would a client PAY the Nano entry?
                                                 # reads a 402 challenge or a resources[] catalogue
dual-rail add --manifest <url|file> --pay-to nano_… --amount 0.0001 [--out p.json|--diff]
dual-rail verify <base-url> [--payment <block hash>] [--json]
dual-rail verifiers [--node <url>] [--json]      # who can validate an XNO payment today, checked live
```

`add` exits **3** rather than emit a patch that removes or modifies a line it
did not author — including on a YAML manifest, which cannot be re-rendered
without rewriting lines, and where it tells you to use `--out` instead. Run on
an already-patched manifest it exits 0 with `already_present` and emits nothing.

## Who can validate an XNO payment today?

```
python3 -m dual_rail.cli verifiers [--json]
```

Checked live each run, never from a list: (1) a `block_info` read against a
public Nano node (`https://rpc.nano.to` unless `--node`) - this is
self-verification with no facilitator and no custodian, because the payer
broadcasts its own signed send block and any node shows it to anyone; it is the
read `dual_rail/verify.py` makes; (2) [gosuda/x402-facilitator](https://github.com/gosuda/x402-facilitator),
whose main-branch README must still have a `### Nano` section naming
`nano:mainnet` with `exact` ticked. It is reported `custodial: false` only while
that section says the payer broadcasts its own block and the facilitator is
read-only on the chain; otherwise `unknown`. A check that cannot be reached is
reported unreachable, not passed. Exit 0 if at least one is confirmed, 1 if none.

## Would a client actually pay your Nano entry?

`inspect` reads the price under whichever name your document uses — x402
renamed it from `maxAmountRequired` (v1) to `amount` (v2), and it reports which
one it found in `amount_field`. It also reads a **multi-resource** manifest,
where `accepts[]` sits under each `resources[]` item rather than at the top
level, and reports each resource separately. `add` deliberately refuses that
shape: which of your resources gets the payout address is your call, not this
tool's, so point it at the one resource's own 402.

`inspect` says what is in your `accepts[]` array. `check` says whether anything
would act on it — and it is a different question, because an x402 client that
cannot parse your Nano entry does not reject it with a reason. The entry fails a
schema check inside the client library and is **dropped before any payment is
attempted**. From your side that is indistinguishable from nobody wanting to pay
in XNO.

```
$ python3 -m dual_rail.cli check https://your-service.example/.well-known/x402

accepts[1]  network "nano-mainnet"
  x402 v2: 3 problem(s)
    [network_not_caip2] "nano-mainnet" is accepted by x402 v1 but refused by v2,
      whose NetworkSchemaV2 requires a colon (@x402/core 2.28.0). Emit "nano:mainnet"
    [amount_field_is_other_version_name] this entry carries maxAmountRequired,
      x402 v1's name for the price…
    [pay_to_invalid] payTo is not a payable Nano account (bad_checksum)…

check: NOT payable as it stands
```

It exits **1** when nothing in the document is payable, so it can gate a deploy.

The rules come in two halves, and the split is the point. `shape_problems` is
**only** what the x402 schema itself rejects, read off `@x402/core` 2.28.0's own
`PaymentRequirementsV1Schema` and `PaymentRequirementsV2Schema` — the renamed
amount field, the CAIP-2 network rule that v2 added and v1 did not have,
`maxTimeoutSeconds` being a `number` so that `"60"` is refused, `extra` having
to be an object or null. That half is checked for **equivalence** against the
real installed package by `tests/cross_check_x402_core.js`, over 120,000
nearly-valid documents of which the library accepts about 42%; the captured run
is in `tests/cross-check-against-x402-core.txt`. It is not part of the suite
because this package has no dependencies and is not acquiring one.

`nano_problems` is what no generic x402 conformance tool can check, because it
needs the chain:

- a `payTo` that is well-formed and **fails its checksum**. x402 asks only for a
  non-empty string, so the client accepts it and the money sent there is
  unspendable.
- an amount that is not a whole number of raw. `@x402nano/typescript-common`
  declares an integer amount `/^\d+$/`, so `"0.0001"` is not a payable v2
  amount however right it looks.
- an amount above 2\*\*128-1 raw, which no Nano block's balance field can hold.
- a network identifier that means Nano but is not the canonical spelling.

And because a client parses the whole 402 or none of it, `check` reports a
**sibling** entry that sinks the document your entry is in — a USDC entry
carrying `"network": "base"` in a document that says `x402Version: 2` fails
`NetworkSchemaV2`, and the array your Nano entry sits in is thrown out with it.

### Two document shapes, and the one that used to read as empty

A **402 challenge** has a top-level `accepts[]`. A **resource catalogue** —
what a seller serves at `/.well-known/x402` — has `resources[]`, each item
carrying its own `url` and its own `accepts[]`. `check` read only the first
shape and reported a catalogue as `accepts must be an array of entries; got
null`: **0 entries, 0 naming Nano, not payable**, exit 1, about a document
carrying payable Nano entries. From the seller's side that is the same thing as
nobody wanting to pay in XNO, which is the confusion this whole command exists
to end. It now reads both, one resource at a time — flattening them would
invent an `accepts[]` no client ever sees and make an entry's index meaningless:

```
$ python3 -m dual_rail.cli check https://extract.paypercall.dev/.well-known/x402

x402 version declared: 2
document:              resource catalogue, 24 resource(s)
accepts[] entries:     24 across all resources
resources naming Nano: 24, of which not payable: 0
```

`payable` for a catalogue is **every** Nano resource, not any: a catalogue of 24
endpoints with one unpayable entry is a seller problem, and an `any` would
report it healthy on the strength of the other 23. `resources_not_payable` says
how many, and each is printed under its own url.

A catalogue entry is an **advertisement**, not a challenge, and the three
fields the x402 schema requires that only a live 402 can supply —
`maxTimeoutSeconds`, and v1's `resource` and `description` — are reported as a
note rather than counted against it. Measured: the manifest above omits all
three on all 24 entries, while a real 402 from the same resource carries
`maxTimeoutSeconds: 60` and a top-level `resource` object. Reporting them as
problems would be the same false alarm `verify` used to raise about a working
USDC rail. The relaxation covers a **missing** field only — a
`maxTimeoutSeconds` of `"60"` is still refused — and nothing a later 402
cannot repair is relaxed at all: a bad checksum, a decimal amount, an amount
over the 128-bit ceiling, a wrong asset, scheme or network still sink the
entry.

`shape_problems` itself is untouched by this, which is why the equivalence run
above still reads 0 disagreements over 120,000 documents: the catalogue
relaxation sits one layer up, in `split_challenge_only`. A catalogue is not a
document `@x402/core` models — `PaymentRequiredSchema` rejects it for want of
`resource` and `accepts` — so the equivalence claim is about the **entries**,
which are `PaymentRequirements` in either shape, and not about the catalogue
around them.

## Network identifiers: there is more than one

`nano:mainnet` is the canonical spelling and the only one x402 v2 accepts.
`nano-mainnet` is also in the wild: legal under v1, whose `NetworkSchemaV1` is
any non-empty string, and refused by v2. `dual_rail/network.py` / `node/network.js` read
both as mainnet, emit the canonical one, and tell you which you were given.

A bare `nano` or `xno` is **refused**, not assumed: it names the family without
naming the network, and Nano's test networks use the same `nano_` address
prefix, so reading it as mainnet would be a guess about where money goes. It
comes back as `network_unspecified`, and `nano:testnet` comes back as
`not_mainnet` — a different answer from "this is not Nano", because the two want
different fixes.

This matters to the adapter and not only to the validator. `find_nano` used to
compare against the literal `nano:mainnet`, so a seller who **already** accepted
XNO and spelled it `nano-mainnet` looked like a seller with no Nano entry, and
`add` appended a second one. The array then carried two Nano prices and two
payout addresses, and which one got paid depended on the payer's protocol
version: a v1 client takes the first entry it can pay, a v2 client refuses
`nano-mainnet` outright and takes the other. `add` is now a no-op there, and
`check` reports such an array as `duplicate_nano_entries` if one reaches it.

## Money

Integer raw end to end (1 XNO = 10\*\*30 raw): `BigInt` in Node, `int` in Python.
A float amount is **refused**, not rounded — a double holds 53 bits of mantissa
against the ~100 a raw balance needs, so one float round trip loses real money
in the low-order digits. Underpayment by a single raw is underpayment.

## Verifying it before you mount it

```
$ python3 -m unittest discover -s tests
Ran 215 tests — OK

$ cd node && npm test
# pass 81

$ python3 -m unittest tests.test_conformance
```

The last one is the interesting one. The two bindings have to behave
**identically**, and a promise that they do is worth nothing without something
that runs them side by side: `tests/test_conformance.py` drives one shared
matrix — addresses, amounts, price bands, challenge shapes, network
identifiers, whole 402 declarations, payment proofs, settlement verdicts —
through both and asserts deep equality, case by case, **messages included**. It
fails rather than skips if `node` is missing, because an unrun conformance suite
is exactly the state in which two implementations drift apart.

Node has no variable-length BLAKE2b (`crypto` offers `blake2b512` only) and
Nano's address checksum needs a 5-byte one, which is **not** a truncation of the
64-byte digest. `node/blake2b.js` implements RFC 7693 properly, and its digests
are checked against Python's `hashlib.blake2b` on ten vectors including
multi-block input.

No test in this repository reaches a Nano node or any host but 127.0.0.1.

## What it does not do

It does not run a node, hold a key, or sign anything — it only reads whether a
block you were paid is a confirmed **send to your account**. It does not choose
your price. It does not
touch your existing rails, and it is built so that it cannot: `assert_additive`
compares the array before and after and raises unless the prefix is deeply equal
and exactly one element was added.

The replay guard is per-process and in-memory. A service running several workers
needs a shared store behind `ReplayGuard.seen`/`remember` — two methods, said
here rather than discovered in production.

The guard keys each purchase on the request **path**, canonicalised the same way
in both bindings (`verify.resource_key` / `resourceKey`): query and any
`scheme://host` prefix dropped, percent-escapes decoded, repeated slashes
collapsed, trailing slash dropped, ASCII lowercased. So `/report/`, `/REPORT`,
`//report`, `/%72eport` and `GET http://any.host/report` are one purchase, and
`/report` and `/reports` are two. A route whose handler really is
case-sensitive shares one key with its other-case spellings: that refuses a
second call, it never admits one.

**Upgrading with a persisted store.** Earlier versions keyed on
`scheme://host/path` (and, briefly on 2026-10-11, on the raw path alone). If
your `seen`/`remember` are backed by a store that outlives the process, rewrite
every stored key through `verify.migrate_legacy_key(key)` (Python) or
`migrateLegacyKey(key)` (Node) before the new version takes traffic. Without
that, every block spent before the upgrade can be spent once more. The
in-memory default starts empty and needs nothing.

A Python app mounted under a prefix passes it: `verify.migrate_legacy_key(key,
"/api")`, because the Python key now includes SCRIPT_NAME and the old one did
not (the Node key always carried the mount through `originalUrl`). Run the
migration once: with a mount prefix it is not idempotent (a second pass turns
`/api/report` into `/api/api/report`). One kind of old key cannot be migrated:
one whose host part the payer shaped with an odd `Host:` header
(`http://a/b/report` becomes `/b/report`), so that block can be spent once more
on the real path. It takes planning before the upgrade and buys one call.

## Who made this, and its honest limits

Written and maintained by **dhyabi2**, as part of an effort to make Nano (XNO)
a practical payment rail for AI agents. It is ours; it is not an official Nano
Foundation or x402 Foundation project.

- **No third-party deployment yet.** The captured verify run is against our own
  test host on 127.0.0.1 with a fake node (its header says so). Nobody outside
  has mounted this in production yet.
- **`nano:mainnet` is not a network name the x402 specification defines.** A
  client that does not know it simply skips the entry - which is exactly why it
  is appended last and never replaces your rails.
- **Replay protection is in-memory and per-process** (see above).
- **Your node is your trust anchor.** A payment counts when the node you
  configure says the block is confirmed; the adapter does not cross-check a
  second node.
- **A proof must be a send to your account, and only that.** Until
  2026-10-04 a confirmed block of any other kind whose `block_account` was your
  payout address verified — which a *receive* on your own account is. Every
  receive hash is public in your account history, so a stranger could read your
  ledger and be served without paying. The payee is now read from the block's own
  send destination, anything that is not a send is refused as `not_a_send`, and
  the two accounts are compared by public key rather than by the `nano_`/`xrb_`
  spelling a node happens to serve.
- Python package 1.3.0, on PyPI; the Node middleware (1.0.0) is not on npm yet.

MIT licensed - see `LICENSE`.
