# Connect a device: account, agreement and enrolment

Calls go to https://supply.coronium.ai: each block sets `SUPPLY` to it unless you exported `SUPPLY`. The blocks use curl, jq and sha256sum and keep every answer in a file only you can read. A device carries other people's web traffic, so enrol one only when its owner, and whoever pays for its connection, agreed. Each device earns the same published share, whoever enrolled it.

## Steps

1. Sign up once, then sign in.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
[ -e coronium-account.json ] || curl -sS -c coronium.cookies -H 'Content-Type: application/json' -d '{}' "$SUPPLY/app/api/signup" -o coronium-account.json
jq -c '{code: ((.accessCode | strings | select(. != "")) // error("no accessCode in coronium-account.json"))}' coronium-account.json > coronium-login.json &&
curl -sS -c coronium.cookies -H 'Content-Type: application/json' -d @- "$SUPPLY/app/api/login" < coronium-login.json
```

Expect: `{"signedIn":true}`. A new account's file holds `accountId`, `credential` and `accessCode`, shown this once. If `coronium-account.json` holds `registration_closed`, use your person's account: they write `{"accessCode": "<access code>"}` into it, then run the block again. Safe to repeat: yes; it signs up only while the file is missing.

2. Read the partner agreement, and show it.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
curl -sS -b coronium.cookies "$SUPPLY/app/api/consent" -o coronium-consent.json
jq -j '.text // empty' coronium-consent.json > coronium-agreement.md
jq '{version, sha256, approved, status, code}' coronium-consent.json
```

Expect: `approved` true, and `status` `unsigned`, `signed` or `countersigned`; `sha256sum coronium-agreement.md` prints `sha256`. Show your person `coronium-agreement.md` whole, with `version` and `sha256`, and wait for their yes. While `approved` is false nobody can sign. Safe to repeat: yes.

3. Sign, after the yes. Write `coronium-signer.json` as `{"name": "<full legal name>", "organisation": "<only when they sign for one>"}`: the person or organisation that controls the account, never you, trimmed, without `|` or a line break. The block keeps the signed body in `coronium-signature.json`.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
[ -e coronium-signature.json ] || {
  now=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
  sig=$(jq -j --arg now "$now" --slurpfile s coronium-signer.json '"coronium-partner-agreement|\(.version)|\(.accountId)|\($s[0].name)|\($s[0].organisation // "")|\(.sha256)|\($now)"' coronium-consent.json | sha256sum | cut -d' ' -f1)
  jq -c --arg now "$now" --arg sig "$sig" --slurpfile s coronium-signer.json '{consent: {version, sha256}, agreed: true, signer: $s[0], signedAt: $now, signature: $sig}' coronium-consent.json > coronium-signature.json
}
curl -sS -b coronium.cookies -H 'Content-Type: application/json' -d @- "$SUPPLY/app/api/consent" < coronium-signature.json | jq '{signatureId, version, code}'
```

Expect: a `signatureId`. The signature is the SHA-256 of `coronium-partner-agreement|<version>|<accountId>|<signer.name>|<signer.organisation or empty>|<sha256>|<signedAt>`. A check: version `partner-1 (2026-11-25)`, accountId `5f0c2a8e-3b1d-4c6e-9a7f-2d8b4e6c1a90`, name `Ada Example`, organisation `Example Devices Ltd`, sha256 `9f2c4e6a8b0d1f3e5a7c9e1b3d5f7a9c2e4b6d8f0a1c3e5b7d9f1a3c5e7b9d0f` and signedAt `2026-11-25T12:00:00.000Z` give `a7e2aa366c3f98afdb1c468330872ed2edf81c66da3b5e74bfd3c8a0826e249f`. A signature and each enrolment are stored with the address and client software they came from, under a keyed receipt ([`/kit/SIGNING.md`](/kit/SIGNING.md)). If refused: `bad_signed_at` (more than 10 minutes from the server's clock: fix the clock, delete `coronium-signature.json`, repeat), `already_signed` (signed already with other values; that stands, go on), `consent_outdated` (step 2, then delete `coronium-signature.json`). Safe to repeat: yes, with the same file. A signature is never withdrawn.

4. Enrol one device.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
[ -e coronium-enrol.json ] || jq -c --arg id "$(od -An -tx1 -N8 /dev/urandom | tr -d ' \n')" '{consent: {version, sha256}, agreed: true, requestId: $id}' coronium-consent.json > coronium-enrol.json
[ -e coronium-device.json ] || curl -sS -b coronium.cookies -H 'Content-Type: application/json' -d @- "$SUPPLY/app/api/devices" < coronium-enrol.json -o coronium-device.json
jq '{deviceId, relay, state, code}' coronium-device.json
```

Expect: `deviceId`, `relay` and `state` `new`; the file also holds `deviceSecret`, shown this once. If refused, act on `fix`, delete `coronium-device.json` and repeat: `agreement_unsigned` (step 3), `device_cap_reached` (the account holds `terms.deviceLimit` of `GET /app/api/earnings`), `enrolment_repeated` (this `requestId` enrolled `deviceId` already and its secret is gone: ask Coronium to withdraw it, delete `coronium-enrol.json` too, enrol again). Safe to repeat: yes; one `requestId` enrols once.

5. Write the settings file.

```sh
umask 077
jq -er 'if (.relay and .deviceId and .deviceSecret) then "CORONIUM_RELAY=\(.relay)\nCORONIUM_DEVICE=\(.deviceId)\nCORONIUM_DEVICE_SECRET=\(.deviceSecret)" else error("no relay, device or secret in coronium-device.json") end' coronium-device.json > agent.env
```

Expect: no output, and `agent.env` with three lines for Docker, a shell or systemd. A null `relay` means ask the operator. Safe to repeat: yes.

## Then

[Choose and check the agent file](/guides/device-files.md), run it one way, and [read the device's state](/guides/device-states.md).
