SDK guide
SDK overview
What @sloppyvoice/sdk 0.1 implements, what you supply yourself, its entry points and runtimes, and how to install it.
Specification: 00 Overview, architecture and conventions, 01 Addresses, display names and links, 02 Discovery, server metadata and server keys, 03 Client transport, envelopes and errors, 04 Cryptographic conventions, 05 Accounts, login, sessions, devices and bots, 06 Federation, 07 Identity keys, certificates and verification, 08 Turning on encryption, pairing, backup and the vault, 09 Communities, membership, channels and security transitions, 10 Roles, permissions, moderation and reports, 11 Messages, attachments, read state and presence, 12 Direct messages and group DMs, 13 MLS profile, 14 Sealed messages, history visibility and sharing, 15 Calls: control, leases, routing and continuity, 16 Audio, 17 Screen share and webcam, 18 Media end-to-end encryption, 19 Notifications and push
@sloppyvoice/sdk is a TypeScript client library for the Sloppy Voice v2 protocol (sv1). It is for people writing bots, clients and test tools in TypeScript or JavaScript who don't want to reimplement the wire rules of the specification themselves: discovery, the HTTPS API conventions, the event WebSocket, errors, paging, idempotency, remote sessions at other servers, and the sv1-c1 cryptographic conventions. Server authors can use its wire types and verification helpers, but it is not a server.
The specification is authoritative. Where the SDK and the spec disagree, the SDK is wrong. The doc comments of exported functions cite the spec section each one implements. If you work in another language, the protocol guide covers the same ground without the SDK.
Version 0.1.0 speaks protocol version 1.0 (PROTOCOL_VERSION) over the WebSocket subprotocol sloppyv.v1. It is ESM only and has no runtime dependencies.
Scope of 0.1
The table lists what 0.1 implements for each part of the protocol, and what it leaves to you or to the platform. Where 0.1 reaches something it can't do, it throws SloppyVoiceError with the code sdk.not_implemented instead of silently succeeding. The last column lists every place 0.1 throws that code, and the parts that are simply absent.
| Area | Spec | In 0.1 | Yours to supply, or not implemented |
|---|---|---|---|
| Addresses and links | 01 | The SV local-part profile, domains, canonicalize, canonical-address checks, display names and confusable skeletons, sloppyv: URIs and HTTPS share links. |
On a runtime whose Unicode data is older than 16.0.0, the profile functions throw sdk.not_implemented (01 §1.4). |
| Discovery | 02 | DiscoveryResolver: native and web resolution, the _sloppyv TXT record and .well-known fallback, GET /v1/resolve and the pin admin endpoints, ServerMetadata validation, server keys, KeyRotation, delegation evidence, pinning and caching. dohTxtResolver, a DNS-over-HTTPS TXT resolver. |
The main entry point has no system DNS resolver, because browsers and Workers can't send DNS queries. Use nodeTxtResolver on Node, Deno and Bun (02 §5.2), dohTxtResolver on Cloudflare Workers, and on a web client its home server's GET /v1/resolve with DoH as the fallback (02 §5.4). |
| HTTPS API | 03 | FetchHttpClient: Authorization schemes, problem errors, retries, Retry-After and rate limits, Idempotency-Key, seq timelines and cursor paging, CORS-safe headers. |
— |
| Event WebSocket | 03 | EventSocket: session.hello and session.ready, subscriptions, heads, resume, resync, heartbeat, session.reauth, close codes and reconnecting, with typed events. |
— |
| Cryptographic conventions | 04 | base64url, UUIDv7, JWS (EdDSA) signing and strict verification, JWK thumbprints, labelled signatures, HKDF, AES-GCM, HPKE, SVF1 attachment encryption, and CPace with the built-in elligator2Generator. | Argon2id: WebCrypto has none, so you supply an Argon2idProvider (04 §12). The primitives come from WebCrypto with no fallback (04 §14.6); without crypto.subtle they throw sdk.not_implemented. |
| Accounts and sign-in | 05 | AuthApi (PKCE, pushed authorization requests, code and refresh exchanges, sign-up, sign-out), HomeSession (silent refresh, refresh-token rotation, 401 recovery), botToken, and the me, devices, bots, profiles and providers APIs. |
Opening the authorize URL in a browser and receiving the redirect are your app's. webLocks, the cross-tab refresh lock of 05 §7.7, throws sdk.not_implemented where the platform has no Web Locks API. |
| Federation | 06 | RemoteSessionProvider: HomeAssertions, remote sessions, silent renewal and extension. FederationApi, DeviceProofs with a pluggable Ed25519 signer, and, for server authors, HomeAssertion and DeviceProof verification and S2S request-token creation and verification. | The server-to-server endpoints (06 §8.1) are typed in @sloppyvoice/sdk/wire but not callable. |
| Identity | 07 | IdentityApi; verifying IdentityState; issuing and verifying IdentityCertificate, DeviceCertificate and DeviceRevocation; contact pins; safety numbers and verification QR codes (@sloppyvoice/sdk/crypto). |
— |
| Device setup and recovery | 08 | PairingApi with the QR payload, the 6-digit code, CPace and payload encryption; BackupApi with the recovery phrase and KeyBackup encryption; VaultApi with record keys, VaultKeyGrants and the merge rules. | The backup key needs your Argon2idProvider. A KeyBackup whose v is not 1 throws sdk.not_implemented (08 §5.1), and so does a vault record type with no record-ID rule; all six types of 08 §8.6 have one. |
| Communities, roles and moderation | 09, 10 | CommunityApi and the myCommunities, channels, invites, roles, moderation, bans, reports and auditLog APIs; the permission registry and effective-permission algorithm of 10 §6. |
— |
| Messaging | 11 | MessagesApi and the reactions, readState, typing, presence, attachments and webhooks APIs; building and validating content objects; posting insecure and sealed carriers. |
— |
| Direct messages | 12 | DmsApi with the DM index, settings, blocks and message requests; DM IDs (@sloppyvoice/sdk/crypto). |
— |
| MLS | 13 | MlsApi and KeyPackagesApi (the Delivery Service endpoints), and everything of the profile that needs no group secrets: the TLS codec, group_id, the GroupContext extensions, the sv_device credential, server proposals, building and verifying KeyPackages, MLS-Exporter from an exporter secret. |
The MLS state machine (commits, Welcome processing, the key schedule, the ratchet tree). You plug in an RFC 9420 implementation as an MlsProvider; the placeholder unimplementedMlsProvider throws sdk.not_implemented for every operation. |
| Sealed messages and history | 14 | Sealing and opening messages given K_hist, creating and opening HistoryShares (@sloppyvoice/sdk/crypto), and HistoryApi. |
K_hist comes from the MLS exporter (exportHistoryKey), so secure contexts need an MlsProvider. |
| Calls | 15 | CallsApi and the relay /connect; leases and coverage, RelayTickets, the relay connection rules, CallContinuity (auto-rejoin and transmit state), the transmit gate, diagnostics. |
WebRTC itself (RTCPeerConnection, ICE, data channels) is the platform's; these modules say when to create, signal and close it. |
| Audio and video | 16, 17 | voice-dc/1 and video-dc/1 codecs with strict validation, sfu-rtp/1 constants, receiver lease enforcement and the video adaptation state machines (@sloppyvoice/sdk/media). |
Capture, encoding, the jitter buffer and mixing are the platform's. |
| Media encryption | 18 | SFrame headers, the KID layout, key derivation, AES-128-GCM encryption through WebCrypto, protecting and opening frames on each transport, replay and epoch bookkeeping, MediaAttestation (@sloppyvoice/sdk/media). |
The epoch secret comes from the MLS exporter, so secure calls need an MlsProvider. Wiring the transform into the platform's media pipeline is yours. |
| Notifications and push | 19 | NotificationsApi and PushApi: settings, notification records, event tickets, push registrations and the gateway call, and the pure rules of 19 (trigger priority, previews, badges). | — |
| Testing | — | MockServer and MockNetwork (@sloppyvoice/sdk/testing): an in-memory server for insecure-mode flows that the real HTTP client, resolver and event socket run against. |
The mock does not implement secure mode, OAuth sign-in, roles and moderation, attachments, calls, notifications and several other features; the MockServer reference lists them. |
The SDK is not a server, and it has no server-to-server client. Server authors get the wire types and the verification helpers listed above, such as RelayTicket signing and validation.
Entry points
| Import | Contents |
|---|---|
@sloppyvoice/sdk |
SloppyVoiceClient and ServerClient, the HTTP client, errors, token providers, paging, the event socket, sign-in and remote sessions, every resource API, content and permission helpers, discovery, the calls modules, the MLS provider interface and every wire type. |
@sloppyvoice/sdk/address |
Addresses, display names and links (01). |
@sloppyvoice/sdk/discovery |
Discovery (02); also re-exported by the main entry point. |
@sloppyvoice/sdk/crypto |
Encodings and suite sv1-c1 (04), identity verification and safety numbers (07), DM IDs (12), sealed messages and HistoryShares (14). |
@sloppyvoice/sdk/media |
voice-dc/1, video-dc/1, SFrame and MediaAttestation helpers (16 to 18). |
@sloppyvoice/sdk/wire |
Wire types, constants and error registries with no logic, and the composed EventMap; also re-exported by the main entry point. |
@sloppyvoice/sdk/testing |
MockServer, MockNetwork, and the MockWebSocket and MockServerSocket they use. |
@sloppyvoice/sdk/node |
Node-only helpers: nodeTxtResolver on node:dns/promises and loadPublicSuffixList. They also work on Deno and Bun. |
Only @sloppyvoice/sdk/node uses Node modules, and it imports them dynamically, so a browser bundle never pulls them in.
Runtimes
0.1 runs on Node 22.12 or later, current browsers, Deno, Bun and Cloudflare Workers. It needs only standard platform APIs that all of these have: fetch, the WHATWG WebSocket, crypto.subtle, crypto.getRandomValues, TextEncoder and TextDecoder, URL, AbortController, setTimeout, structuredClone and queueMicrotask. For tests, the client options replace fetch, the WebSocket constructor, the clock, the timers, the sleep between HTTP retries and the jitter source; cryptographic randomness always comes from crypto.getRandomValues.
Three runtime features are checked rather than assumed:
- Unicode 16.0.0 or later, which addresses and domains need (01 §1.4). Node 22.12 ships ICU 76, which has it; on an older engine the address profile functions throw
sdk.not_implementedinstead of accepting addresses they can't check. - WebCrypto. The SDK has no fallback implementations of the primitives (04 §14.6), so without
crypto.subtlethe crypto functions throwsdk.not_implemented. - Web Locks, only for webLocks, which web clients with several tabs use to serialize token refreshes (05 §7.7).
On Node, Deno and Bun, pass nodeTxtResolver() as txt so the client can run native discovery (02 §5.2); on Cloudflare Workers, pass dohTxtResolver({ url }) instead. A web client can't query DNS: it passes homeBaseUrl, the base URL of the server that served it, and the client resolves other domains through that server's GET /v1/resolve, with an optional DoH resolver as the fallback (02 §5.4). Runtimes and bundling covers each runtime in detail.
Install
The package is served from this site, not from the npm registry. Install the tarball by URL:
npm install https://developer.sloppyvoice.com/downloads/sloppyvoice-sdk-0.1.0.tgzIt installs as @sloppyvoice/sdk, with type declarations and the TypeScript source. The downloads page lists each file's SHA-256, so you can download the tarball, check it, and install the local file instead.
For a page without a build step, download sloppyvoice-sdk-0.1.0.mjs, a single ES module, serve it from your own origin and import it by path:
import { SloppyVoiceClient, staticToken } from './sloppyvoice-sdk-0.1.0.mjs'The browser module is built from the main entry point only, so it exports what @sloppyvoice/sdk exports (which includes /discovery and /wire) and nothing from /address, /crypto, /media, /testing or /node. Use the tarball and a bundler if you need those in a browser.
A first program
A bot on Node that finds its home server, reads its own account, and reports any SDK error by its code:
import { SloppyVoiceClient, botToken, isSloppyVoiceError } from '@sloppyvoice/sdk'
import { nodeTxtResolver } from '@sloppyvoice/sdk/node'
const sv = new SloppyVoiceClient({
client: 'hello-bot/1.0',
home: 'sloppyvoice.com',
auth: botToken(process.env.SV_BOT_TOKEN!),
txt: nodeTxtResolver(),
})
try {
const home = await sv.home()
const { account } = await home.me.get()
console.log(`Signed in as ${account.address} on ${home.domain}`)
} catch (e) {
if (isSloppyVoiceError(e)) console.error(e.code, e.detail)
else throw e
} finally {
await sv.close()
}The bot token is only ever sent to the bot's home server. When you call sv.serverFor(address) for an address on another server, the client gets a remote session there from a HomeAssertion the home server signs, and that server only ever sees its own token (03 §3.2 rule 3).
More
The SDK guides, in sidebar order:
- Quickstart: a bot: create a bot token, connect, answer
!ping, and run the same bot againstMockServer. - Clients, servers and discovery: how
SloppyVoiceClientfinds servers and authenticates to each one. - Signing in and tokens: bot tokens, the OAuth sign-in flow, home sessions and remote sessions.
- Receiving events: the event socket, typed events, subscriptions, stream positions, resyncs and reconnects.
- Messages, reactions and attachments: sending, reading, editing and reacting, plus typing, read state, presence, attachments and webhooks.
- Communities, roles and moderation: channels, invites, roles, local permission checks, moderation, reports and the audit log.
- Direct messages: 1:1 and group DMs, the DM index, message requests, settings and blocks.
- Errors and retries:
SloppyVoiceError, what the SDK retries by itself, rate limits, idempotency keys and cancellation. - Secure mode and cryptography: the
/cryptoentry point, sealed messages, and the parts of secure mode you plug in. - Calls and media:
CallsApi,CallContinuity, and thevoice-dc/1,video-dc/1and SFrame helpers. - Testing with MockServer: running a bot or client against an in-memory server.
- Runtimes and bundling: discovery on each runtime, the browser module, bundlers and the Content-Security-Policy.
Reference and downloads:
- API reference: every exported class, function, type and constant, by entry point.
- Downloads: the tarball, the browser module, the licence and their SHA-256 sums.
- Protocol guide: how the wire protocol works, independent of the SDK.