client.rest
Client. Constructed lazily on first access, and it reuses the client’s restUrl and debug options.
RestApi
method, path, init?
One authenticated request. Resolves the raw response on 2xx and throws
CloakRestError otherwise. path is origin-relative and includes its mount prefix, for example /api/files/list or /auth/verify-session.method, path, init?
request() plus a JSON body parse. An empty 2xx body resolves as null. A non-JSON body throws CloakRestError.method, path, init?
request() plus the raw bytes and a response-header reader. This is the attachment-download shape, where the wrapped file key and IV ride response headers alongside the ciphertext.RestRequestInit
Per-request extras.string
The request body, already serialized.
object
Extra request headers, as a
Record<string, string>.The
userid and verification auth headers are added by the lane and set last, so a caller cannot override them.RestClient
client.rest. It is exported for custom lanes and test doubles. A normal bot uses client.rest and never constructs one.
It holds the derived credential, mints it on demand behind a single-flight latch that covers both phases, and refreshes it inside a skew window. The credential is dropped only on a 401, never on a realtime reconnect, because it is time-bound rather than session-bound.
RestClientOptions
string
required
The REST origin, for example
https://api.cloak.chat. Validated at construction. https is required except for localhost, 127.0.0.1 and ::1.() => Promise<MintedSession>
required
Phase one, injected.
Client owns this because only the transport can speak an opcode.RestFetch
An injected
fetch. Defaults to globalThis.fetch.() => number
An injected clock, for tests.
boolean
Print a redacting one-line trace per request: method, path and status only.
Types
MintedSession
What opcode 638 hands back, phase one of the mint.string
A dashed uuid string, verbatim off the wire. Never normalized: both digests hash the id exactly as the caller sent it.
string
A dashed uuid string, verbatim off the wire.
string
The one-time secret. It leaves the server exactly once and is exchanged for the header immediately, then dropped. Never persisted, never logged, never sent as a header.
number
Absolute expiry of the credential row, in milliseconds.
RestCredential
Phase two’s output, and the only thing the request path ever holds.string
The same string as
MintedSession.userId, byte for byte.string
The derived request header.
number
Absolute expiry, in milliseconds.
RestResponseLike
The slice of afetch Response the lane reads. globalThis.fetch’s Response satisfies it structurally, and so does a small test double.
RestFetch
Constants
string
'https://api.cloak.chat'. A different service from the opcode wire, so url and restUrl are set independently.string
'/auth/verify-session'. The bootstrap endpoint, mounted at /auth and not under /api. It is deliberately not behind the auth middleware, which is what makes it usable to bootstrap.number
30000. How far before the stated expiry the lane re-mints. With the 15 minute credential lifetime, a long-running bot re-mints roughly four times an hour, comfortably under the mint rate limit.Client option
string
Override the REST origin. Defaults to
DEFAULT_REST_URL. A bad value throws on the first client.rest use, not at construction of the Client.CloakRestError
CloakActionError with opcode 638 instead. Full field notes are on the errors reference.
No credential material is ever quoted into this error, in any field or in
toString().Wire slots
The opcode 638 reply’s column map is exported asMintRestCredentialIdx, documented with the rest of the wire constants on the protocol reference.
Next
The REST lane
Why the mint is two phases, and what is reachable.
Errors
CloakRestError next to the other classes.Protocol constants
MintRestCredentialIdx and the rest of the wire maps.Client
restUrl among the constructor options.