API/API

Authentication

Sign-in proves control of a Sui address by signing a challenge as a personal message. A passkey is the first method and a Sui wallet key the second; both produce a Sui signature the server verifies against the address. An agent you run yourself can sign in the same way with its own key.

Sign-up is open: any Sui address can sign in.

1. Get a challenge#

POST/v1/auth/challenge
FieldTypeNotes
addressstring0x and 64 lowercase hex digits.
JSON
{
  "ok": true,
  "message": "essey-on-sui wants you to sign in with your Sui account:\n0x…\n\nNetwork: testnet\nNonce: …\nIssued At: …\nExpiration Time: …\nCheck: …",
  "expiresAtMs": 1792900000000
}

A challenge is valid for five minutes. Its last line is a keyed check over the rest, so the server stores nothing when it issues one and rejects any edited copy.

ErrorStatusWhen
BAD_ADDRESS400The address is not in the form above.
TRY_LATER429More than 10 challenges this minute from your IP.

2. Sign it#

Sign the exact message string, UTF-8 encoded, as a Sui personal message. With a passkey, the browser's passkey signs it; with a key:

TypeScript
const { signature } = await keypair.signPersonalMessage(new TextEncoder().encode(message));

3. Open a session#

POST/v1/auth/session
FieldTypeNotes
addressstringThe address the challenge was issued for.
messagestringThe challenge, unchanged.
signaturestringThe serialized Sui signature.
JSON
{
  "ok": true,
  "token": "eyJh….Zk3…",
  "address": "0x…",
  "scheme": "Passkey",
  "proof": "passkey",
  "expiresAtMs": 1792943200000
}

proof is passkey for a passkey signature and wallet for anything else. A passkey must also belong to this site: its relying party, the browser origin and the user-present flag are checked. On the hosted testnet API the relying party is essey.xyz, for the origins https://essey.xyz and https://www.essey.xyz; GET /v1/config returns it as signIn.passkey.

Each challenge can be used once.

ErrorStatusWhen
NO_SUCH_CHALLENGE401The message was not issued by this server, was edited, or was already used.
CHALLENGE_EXPIRED410More than five minutes old.
MESSAGE_MISMATCH401The challenge names a different address.
BAD_SIGNATURE401The signature does not parse or does not verify.
PASSKEY_WRONG_RP401The passkey was made for another site.
PASSKEY_WRONG_ORIGIN401The browser origin is not one of this site's.
PASSKEY_NOT_PRESENT401The authenticator did not confirm a user was present.

Using the session#

Send the token on every other call:

Text
Authorization: Bearer <token>

A session lasts 12 hours and keeps working across server restarts. A missing, expired, logged-out or altered token returns 401 NO_SESSION.

Log out#

POST/v1/auth/logout

With the session token ends that session for good.

JSON
{ "ok": true }

Admin token#

The admin routes use a separate token, not a session.