# Verifying a company on Grietens

For the AI assistant (or the person) who sets up a shop on Grietens. A shop reaches the open quote network (requests from the
Grietens request page and from buyers' AI apps), and shows its logo and a link to its website, only once its **company** is checked.
The company proves itself by its own **domain**: something only the business controls. Who does the setup does not matter (the
owner, a relative, an agency, an AI assistant): what is proven is the business, never the installer. It takes about a minute.

The example below is made up: the joinery **Kalna galdniecība**, its domain `kalnagaldnieciba.example`.

## 1. Start

State the company's facts (they are never shown to buyers), then start with the company's own domain:

```
POST /api/v1/shop-profile           {"legal_name": "SIA Kalna galdniecība", "registration_number": "40003999999", "country": "LV",
                                     "website": "https://www.kalnagaldnieciba.example"}
POST /api/v1/company-verification   {"domain": "kalnagaldnieciba.example"}
```

(MCP: `set_shop_profile`, `start_company_verification`.) The answer holds a code tied to this workspace and this domain, valid
30 days, and the three ways to prove it, with the exact record, file and tag:

```json
{ "state": "pending", "domain": "kalnagaldnieciba.example",
  "pending": { "code_expires_at": "2026-12-16T09:00:00.000Z", "ways": {
    "record": { "name": "_grietens.kalnagaldnieciba.example", "type": "TXT", "value": "grietens-verify=3f9a…" },
    "file":   { "urls": ["https://kalnagaldnieciba.example/.well-known/grietens.txt", "https://www.kalnagaldnieciba.example/.well-known/grietens.txt"],
                "content": "3f9a…", "tag": "<meta name=\"grietens-verify\" content=\"3f9a…\">" },
    "mail":   { "needs": "an address at kalnagaldnieciba.example …" } } } }
```

Starting the same domain again returns the same code while it is valid. The domain must be the company's own: a registrable domain,
or a subdomain of the shop's own website's domain (`shop.kalnagaldnieciba.example` when the website is on `kalnagaldnieciba.example`).
An IP address, a local name and every domain that many unrelated people share are refused, because anyone can get an address there,
so they can never prove a company: a mail provider's or an internet provider's mail domain (gmail.com, inbox.lv, elisanet.fi,
online.no, t-online.de, wp.pl), a website-builder, hosting, app-platform or dynamic-DNS domain and any host under one (wixsite.com,
github.io, azurewebsites.net, onrender.com, duckdns.org), and a registry's own ending (co.uk, com.lv: the company's domain is the
name in front of it, `kalna.co.uk`). The list is built in (`lib/shared-domains.js`); it holds the common ones, not every one.

## 2. Prove it, one of three ways

**A. A record on the domain.** In the domain's DNS settings add a TXT record named `_grietens` (the full name
`_grietens.kalnagaldnieciba.example`) with the value `grietens-verify=<code>`. Grietens asks the domain's own (authoritative) name
servers directly, so a new record counts as soon as those servers have it: there is no waiting for caches.

**B. A file on the website.** Put a file at `https://kalnagaldnieciba.example/.well-known/grietens.txt` (or on `www.`) whose text holds
the code, or put `<meta name="grietens-verify" content="<code>">` in the `<head>` of the front page. It must be served over https
directly: Grietens does not follow a redirect to another host. The tag is looked for in the head only: before `</head>`, or before
`<body` on a page that does not close its head. A page that marks neither has no head to look in, so use the file there.

**C. A link by mail.** For a shop that can change neither its DNS nor its website: `POST /api/v1/company-verification/mail
{"address": "info@kalnagaldnieciba.example"}` (`send_verification_mail`, the owner's AI only). The address must be at the domain being
verified. Grietens mails one link; a person who reads that mailbox opens it and sees which company asks (as the workspace states it,
and as in the register when Grietens' directory has it), who set the workspace up, and what confirming allows, with two buttons:
**Yes, this is us** and **This is not us**. The link works 7 days. At most 3 mails per workspace and 3 per domain a day. Grietens keeps
only the address's domain and a keyed hash, never the address, and sends nothing else to it. When the server does not send mail, the
answer says so and points at A and B. A mail is sent only for a workspace whose owner has made an account (409 `no_account`
otherwise; A and B need none). The mail itself names the domain and who set the workspace up, and no name the workspace chose for
itself: the page behind the link shows those.

## 3. Check

```
POST /api/v1/company-verification/check   {}
```

(`check_company_verification`.) Grietens looks now: the file and the front page on the domain and on `www.`, and the TXT record on
the authoritative name servers, asked a few times, about 60 seconds at most in one call. The answer says what it found and by which
way, everything it looked at with the result, and the label buyers now see:

```json
{ "found": true, "way": "dns", "state": "proven",
  "company_check": { "state": "verified", "method": "domain", "domain": "kalnagaldnieciba.example", "label": "Confirmed by kalnagaldnieciba.example" },
  "looked": [ { "way": "dns", "where": "_grietens.kalnagaldnieciba.example TXT at ns1.…", "result": "found" } ] }
```

Not found yet: the answer lists each place and what it saw ("no grietens-verify record yet", "HTTP 404", "a grietens-verify tag is
there with another code"); fix that and check again. `get_company_verification` shows the state at any time.

## What each way proves, and the labels

| Way | What it proves | Label buyers see |
|---|---|---|
| A record, a file or a tag, or the mailed link | the workspace controls the domain | **Confirmed by kalnagaldnieciba.example** |
| a record, a file or a tag (never the mailed link), and Grietens' directory holds a company with the stated country and registration number whose website is on that domain | the domain belongs to that registered company | **Registered company · kalnagaldnieciba.example** |
| a person at Grietens checked the company register (`ask_company_check`, for a company with no domain) | the company is in the register | **Verified company** |

Every label is a fact that was checked, never a rating. Any of the three opens the same things: requests from the Grietens request
page and buyers' AI apps (when the engine card says `open_requests: true`), the logo and the website link. A person's check is never
replaced by a domain proof. When the legal name, registration number or country change, a domain proof stays and the register match
is worked out again.

## Keeping it

Ways A and B are re-checked every day. A proof missing on one check: the workspace gets an alert. Missing on two checks in a row: the
verification is taken away, the shop is "Not checked yet" again, the open network stops sending it requests, and the workspace gets
an alert; put the record or the file back and check again. A check that gets **no answer** (the website or the name servers are
down) is not a miss, but it cannot go on for ever: after 3 such days in a row the workspace gets one alert saying what will happen,
and after 7 in a row the verification is taken away the same way (a company that closed leaves exactly this behind, and its domain's
next owner must not inherit the label). When the site is back, start and check again. `get_company_verification` shows both counts
(`missed_checks`, `unanswered_checks`). A mailed confirmation (C) is not re-checked: the address is not kept, so it stays until the
workspace removes it or the person says "This is not us"; for that reason it is never more than "Confirmed by", and never opens a
workspace (below). `remove_company_verification` takes the shop's own verification away.

## "This is not us"

When the person at the domain presses **This is not us**: the verification of that domain for that workspace is removed, the shop
stops receiving requests from the open network (a company a person at Grietens had checked goes back to "asked" for a person to look
again), the workspace and Grietens both get an alert, and the page tells the person plainly that this was done. Nothing else is
needed from them.

## With the engine's own key

Before the shop has a login, the engine's workspace key (`POST /api/public/engine/key`) may call `get_company_verification`,
`start_company_verification` and `check_company_verification`. The mail and the removal are the owner's or his AI's.

## Getting back in with no account

A workspace an AI set up with one click has no account: it is reached only through the connections of the apps that use it. When
that connection is lost (a new chat app, a lost token, another assistant), the shop gets back in by proving its domain again, with
no account. It works only while the company is **verified by that domain** with a record, a file or a tag that Grietens' daily check
**found within the last 3 days** (a check that got no answer does not count, and a verification by a mailed link never opens a
workspace) and **nobody has made an account** for the workspace.

1. Connect the assistant again the usual way: "I'm new to Grietens" makes a fresh, empty workspace for this new connection.
2. From that connection, `start_workspace_recovery {"domain": "kalnagaldnieciba.example"}`. It answers a **fresh** code for this
   connection, valid 30 minutes, and three places for it, any one enough. They are not the verification's places, so leave those as
   they are:
   - the TXT record `_grietens-recover.kalnagaldnieciba.example` with the value `grietens-recover=<code>`;
   - the file `https://kalnagaldnieciba.example/.well-known/grietens-recover.txt` (or on `www.`) holding the code;
   - the tag `<meta name="grietens-recover" content="<code>">` in the front page's head.
   The answer is the same whether or not a workspace exists for the domain.
3. `check_workspace_recovery {}` looks for it the same way step 3 looks (the domain's own name servers asked directly, the website
   through Grietens' guarded fetch, about a minute at most). Found, and exactly one workspace is verified by that domain and has no
   account: **this connection is moved into it**, and from the next call every tool works there. The answer names the workspace.
   The apps already connected there keep working. The empty workspace of step 1 is deleted; if anything was put in it (a request, a
   quote, a file), it is kept and the answer says so.

What is never done: a workspace with an account is never opened by a domain (the answer says it is opened by signing in, and a
lost password is reset for that account); the verification's own record alone never opens anything (the fresh code must be found);
the fresh code alone never opens anything (the workspace must be verified by the same domain today); with more than one workspace
verified by the domain nothing is moved and Grietens' staff are told. Only an AI app's own connection can be moved: a service key
stays in its workspace. Each outcome after a found code is an alert in the workspace concerned ("An AI app got back into this
workspace by proving kalnagaldnieciba.example"), an entry in its audit log and a note to Grietens' staff. Starting and checking are
limited per connection, per address, and per domain for each address (so nobody uses up a company's own tries for its domain). Remove the recovery code's record or file afterwards; keep the verification's.
