# Identity verification for a site

Use this when a site answers with HTTP 401 and a `PROOF-REQUEST` header, or
asks for the owner's Proof account email. The packaged helper makes the site
calls and relays the challenge through the Coordinator, so the challenge,
cookies and Result Artifact stay in its private directory. No
transaction is signed and no funds move. This reference follows
x401 0.2.0 and needs no other reading.

## The Proof email

A site needs the owner's Proof account email before it can issue a usable
challenge. When the site asks for it, ask the user; never guess it or reuse
another address. Say why in plain words, without naming `login_hint`: the site
passes it to Proof to find the owner's account, and the Wallet shows it masked. Put
it only in `request.json`, where the site asks for it. When the output's
`peerProblemType` is `proof-account-email-required`, the challenge carried no
account email: tell the user the site needs the owner's Proof email. The helper
has removed its directory, so write `request.json` with the email in a new
private directory and run the helper on that. On the owner's rules in an
unattended run, report that the site needs the owner's Proof email and stop.

## Run the helper

The helper sends a text `body` and retries with the verification in the
`PROOF-RESPONSE` header. A binary request body, or a site that wants the
verification in `Authorization`, is unsupported. Report that to the user and
stop, without starting a verification.

Before starting a new verification, delete earlier x401 directories whose
expiry has passed; the helper's waiting output names each directory and its
expiry. Create a new private directory outside the package and Pairing
state (0700 on POSIX; on Windows, access for the operating-system account
running the agent only). Write `request.json` in it with a script
or file tool, keeping its contents out of shell arguments and output:

```json
{ "url": "https://site.example/action", "method": "POST", "headers": { "content-type": "application/json" }, "body": "{\"email\":\"...\"}" }
```

`url` must be `https:` (`http:` only for local or `.test` hosts). `headers`
and `body` are optional. `body` is the exact text to send. Put any
cookies or credentials the site already needs in `headers`. From the selected
installed package, run:

```text
node scripts/x401-fetch.mjs --trust-profile production --state-dir <same-absolute-state-directory> --pairing <id> --dir <private-directory>
```

Each run does one step and exits. Follow the JSON it prints:

- `site-answered` with `verification: "none"`: the site asked for no
  verification. Read `body` for what it needs; to try again, write
  `request.json` in a new private directory and run the helper on it.
- `proofState` `awaiting-decision` or `waiting-for-proof`: relay `proofMessage`
  as written, then follow [the waiting rule](../SKILL.md#waiting-for-the-decision).
  When the user replies, rerun the same command. The owner may finish at Proof
  without returning; a reply is your cue to check. The owner acts in the
  Wallet and at Proof themselves. The Wallet shows what the site says it needs
  and a masked account, not a verified claim about the site. On the owner's
  rules in an unattended run, report the pending verification and stop.
- `site-answered` with `verification: "artifact"`: the helper retried the
  original request once. Report the site's confirmed outcome from
  `httpStatus` and `body`. `newChallenge` or a `proof-result` header means the
  site did not accept the verification, which is not success.
- `proofState` `rejected`, `expired`, `failed` or another value: follow `nextAction`.
  After `rejected`, stop and ask before any new request. Starting again needs
  a fresh site challenge; ask first unless the owner's rules allow it.
- An `error`: follow its `nextAction`. Where it says to rerun an `x401`
  command, rerun the helper with the same directory. After `site-unanswered`,
  the site may have acted: check its outcome or ask the user before sending
  again. A rerun never resends the first request on its own: the helper renames
  `request.json` to `request.sent` before sending it.

The first challenge freezes the request: later runs retry that exact URL,
method, body, headers and cookies, and ignore a new `request.json`. Printed
site answers are capped, with values you have not seen shown as `[redacted]`
and email addresses as `[email]`. The helper deletes the directory once the
verification has ended, or on the first run after its expiry, and the output
then has `removed`. Otherwise the
directory holds a pending verification, a request to correct or files of your
own; follow `nextAction`, and delete it yourself only if you abandon the
verification. A payment challenge
is a separate action, not permission to pay.
