# How ProperTrust works

ProperTrust is a neutral record keeper for agreements. It does three things:

1. **It freezes a wording.** The text of a contract is rendered to a PDF, hashed with SHA-256, stored encrypted, and the hash is anchored in the Bitcoin blockchain. From that moment nobody, including ProperTrust, can change the wording without the hash changing.
2. **It runs the signature round.** Every party is invited, reads the wording clause by clause, confirms each clause, and signs. Each step is recorded with its time.
3. **It issues the result.** When all parties have signed, the signatures are frozen in a signature bundle, the bundle is anchored too, and every party receives a numbered edition.

You, the agent, act for one account, the **owner** of the agreements you create. You prepare, send, follow and report. You never sign: a signature is given personally by each party.

## The objects

| Object | What it is |
|---|---|
| **Document** | A file in the encrypted vault with its SHA-256 and its anchors. Every agreement has one; you can also deposit documents on their own as timestamps. |
| **Agreement** | A document plus a signature round. Status: `collecting`, `completed` or `cancelled`. |
| **Party** | One seat in the round: a person or company that is to sign. Status: `invited`, `joined`, `read`, `signed`. The owner is always the first party. |
| **Clause** | A section of the wording. Parties confirm clauses one by one ("read and understood"). |
| **Signature** | The recorded acceptance of one party: method, time, identity level, hash. |
| **Bundle** | The canonical JSON record of a completed round: document hash, parties, read receipts, signatures. It is hashed and anchored. |
| **Edition** | The numbered copy of a completed agreement that belongs to one party ("Edition 2 of 3"). |
| **Anchor** | The proof that a hash existed at a time: an OpenTimestamps proof that ends in a Bitcoin block. |
| **Verification code** | The short code printed with a QR on the PDF. Anyone holding the paper can check the status at `https://propertrust.com/d/<code>`. |

## The life of an agreement

```
wording ──► agreement_create ──► collecting ──► every party: invited → joined → read → signed ──► completed
              (PDF, hash,          (invitations by e-mail            (clause by clause)          (bundle, anchor,
               vault, anchor)       and, with a handle, Telegram)                                 one edition each)
```

- `collecting` → `completed` happens by itself when the last party signs. If the round was created with `open_for_parties`, it stays open until the owner calls `agreement_close`.
- `collecting` → `cancelled` only by the owner (`agreement_cancel`). A cancelled agreement cannot be reopened; its document and timestamp stay on the record.
- A frozen wording cannot be edited. To change a word, cancel and create a new agreement.

## What a key can do

A key acts as the account that created it and sees what that account sees in the panel. It has up to three scopes:

- `read`: templates, agreements, documents, proofs. Every key has it.
- `write`: create agreements, invite and remove parties, remind, close, cancel, deposit documents, trigger the Telegram bot.
- `content`: read the wording of agreements and download files.

No scope allows signing, confirming a clause, or reading on behalf of a party. Reading a wording through the API never counts as a read receipt.

## Before you act for somebody

- Creating an agreement, adding a party and reminding **send messages to other people** (e-mail, and Telegram when you pass a handle). Confirm with your principal before you call them.
- Composed wordings come from a clause library. They are an aid, not legal advice. Say so when you present one.
- Titles travel: the title of an agreement appears in invitation e-mails and Telegram messages. Keep confidential facts out of titles. See the topic `confidentiality`.

## Where to read on

| Topic | Read it when |
|---|---|
| `contracts` | you need to get a wording into ProperTrust |
| `distribution` | you need to bring it to the parties |
| `signatures` | you need to know what comes back and what it proves |
| `confidentiality` | you handle anything sensitive |
| `telegram` | a party is to be reached through Telegram |
| `recipes` | you want the sequence of calls for a common task |
| `errors` | a call was refused |

---

# Getting a contract in

`agreement_create` takes a wording from exactly one of four sources and starts the signature round. Choose the source by what you have.

| You have | Source | What you get |
|---|---|---|
| A standard contract the account uses again and again | `template` + `variables` | The account's own wording with the blanks filled |
| The facts of a deal, but no text | `contract_compose` → `draft` | A wording built from the clause library, reviewed by a human before it is frozen |
| A finished text | `wording` (Markdown) | Exactly your text, split into clauses |
| A finished file (PDF, scan, Word export) | `file_base64` + `filename`, or a multipart upload | The file as it is, signed as a whole |

## 1. From a template

`templates_list` shows the library of the account. Each template has a `key` (for example `shop.product-x`) and `variables`, the names it needs.

```json
{
  "template": "shop.product-x",
  "variables": { "product": "Concrete mixer M200", "price": "CHF 900" },
  "parties": [ { "name": "Jane Buyer", "email": "jane@example.com", "role": "Buyer" } ]
}
```

- Every variable must have a value, otherwise the call is refused with the list of missing names.
- These fill themselves: `date`, `title`, `party1_name`, `party1_role`, `party1_email`, and the same for party 2 and 3. Party 1 is the owner.
- Identity level and letterhead come from the template.

## 2. From the facts of a deal

`contract_compose` builds a wording from structured input: contract type, parties, governing law, forum, and the fields of that type (amount, scope, dates and so on). `catalog` lists every allowed value and which fields belong to which type.

No language model is involved in composing. The clauses are fixed texts from the ProperTrust clause library, chosen by contract type, legal system and forum. The same input gives the same wording.

```json
{
  "contract_type": "service",
  "title": "Website relaunch",
  "governing_law": "ch",
  "parties": [
    { "name": "Miller AG", "entity_type": "company", "country": "Switzerland", "representative": "Anna Miller" },
    { "name": "Bob Works GmbH", "entity_type": "company", "country": "Germany", "email": "bob@example.com" }
  ],
  "fields": { "amount": 12000, "currency": "CHF", "scope": "Design and build of the new website", "payment_terms": "50 % on signing, 50 % on delivery" },
  "save_draft": true
}
```

- Without `save_draft` the call only returns the Markdown; nothing is stored.
- With `save_draft` (write scope) the wording is stored as a draft. Your principal can open the returned `url`, read and edit it in the panel. This is the recommended path: **a human reads the wording before it is frozen.**
- Then call `agreement_create` with `"draft": "<id>"`. A draft can be turned into an agreement once.
- Languages of the clause library: English and German.

## 3. From your own text

Pass Markdown in `wording` and a `title`.

```markdown
## 1. Subject
The Seller sells the concrete mixer M200 to the Buyer for CHF 900.

## 2. Delivery
Within 14 days at the Buyer's site.

## 3. Governing law
Swiss law applies. Place of jurisdiction is Zurich.
```

How the text becomes clauses:

- Every line that starts with `## ` opens a new clause. The heading is the clause title; number it yourself if you want numbers.
- Text that stands before the first `## ` (parties, recitals) becomes one first clause called "Parties and recitals". If there is nothing there but the title, there is no such clause.
- A text without any `## ` is one single clause.
- If the text has no `# Title` line, the title is put on top.
- Bold, italics, lists and tables in Markdown are rendered in the PDF. HTML is stripped.

Write the parties into the text yourself: who they are, with address and role. The list in `parties` decides who is invited; it does not change the wording.

## 4. From a finished file

Pass the file as `file_base64` with a `filename`, or send it as multipart form data in the part `file` (REST). A `title` is required.

- The file is stored exactly as it is. Its SHA-256 is the hash of the bytes you sent, so everybody who holds the same file can check it.
- There are no clauses: each party confirms once that it has read the whole document, then signs.
- No verification block is printed into your file. The verification code is in the answer; print it yourself if the paper should carry it.

## What happens when you call `agreement_create`

1. The wording is rendered to a PDF (sources 1 to 3) on the account's letterhead, with a verification block at the end: QR code, link and code.
2. The PDF is hashed, encrypted and stored. The hash goes to the Bitcoin anchor queue.
3. The agreement is created in status `collecting`. The owner is the first party and has status `joined`.
4. Every other party gets a seat with status `invited` and a personal join link. Parties with an e-mail get the invitation by mail. Parties with a Telegram handle are contacted by the bot, see `telegram`.
5. The answer contains the id, `document_sha256`, `verify_code`, `verify_url`, and for every invited party `join_url` and `telegram_start_link`.

## Options

| Argument | Effect |
|---|---|
| `parties` | The other parties: `name`, and `email` and/or `telegram`, optional `role`. The owner is added by itself. May be empty for sources 2 to 4: parties can be added later. |
| `message` | A note shown in the invitation. |
| `pin` | 4 to 8 digits. With it, somebody who holds the paper and the PIN sees wording and parties on the public check page. Without it, the page shows status and hash only. |
| `require_level` | Identity level every signer needs. Default 1 (verified e-mail). During the beta, higher levels are granted by hand only, so a higher value can make an agreement unsignable. |
| `open_for_parties` | Keep the round open: parties can be added after others signed, and the agreement completes only on `agreement_close`. |
| `language` | `en` or `de`: language of the verification block when you pass `wording`. |
| `idempotency_key` | Send the same value again within 24 hours and you get the first agreement back instead of a second one. Use the order number or another id of your own. |

## After freezing

- The wording cannot be changed. `agreement_cancel` and a new `agreement_create` is the only way to correct it.
- The owner still has to sign too. The owner reads and signs in the panel (https://propertrust.com/app) or in Telegram like every other party; a key cannot do it.
- `agreement_wording` (content scope) returns the frozen clauses; `GET /v1/agreements/{id}/document` returns the PDF.

---

# Bringing it to the parties

A party has to do four things: open its invitation, have a ProperTrust account, read the wording, sign. This page says how the invitation reaches it and how you follow the round.

## The three ways an invitation travels

| Way | You pass | What ProperTrust does |
|---|---|---|
| **E-mail** | `email` of the party | Sends the invitation with the personal join link. |
| **Telegram, one to one** | `telegram` handle of the party | The bot writes to the party if it may, and gives you a start link if it may not. The party reads and signs in the private chat with the bot. See `telegram`. |
| **You pass the link on** | nothing more | The answer of `agreement_create` and `agreement_get` holds a `join_url` (website) and a `telegram_start_link` (bot) for every invited party. Send either through any channel your principal uses. |

A party may have both an e-mail and a handle; it is then contacted on both and uses whichever it likes. The links are personal: whoever opens a link first takes that seat. Send each link to its party only.

A fourth way exists for parties that sit together in a Telegram group the bot moderates: `telegram_moderate` runs the whole round in that group. See `telegram`.

## What the party goes through

1. **Open.** The join link leads to a page that names the sender and the title.
2. **Account.** Without an account the party registers there. An invited party needs no beta code. It must confirm its e-mail address, which gives identity level 1.
3. **Join.** The seat is bound to the account. Party status: `joined`.
4. **Read.** The party confirms every clause one by one ("read and understood"). It can ask for an explanation of a clause in its own language. When all clauses are confirmed, the read receipt is complete. Status: `read`. For a wording without clauses, the party opens the document and confirms that it read it.
5. **Sign.** The party accepts the agreement as a whole. Status: `signed`.

Signing before reading is refused. A party whose identity level is below `require_level` cannot sign.

## Following the round

`agreement_get` is the one call to poll. Per party it returns:

- `status`: `invited`, `joined`, `read` or `signed`
- `acknowledged_clauses`: how many clauses are confirmed so far
- `joined_at`, `read_at`, `signed_at`
- `signature`: the signature record once signed, see `signatures`
- `telegram`: handle and whether the bot has written or the party has opened the chat
- for the owner only: `email`, `join_url`, `telegram_start_link`

And for the agreement: `status`, `signed` (count), `anchored`, and after completion `bundle_sha256` and `editions`.

There are no webhooks yet. Poll at a calm pace: every few minutes while you wait for people, not every second. The rate limit is per key.

## Changing the round

| Call | Use it to |
|---|---|
| `agreement_add_party` | invite a further party while the agreement is `collecting`. Needs `name` and `email` or `telegram`. With `notify: false` no message is sent and you pass the link on yourself. |
| `agreement_remove_party` | remove a party that has not read or signed. A party that has read or signed stays on the record. |
| `agreement_remind` | send the invitation again to every party still `invited`: by mail, and through the bot for parties with a handle. The bot writes to the same party at most every six hours. |
| `agreement_set_pin` | set or remove the PIN of the public check page. |
| `agreement_close` | complete a round that was kept open with `open_for_parties`. Works when every current party has signed. |
| `agreement_cancel` | end a round that is still collecting. Final. |

Only the owner changes an agreement. A key of another party can read the agreement once that party has joined, and nothing more.

## When a party does not want to sign

On the website a party simply does not sign; you see it stay at `joined` or `read`. In Telegram a party can press "I do not sign": it is then removed from the round and appears under `declined` in `agreement_get` with its name and the time. The owner decides what follows: change the deal and start a new agreement, or go on with the remaining parties.

## Completion

When the last party signs (or on `agreement_close`):

- the signature bundle is written, hashed and queued for anchoring,
- every party gets its edition and an e-mail with the link; parties in Telegram get the link there too,
- `agreement_get` shows `status: completed`, `bundle_sha256`, `bundle_proof_url` and the `editions`.

Tell your principal at this point, with the `verify_url`. That link is what anybody can use later to check the document.

---

# What comes back: read receipts, signatures, bundle, editions, anchors

Everything a round produces is a record with a time and a hash. This page lists the records, where you find them, and what each one proves.

## 1. The document hash

`document_sha256` is the SHA-256 of the frozen PDF (or of the file you uploaded). It is in the answer of `agreement_create` and never changes. Whoever holds the file can compute the hash and compare. `proof_lookup` answers for any hash whether and since when it is registered.

## 2. The read receipt

For a wording with clauses, each party confirms each clause separately. Stored per party: the time of every single confirmation, and when the last clause was confirmed, a read receipt with the document hash and the number of clauses. For a file without clauses, the receipt records that the party opened the whole document.

In `agreement_get` you see `acknowledged_clauses` and `read_at` per party.

## 3. The signature

A party signs after its read receipt is complete. The signature is the party's authenticated declaration that it accepts the agreement as a whole. In `agreement_get`, once a party has signed:

```json
"signature": {
  "method": "pt-click",
  "at": "2026-11-27T09:14:03+00:00",
  "identity_level": 1,
  "acknowledged_clauses": 11,
  "hash": "5f0c…"
}
```

| Field | Meaning |
|---|---|
| `method` | `pt-click`: signed on the website while signed in. `pt-telegram`: signed with a button in the private chat with the ProperTrust bot, from the Telegram account connected to the party's ProperTrust account. |
| `at` | Time of the signature, UTC. |
| `identity_level` | What ProperTrust had verified about the signer at that moment: 1 e-mail address, 2 payment card, 3 identity document, 4 established business. |
| `acknowledged_clauses` | How many clauses the party had confirmed. Equals the clause count of the agreement. |
| `hash` | SHA-256 over `agreement id | party id | account id | document hash | time`. It ties this signer to this document at this time. |

Stored with the signature, but not returned by the API: for `pt-click` the IP address and browser, for `pt-telegram` the Telegram user id, the id of the button press and the message id. They are kept as evidence for the case that a signature is disputed.

**What kind of signature it is.** A ProperTrust signature is an electronic signature based on the account and the declaration of the signer. It is not a qualified electronic signature and not a notarial deed. Where the law requires a particular form (for example written form for some guarantees, or a notary for real estate), this signature does not replace it. Say this to your principal when the contract type may need a form; do not decide the legal question yourself.

## 4. The signature bundle

When the round completes, ProperTrust writes one canonical JSON document, the bundle:

```json
{
  "propertrust_bundle": 2,
  "agreement_id": "01…",
  "title": "Website relaunch",
  "document": { "sha256": "…", "size": 97352, "first_seen_at": "…", "clauses": 11 },
  "parties": [
    { "party_id": "01…", "name": "Miller AG", "identity_level": 1, "joined_at": "…", "read_at": "…",
      "acknowledged": { "0": "…", "1": "…" }, "signed_at": "…", "signature_hash": "…", "method": "pt-click" }
  ],
  "completed_at": "…"
}
```

- `bundle_sha256` in `agreement_get` is the SHA-256 of exactly this JSON text.
- `agreement_bundle` returns the bundle, both parsed and as the exact text (`bundle_json`), so you can hash it yourself.
- The bundle is stored in the vault and anchored like every document. `bundle_proof_url` is its public proof page.
- The bundle holds names, times and hashes. It does not hold the wording.

The bundle is the answer to "who signed what, when": the document hash says what, the party entries say who and when, and the anchor says that this record existed at that time and was not changed since.

## 5. The editions

Each party gets one edition of the completed agreement: "Edition 1 of 3", "Edition 2 of 3". An edition is the party's own certificate page of the completed agreement. `editions` in `agreement_get` lists them with their `url`; a party has to be signed in to open its edition.

## 6. The anchors

An anchor is an OpenTimestamps proof for a hash.

| `status` | Meaning |
|---|---|
| `pending` | queued |
| `submitted` | sent to the OpenTimestamps calendars, waiting for a Bitcoin block |
| `confirmed` | included in a Bitcoin block; `bitcoin_block` and `confirmed_at` are set |

Confirmation usually takes a few hours. Nothing depends on it for signing: the round runs while the anchor matures. `document_get` and `proof_lookup` show the anchors; `ots_url` downloads the proof file, which anybody can verify with an OpenTimestamps client against the Bitcoin blockchain, without ProperTrust.

Only the hash is anchored. No name, no title and no content go on a blockchain.

## 7. The verification code

Every agreement has a `verify_code` and a `verify_url` (https://propertrust.com/d/CODE). The page shows who issued the document, the state of the round, the hash and the anchor. With the PIN, or signed in as a party, it also shows the wording and the parties. `verify_code` gives you the same as the page without the PIN.

## Reporting to your principal

A complete report on a finished agreement contains: title, the parties with `signed_at` and `method`, `document_sha256`, `bundle_sha256`, the anchor state, and the `verify_url`. Do not call an agreement "signed" before `status` is `completed`, and do not call it "anchored in Bitcoin" before `anchored` is set.

---

# Confidentiality: who sees what

Read this before you put anything sensitive into a call. It says where content is stored, what is public, what travels in messages, and what you should keep out.

## Where the content is

- Every document is encrypted before it is stored: its own key (XChaCha20-Poly1305), and that key wrapped with the key of the application. The unencrypted upload is deleted right after.
- This is encryption at rest. ProperTrust operates the keys and can decrypt for the people who are entitled: the owner and the parties. It is not end-to-end encryption between the parties.
- Clauses of a structured wording are stored with the agreement so that parties can confirm them one by one.

## What is public

Three pages can be opened by anybody who has the right value. None of them shows content.

| Page | Who can open it | What it shows |
|---|---|---|
| Proof page `https://propertrust.com/p/<sha256>` | whoever knows the hash, so in practice whoever holds the file | hash, time of the first deposit, public name and identity level of the depositor, kind of document, anchors. The title only if you set `public_title`. |
| Check page `https://propertrust.com/d/<code>` | whoever holds the paper or the code | issuer with identity level, date, status of the round, how many of how many signed, hash, anchor. With the PIN: also wording and parties. |
| Public profile `https://propertrust.com/u/<handle>` | everybody, if the account set a handle | identity badges and counts. No contact data, no titles. |

Consequences for you:

- A hash does not reveal content, but it identifies a file. Do not publish hashes of documents whose existence is confidential.
- The name of the account appears as depositor and as issuer. An account that must stay unnamed should set a neutral display name in the panel.
- Leave `public_title` off unless the title is meant to be seen.
- Set a `pin` when the paper travels and holders should be able to read the wording; give the PIN to them separately. Leave it off when the check page should show the status only.

## What goes on the blockchain

Only SHA-256 hashes, aggregated through OpenTimestamps. No name, no title, no content, no personal data. A hash cannot be turned back into the document.

## What travels in messages

| Message | Contains |
|---|---|
| Invitation e-mail | name of the owner, title of the agreement, your `message`, the personal join link |
| Completion e-mail | title, link to the edition |
| Telegram invitation from the bot | name of the owner, title, buttons |
| Telegram private chat while a party reads | the full wording, clause by clause, and the PDF |
| Telegram group round | the PDF and every clause, posted in the group |

- **Titles and messages are not confidential.** Write "Service agreement 2026-11" rather than "Settlement of the Miller patent dispute".
- **Telegram is not end-to-end encrypted for bots.** A wording read in Telegram passes through Telegram's servers. For a wording that must not leave ProperTrust, do not pass handles; use e-mail, where the party reads on the website.
- **Links are keys to a seat.** `join_url` and `telegram_start_link` let the first person who opens them take that seat. Send each to its party only, and do not log them.

## What the other parties see

A party sees the whole wording, the names of all parties and their progress. It does not see the e-mail addresses of the others, the join links, or the owner's note to somebody else. An invited party that has not joined yet sees nothing through the API.

## What your key exposes

- A key without the `content` scope gets titles, names, statuses and hashes, but neither wording nor files. Ask for a key with `content` only if your task needs to read text.
- Every call that changes something is logged for the owner with the name of the key: operation, time, result.
- Treat the key like a password. It acts as the account.

## Artificial intelligence inside ProperTrust

- Composing a contract uses no language model.
- "Explain this clause" does: when a party asks for an explanation, that clause is sent to Anthropic's Claude and the answer is shown to the party and kept for the next reader. This happens only on the party's request, clause by clause.
- Nothing is sent to a model because you called the API.

## What stays

- A cancelled agreement keeps its document and its timestamp. The record that a wording existed cannot be withdrawn.
- A record that other parties rely on stays even when one party leaves.

## Rules of thumb for an agent

1. Put facts into the wording, not into the title, the message or a file name.
2. Do not copy wording, links or PINs into logs, tickets or chats outside the task.
3. Use the smallest key that does the job.
4. If your principal says "confidential", choose e-mail over Telegram and leave `public_title` off.
5. If you are unsure whether something may be sent, ask before you call `agreement_create`.

---

# Telegram: when and how the bot is triggered

The ProperTrust bot is @propertrustservicebot. It can do two things for an agreement: invite single parties and let them read and sign in the private chat, or run the whole round in a group. You trigger the first by passing Telegram handles, the second with `telegram_moderate`.

## When to use it

Use Telegram when the party is easier to reach there than by e-mail, when you have no e-mail address at all, or when the parties already talk in a Telegram group. Do not use it for a wording that must stay inside ProperTrust: what the bot shows passes through Telegram (see `confidentiality`). When in doubt, pass the e-mail only.

## One to one: pass the handle

Give a party a `telegram` handle in `agreement_create` or `agreement_add_party`. `@jane_buyer`, `jane_buyer` and `t.me/jane_buyer` are all accepted. An `email` next to it is optional.

```json
{
  "title": "Purchase of concrete mixer M200",
  "wording": "## 1. Subject\n…",
  "parties": [ { "name": "Jane Buyer", "telegram": "@jane_buyer" } ]
}
```

The bot is triggered at once, and the answer tells you per party what happened, under `telegram`:

```json
"telegram": [
  { "party_id": "01…", "name": "Jane Buyer", "telegram": "@jane_buyer",
    "status": "needs_start_link",
    "start_link": "https://t.me/propertrustservicebot?start=p_…",
    "note": "The bot has never talked to this Telegram account, and Telegram does not let a bot write first. Pass the start link on; the bot takes over when the person opens it." }
]
```

| `status` | Meaning | What you do |
|---|---|---|
| `contacted` | The bot knows this account and has sent the invitation into the private chat. | Nothing. Poll `agreement_get`. |
| `needs_start_link` | The bot may not write to this account: the person never opened a chat with the bot, or blocked it. | Give the `start_link` to your principal to send to that person, in Telegram or any other way. The bot takes over the moment the person opens it. |

This limit is Telegram's, not ours: **a bot cannot start a conversation.** It is the normal case for somebody who has never used ProperTrust. So always be ready to hand out the start link.

The start link is personal like the join link: the first Telegram account that opens it takes the seat.

### What the party sees in the private chat

1. The invitation: who invites, the title, a button "Read and sign here" and a button to the website.
2. The ProperTrust terms, to accept with a button (once per Telegram account).
3. A link to connect or create a ProperTrust account (once). The party registers without a beta code and confirms its e-mail.
4. The wording, one clause per message, each with "Read and understood" and "Explain this clause".
5. The signature prompt with the document hash: "I agree and sign" or "I do not sign".
6. After completion: the link to its edition.

The party can stop and continue later with `/sign` in the chat, or switch to the website at any point; both show the same state.

### What you see

In `agreement_get`, per party: `telegram.handle`, and `telegram.state`: `not_contacted`, `contacted` (the bot wrote), `opened` (the party opened the chat and the seat is bound to that Telegram account), then the normal `status` moves through `joined`, `read`, `signed`. A signature given this way has `method: pt-telegram`.

If the owner's own account is connected to Telegram, the bot also tells the owner in the private chat when a party signs or declines.

### Triggering again

- `telegram_invite` runs the bot again for one agreement: it writes to parties it has not written to yet, and returns the status and start link of every party with a handle. With `again: true` it also repeats the invitation to parties that were contacted before.
- `agreement_remind` reminds by e-mail and through the bot.
- The bot writes to the same party at most once in six hours, however often you call.

Trigger the bot when it is needed, not on a timer: after creating the agreement (automatic), after you learn that a party has now opened the bot, and for a reminder your principal asked for.

## In a group: `telegram_moderate`

When all parties sit in one Telegram group, the bot can run the round there: it posts the PDF and every clause into the group, each member confirms and signs in the private chat, and the group sees who has signed.

Conditions:

1. The bot is a member of the group, and every member has accepted the terms in the private chat with it. `telegram_groups` shows the groups of the account and `on_the_record: true` when that is done.
2. The account behind your key is connected to Telegram and is a member of that group.
3. The agreement is `collecting` and owned by that account.

Then call `telegram_moderate` with the group id from `telegram_groups` and the agreement id. The bot writes into the group at once. The members of the group become the parties; they need no e-mail invitation.

The bot cannot be added to a group through the API. A person adds it in Telegram.

## What the bot never does

- It does not sign for anybody and does not count silence as consent.
- It does not write to an account that never opened a chat with it.
- It does not show a wording to a Telegram account that does not hold a seat.

## Evidence

A step taken in Telegram is recorded with the Telegram user id, the id of the button press and the message id, next to the time and the document hash. In a moderated group, the chat itself is kept as a hash-chained record that members can export. Identity in Telegram rests on the Telegram account and the ProperTrust account connected to it; the handle alone proves nothing, and handles can change. If it matters who exactly signs, raise `require_level` or use e-mail to an address your principal knows.

---

# Recipes

Sequences of calls for common tasks. Tool names are the MCP names; in REST the same operations live under `https://api.propertrust.com/v1` (see the reference).

## Check the connection

1. `pt_whoami` → the account, its identity level, the scopes of your key.
2. If `identity.may_create_agreements` is false, stop and tell your principal: the account must confirm its e-mail first.

## Timestamp a file

1. `pt_document_deposit` with `title` and the content (`text`, or `content_base64` with `filename`).
2. Report `sha256` and `proof_url`. The anchor is `pending` now.
3. Later: `pt_document_get` → `anchors[0].status` is `confirmed` with the Bitcoin block.

To check a file without uploading it: compute its SHA-256 yourself and call `pt_proof_lookup`.

## An NDA between your principal and one other company, by e-mail

1. `pt_catalog` → look up `contract_types.nda` and the `governing_laws` key your principal wants.
2. `pt_contract_compose` with `contract_type: "nda"`, a title, both parties with name, country and address, a `purpose`, and `save_draft: true`.
3. Show your principal the wording (or the draft `url`) and wait for a yes. Say that it is standard wording and not legal advice.
4. `pt_agreement_create` with `draft: <id>` and `idempotency_key`. If the other party's e-mail was not in the draft, pass `parties: [{name, email}]`.
5. Tell your principal: the invitation is sent, and they themselves still have to read and sign in the panel.
6. `pt_agreement_get` from time to time. When `status` is `completed`, report with `verify_url`, and `pt_agreement_bundle` if they want the record.

## A sale from the shop: template and order number

1. Once: your principal saves the contract as a template with a key, for example `shop.product-x`, in the panel.
2. Per order: `pt_agreement_create` with `template`, `variables`, the buyer as party, and `idempotency_key` = the order number. A repeated call for the same order returns the same agreement.
3. Store the returned `id` with the order. Poll `pt_agreement_get` until `completed`.

## A party you can reach only on Telegram

1. `pt_agreement_create` with the wording and `parties: [{ "name": "Jane Buyer", "telegram": "@jane_buyer" }]`.
2. Look at `telegram[0].status` in the answer.
   - `contacted`: the bot has written to her. Done.
   - `needs_start_link`: give `telegram[0].start_link` to your principal with a sentence like "Please send Jane this link; the ProperTrust bot will show her the contract." Do not send it anywhere yourself unless your principal told you where.
3. `pt_agreement_get` → `parties[].telegram.state` goes to `opened`, then `status` to `joined`, `read`, `signed`.
4. If nothing happens and your principal asks for a reminder: `pt_agreement_remind`.

## A crew that already talks in a Telegram group

1. `pt_telegram_groups` → find the group; it must show `on_the_record: true`. If it does not, the members still have to accept the terms in the private chat with the bot: tell your principal.
2. `pt_agreement_create` with the wording and no parties.
3. `pt_telegram_moderate` with the group id and the agreement id. The members of the group become the parties.
4. `pt_agreement_get` until `completed`.

## Somebody sent your principal a ProperTrust document

1. Read the code next to the QR on the document.
2. `pt_verify_code` → issuer, status, how many signed, hash, anchor.
3. If you have the file: compute its SHA-256 and compare it with `document_sha256`. Equal means it is the registered version, byte for byte.
4. Report what is confirmed and what is not. A code that is `registered: false` is not a ProperTrust document.

## An existing PDF that only needs signatures

1. `pt_agreement_create` with `title`, `file_base64`, `filename` and the parties.
2. The parties confirm once that they read the document, then sign. There are no clauses.

## Correct a mistake in a frozen wording

1. `pt_agreement_cancel` on the wrong one. Tell the parties why; they already got an invitation.
2. Create the corrected agreement. Use a new `idempotency_key`.

## Add somebody later

1. Create the agreement with `open_for_parties: true`.
2. `pt_agreement_add_party` whenever a further party is known.
3. When everybody has signed: `pt_agreement_close`. Only then the agreement completes.

---

# Errors and limits

## How errors look

REST answers with an HTTP status and a JSON body. `error` is a stable word you can test for, `message` is a sentence for people, `details` names fields when there are any.

```json
{ "error": "invalid_input", "message": "\"contract_type\" must be one of: nda, service, …", "details": { "contract_type": ["…"] } }
```

As MCP tools, the same errors come back as a tool result with `isError: true` and the text `Error (<error>): <message>`. Protocol errors (unknown method, unknown tool, broken JSON) are JSON-RPC errors.

| Status | `error` | Meaning | What to do |
|---|---|---|---|
| 401 | `missing_api_key`, `invalid_api_key` | No key, or it is unknown, revoked or expired. | Ask your principal for a valid key. Do not retry. |
| 403 | `scope_missing` | The key lacks the scope the operation needs. `details.needs` names it. | Ask for a key with that scope, or do without. |
| 403 | `forbidden` | Only the owner of the agreement may do this. | Stop. |
| 403 | `level_too_low`, `email_not_verified` | The account's identity level does not allow it yet. | Tell your principal to confirm the e-mail address. |
| 404 | `not_found`, `template_not_found` | Nothing with this id for this account. An agreement of somebody else looks the same as one that does not exist. | Check the id. |
| 409 | `conflict` | The state does not allow it: already completed, already cancelled, party already signed, draft already used. The message says which. | Read the state with `agreement_get` and decide again. |
| 409 | `not_completed` | The bundle exists only after completion. | Wait. |
| 409 | `not_connected` | The account is not connected to Telegram. | Your principal sends `/connect` to the bot. |
| 409 | `in_progress` | A call with the same idempotency key is still running. | Wait a few seconds and repeat with the same key. |
| 413 | `too_large` | The file is too large for this way of transfer. | Use the REST download or a multipart upload. |
| 422 | `invalid_input` | An argument is missing or wrong. | Correct it. |
| 422 | `cannot_create` | The agreement could not be built, for example template variables are missing. | The message lists what is missing. |
| 429 | `rate_limited` | Too many calls with this key. | Wait for `Retry-After` seconds. |
| 5xx | | A failure on our side. | A writing call may or may not have happened: read the state before you repeat it, or repeat with the same idempotency key. |

## Limits

- 120 calls a minute per key. The headers `X-RateLimit-Limit` and `X-RateLimit-Remaining` show where you stand.
- Up to 25 other parties per call; more can be added afterwards.
- A wording up to 200 000 characters. A file up to 48 MB by multipart upload, about 11 MB as base64.
- `document_content` as a tool returns files up to 5 MB; larger ones through `GET /v1/documents/{id}/content`.
- The bot writes to the same party at most once in six hours.
- Lists are paged with `limit` (up to 100) and `page`; `has_more` says whether another page exists.
- Times are ISO 8601 in UTC.

## Idempotency

Writing calls accept an idempotency key: the header `Idempotency-Key` in REST, the argument `idempotency_key` as a tool. A second call with the same key and the same key holder within 24 hours returns the first result with `"idempotent_replay": true` and creates nothing. Use it on every `agreement_create` and `document_deposit` that might be retried, with an id from your own system.

## What a writing call sets in motion

| Call | Outside effect |
|---|---|
| `agreement_create` | e-mail to every party with an address; a Telegram message to every party with a handle the bot may write to |
| `agreement_add_party` | the same for that party, unless `notify` is false |
| `agreement_remind`, `telegram_invite` | messages to parties that have not joined |
| `telegram_moderate` | the bot posts into the group |
| `agreement_cancel` | nothing is sent; inform the parties yourself |
| `document_deposit` | nothing is sent; the hash is anchored |

Ask your principal before the first four.
