tcmts.atproto

test/
11 definitions

Types

AuthServer type
What an authorization server's metadata says, of what tcm uses.
DidDocument type
What tcm reads of a DID document.
Identity type
An account: its DID, its handle (when it checks out both ways), and the PDS holding its repository.
KeptSessions type
The kept sign-ins, by DID, and the one used last.
NoSuchRecord typeof NoSuchRecord
A record that a repository doesn't hold (`getRecord` says there's none): not theirs, and gone if it was.
NotTheirs typeof NotTheirs
Thrown when a record doesn't check out against its writer's signed repository: it's failed, not retried.
OAuthSession type
A signed-in account, as kept: who, and the tokens to call its PDS as them, bound to a DPoP key.
Refused typeof Refused
What this library won't do, and won't by being asked again: a DID, a handle or a server it won't ask, an answer it won't read, a sign-in that went wrong. Its message says why, to whoever asked (tcm prints it as it does any error a command meets).
TokenAnswer type
A token endpoint's answer.

Server

atprotoSession (o: { who?: string | undefined; scope: string; why: string; tell?: ((line: string) => void) | undef…
A sign-in for `scope`, as `who` (a handle or DID) or, without one, the one used last: kept from before (its tokens refreshed if they've expired), or a new one, in the browser, kept for next time.
authServerFor (pds: string) => Promise<AuthServer>
The authorization server a PDS signs in with, and its metadata.
b64url (b: string | Buffer<ArrayBufferLike>) => string
base64url
didDocument (did: string) => Promise<DidDocument>
A DID's document: did:plc from the PLC directory, did:web from its host: a host name, and a port (`%3A`) alone, fetched as any server someone else names is (`guardedFetch`: https, public addresses only, no redirects).
directory () => string | undefined
Where identities are looked up, if not on the network itself: `$TCM_ATPROTO_DIRECTORY`, a PLC directory that also resolves handles (`com.atproto.identity.resolveHandle`), for a private network or a test's.
dpopFetch (key: JsonWebKey, url: string, init?: RequestInit, accessToken?: string | undefined) => Promise<Res…
A request with a DPoP proof (and the access token, when given), made again once with a fresh nonce when the server asks for one, as servers do.
dpopProof (key: JsonWebKey, method: string, url: string, nonce?: string | undefined, accessToken?: string | u…
A DPoP proof for a request: signed with the key, over its method and URL (and the access token, sent with it).
keepSession (did: string, s: OAuthSession | undefined) => void
Keep a sign-in (and make it the one used last), or forget one (`undefined` for its DID).
localNetwork () => boolean
Whether the AT Protocol network is one on this machine, or a test's (`$TCM_ATPROTO_LOCAL=1`): plain http, and addresses only this machine or its network reach, are allowed for the servers records and documents name. Never set for a registry on the internet.
loopbackServer (waitMs?: number, state?: string | undefined) => Promise<{ port: number; answer: Promise<URLSearchP…
A server on 127.0.0.1 (a port of its own) for the browser to come back to from signing in: its port, and the query it comes back with (or a timeout, after `waitMs`). With `state`, only an answer with that state is taken: any other request (another program on this machine's) is turned away, and the sign-in goes on waiting.
openBrowser (url: string) => void
Open a URL in the browser: `$BROWSER` if it's set (the URL its last argument), else the system's.
pdsOf (doc: DidDocument, did: string) => string
A DID document's PDS (`#atproto_pds`), as an origin to put paths after: https (http on a local network), and nothing but a scheme and a host (no path, query or credentials, which would let a document choose where tcm's requests go on a host). Throws if there's none, or it's anything else.
privateAddress (ip: string) => boolean
Whether an IP address is one only this machine or its own network reaches: unspecified, loopback, private, link-local, carrier-grade NAT, benchmarking, multicast or reserved, unique-local, or an IPv4 address mapped into IPv6 that is one.
publicUrl (url: string, what: string) => Promise<URL>
A URL tcm may fetch on someone else's say-so (a record's, a DID document's, a registry visitor's): https, with no credentials in it, at a host whose addresses are all public. On a local network (`localNetwork`) http, and any address, are allowed. Throws a `Refused` saying why otherwise.
readSessions () => KeptSessions
The kept sign-ins: from a file this user owns, not a link, which only they can read (it's made so if others could).
refreshSession (s: OAuthSession) => Promise<boolean>
Refresh a sign-in's tokens (and keep them): false when they can't be (expired, or revoked).
resolveHandle (handle: string) => Promise<string>
A handle's DID: from its DNS (`_atproto.<handle>`), else its HTTPS well-known (or the directory, if one is set).
resolveIdentity (who: string) => Promise<Identity>
Who a handle or DID is. A handle counts only both ways: it names the DID, and the DID's document names it back; a DID's handle is left out when it doesn't.
sessionsFile () => string
Where sign-ins are kept: `$XDG_CONFIG_HOME/tcm/atproto.json` (`~/.config/tcm/atproto.json`), readable only by you.
signIn (who: string, scope: string, tell?: (line: string) => void) => Promise<OAuthSession>
Sign in as `who` (a handle or DID) with OAuth, in the browser, for `scope`: as AT Protocol's loopback client (no client metadata to host), with PKCE and DPoP-bound tokens. `tell` says what's happening.
signingKey (did: string) => Promise<{ pds: string; key: PublicKey; }>
A DID's repository signing key, from its DID document (`#atproto`): a `Multikey`, or a legacy `EcdsaSecp256k1VerificationKey2019` / `EcdsaSecp256r1VerificationKey2019`, whose key is written uncompressed (as a PLC directory still serves some, and did:web documents may), compressed for importing.

Shared

HOSTNAME RegExp
A host name as DNS has them: labels of letters, digits and hyphens, at least two, the last not all digits.
browserCommand (url: string, platform: string, browser: string | undefined) => [string, string[]]
How to open a URL in a browser: `$BROWSER` if it's set (the URL its last argument), else the platform's.
cappedBytes (res: Response, max: number, what: string) => Promise<Uint8Array<ArrayBufferLike>>
A response's body, read only up to `max` bytes: one that says it's longer, or turns out to be, is refused (an answer from a server someone else names can't take all the memory there is).
compressedKey (bytes: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>
An elliptic-curve public key in compressed form (33 bytes: 2 or 3 for y's parity, then x), as `importRaw` takes it; one written uncompressed (65 bytes: 4, x, y), as legacy DID documents write theirs, is compressed.
dpopNonces Map<string, string>
The DPoP nonce each server last gave, by origin.
getJson <T>(url: string) => Promise<T>
GET a JSON document, giving up after 30 seconds.
guardedFetch (url: string, what: string, init?: RequestInit, ms?: number) => Promise<Response>
`fetch`, for a URL someone else gave (`publicUrl` checks it): redirects aren't followed (a server can't send tcm on to an address it wouldn't ask), and it gives up after `ms` (default 15 s).
isDid (s: string) => boolean
A DID as the DID syntax has it (`did:<method>:<id>`, the id of letters, digits and `._:%-`): no `/`, `?` or `#`.
oauthAnswer (q: URLSearchParams, state: string, issuer: string) => string
The code an authorization server's answer gives, if it's this sign-in's: its state, no error, and its issuer named (RFC 9207) as the one asked. Throws saying which isn't so.
okJson <T>(res: Response, what: string) => Promise<T>
A JSON answer, or an error saying what the service said.
pdsFetch (s: OAuthSession, p: string, init?: RequestInit) => Promise<Response>
A request to the signed-in account's PDS (`/xrpc/…`), as them: its tokens refreshed once if the PDS says they've expired.
signedRecord (did: string, collection: string, rkey: string) => Promise<{ cid: string; record: unknown; }>
A record at `did`/`collection`/`rkey`, as its author's repository signs it: fetched from their PDS with `com.atproto.sync.getRecord`, its blocks checked against their CIDs and its commit against the DID's key. A DID, document or PDS tcm won't ask (`guardedFetch`, `pdsOf`), or a proof too big to be one, is `NotTheirs`; a record the repository doesn't hold is `NoSuchRecord`.