# Protocol

Use the aSecret 0.2 protocol to implement a compatible client or server for encrypted secrets and user-approved details.

## What it covers

- **Agent secrets.** An agent registers with no account and keeps its secrets as sealed items: `POST /v1/agents`, then `/v1/items` with its `ast_` token. [agent-secrets.md](https://github.com/asecret-org/protocol/blob/main/spec/0.2/agent-secrets.md)
- **Linking a person.** A link code the person approves at asecret.sh (`POST /v1/me/link-code`), and the agent's key sealed to their recovery key (`PUT /v1/me/escrow`).
- **Asks.** A linked agent asks its person with `POST /v1/requests`, reads the outcome with `GET /v1/requests/{id}`, and cancels with `POST /v1/requests/{id}/cancel`.
- **A person's own server.** Owner connections, saving a payment method with a participating merchant, and deliveries to merchants, which a self-hosted aSecret server offers. [PROTOCOL.md](https://github.com/asecret-org/protocol/blob/main/PROTOCOL.md)

## The hosted API

```sh
curl https://api.asecret.sh/.well-known/asecret
```

Discovery lists the profiles api.asecret.sh offers (`agent-storage`, `person-link`, `agent-http`, `save-detail`, `setup-invitation`, `share-detail`), the kinds of detail an agent can ask to save and to use, and its limits. Calls take `Authorization: Bearer ast_…` and may send `asecret-version: 0.2`. A value is sealed before it's sent, as `application/asecret-item` or JSON; the API never sees one in the clear. While your user has turned on agent recovery and holds no copy of the agent's key, each answer carries `asecret-escrow: wanted`.

An ask to api.asecret.sh is `details.save`, `details.request_setup` or `details.share`. A `details.share` ask carries a `public_key` the agent made for that ask alone, and, if it likes, a `purpose` the person sees. The person's browser seals the detail to that key, so the agent reads it sealed in the ask's outcome and opens it on its own machine. `POST /v1/requests/{id}/received` then says it has it, and the sealed copy goes; one nobody collects goes after a day.

## From code

```sh
npm i @asecret/sdk
pip install "asecret-sdk @ git+https://github.com/asecret-org/clients.git#subdirectory=python"
```

`@asecret/sdk/crypto` seals and opens secrets exactly as the CLI does, and the SDKs make the protocol's calls with typed answers. [asecret-org/clients](https://github.com/asecret-org/clients)

The specification, its JSON schemas, test fixtures and an interoperability runner are in [asecret-org/protocol](https://github.com/asecret-org/protocol), under the MIT License.
