# HumanProof

> Prove a person is present before a form or an action goes through, without learning who they are. Add one script to the page and one check on your server.

Source: https://docs.trustaige.com/humanproof

Replace these placeholders with your organization's own values:

- `<your-site-host>`: Your site’s host, for example `www.example.com`. The host your form lives on, as you registered it under HumanProof → Sites.

HumanProof answers one question: is a person here right now? It never answers
*who*. Use it where bots cost you money or trust (sign-ups, comments, free
trials, text-message codes, downloads) without making real people solve
puzzles. The visitor taps once and uses their passkey; a visitor with no passkey
makes one in the same tap.

## Quickstart

1. **Register your site.** In the hub, open **HumanProof → Sites** and add the
   host your form lives on, such as `www.example.com`, and choose the
   [level of proof](/humanproof/levels) its visitors give. HumanProof only
   vouches for the hosts you register. If your forms live on several
   subdomains, register the domain above them, such as `example.com`, and
   choose **Subdomains too**: the DNS record that proves the domain covers
   every name under it.

2. **Add the script and mark the form.** Load the script once, then add
   `data-humanproof` to each form you want to protect. The widget appears above
   the submit button, and a `humanproof-token` field is sent with the form.

   ```html title="signup.html" {1,3}
   <script src="https://id.trustaige.com/humanproof.js" defer></script>

   <form action="/signup" method="post" data-humanproof>
     <input name="email" type="email" required>
     <button type="submit">Create account</button>
   </form>
   ```

   Protecting something that isn't a form, such as a download, a vote or a
   costly action? See [without a form](/humanproof/without-a-form).

3. **Check the token on your server.** A check in the browser is one a bot can
   skip. Before you act, send the token and your site's host to the verify
   endpoint, and act on `valid`. Trustaige learns the token and the site,
   nothing about the person.

   ```js
   app.post('/signup', async (req, res) => {
     const token = req.body['humanproof-token'];
     const check = await fetch('https://id.trustaige.com/humanproof/verify', {
       method: 'POST',
       headers: { 'Content-Type': 'application/json' },
       body: JSON.stringify({ origin: '<your-site-host>', token: token || '' }),
     });
     const { valid } = await check.json();
     if (!valid) return res.status(403).send('Prove you are human, then try again.');
     await createAccount(req.body);
   });
   ```

   ```go
   func handle(w http.ResponseWriter, r *http.Request) {
       token := r.FormValue("humanproof-token")
       body, _ := json.Marshal(map[string]string{"origin": "<your-site-host>", "token": token})
       resp, err := http.Post("https://id.trustaige.com/humanproof/verify", "application/json", bytes.NewReader(body))
       if err != nil {
           http.Error(w, "try again", http.StatusServiceUnavailable)
           return
       }
       defer resp.Body.Close()
       var v struct{ Valid bool }
       json.NewDecoder(resp.Body).Decode(&v)
       if !v.Valid {
           http.Error(w, "Prove you are human, then try again.", http.StatusForbidden)
           return
       }
       createAccount(w, r)
   }
   ```

   ```python
   @app.post("/signup")
   def handle():
       token = request.form.get("humanproof-token")
       check = requests.post("https://id.trustaige.com/humanproof/verify",
                             json={"origin": "<your-site-host>", "token": token or ""}, timeout=5)
       if not check.json()["valid"]:
           abort(403, "Prove you are human, then try again.")
       return create_account(request.form)
   ```

   ```bash
   curl https://id.trustaige.com/humanproof/verify \
     -H 'Content-Type: application/json' \
     -d '{"origin":"<your-site-host>","token":"<humanproof-token>"}'
   ```

   A request without a token is refused, the same as one whose token fails. A
   bot that skips the widget gets the same answer as a bot that fails it: that
   is what makes it a check.

## Act on the answer

| Answer | Means | Do |
|---|---|---|
| `valid: true` | A person proved it, for this site. | Go ahead. |
| `spent` | This token was already used. | Refuse: a token works once. |
| `below_site_policy` | Real, but a lower level than this site asks for. | Refuse, and ask them to prove again. |
| `invalid` | Not a token HumanProof issued for this site. | Refuse. |
| `origin_not_enabled` | This site isn't registered. | Register it under **HumanProof → Sites**. |

When `valid` is true, `tier` says how presence was shown: `prove`,
`prove_plus` or `attested` (see [levels](/humanproof/levels)). Every field and
status is in the [verify reference](/reference/verify-humanproof).

## Verify without calling Trustaige

Prefer not to call the verify endpoint? Tokens also verify offline against the
public keys published at
`https://id.trustaige.com/.well-known/private-token-issuer-directory`, using
Privacy Pass ([RFC 9578](https://www.rfc-editor.org/rfc/rfc9578)).

## Next

- [**Without a form**](/humanproof/without-a-form): downloads, votes and costly
  actions, and single-page apps.
- [**Levels of proof**](/humanproof/levels): Prove, Prove+ and Attested, and
  which to ask for.
- [**Use cases**](/humanproof/use-cases): where HumanProof pays off, with the
  level to ask for in each.
