The ts-stack uses a layered authentication model. Three BRC numbers are relevant: BRC-103, BRC-104, and BRC-31. They are related but distinct.
BRC-103 defines the core mutual-auth primitive: a Peer abstraction.
@bsv/authsocket implements BRC-103 over WebSocket.
@bsv/auth-express-middleware wraps BRC-103/104 for Express HTTP servers.
@bsv/message-box-client uses BRC-103 to authenticate against MessageBox servers.
BRC-104 defines the message-framing layer used with BRC-103 Peer sessions. It specifies how messages are encoded, versioned, and transmitted once a BRC-103 session is established.
BRC-31 is the HTTP-specific profile of the BRC-103/104 mutual auth framework.
It specifies a set of x-bsv-auth-* HTTP request and response headers that implement the challenge-response handshake over standard HTTP semantics:
Client request:
x-bsv-auth-version: 1
x-bsv-auth-identity-key: <client's identity public key>
x-bsv-auth-nonce: <random nonce>
x-bsv-auth-signature: <signature over nonce + request metadata>
Server response:
x-bsv-auth-nonce: <server nonce>
x-bsv-auth-signature: <server signature proving its identity>
Both parties emerge from the handshake having verified each other's identity keys. Subsequent requests in the same session use a session token derived from the initial handshake.
@bsv/auth-express-middleware installs BRC-103/BRC-104 as Express middleware. Any route wrapped by it requires a valid BRC-103 handshake from the client over the BRC-104 HTTP binding.
The machine-readable spec is at specs/auth/brc103-mutual-auth.yaml (AsyncAPI 3.0).
An identity key is a long-lived BRC-42-derived public key representing a user, service, or application. Properties:
All BRC-103/104 and BRC-31 handshakes use identity keys for signing. Applications retrieve their identity key via wallet.getPublicKey({ identityKey: true }).
@bsv/authsocket and @bsv/authsocket-client implement BRC-103/104 over WebSocket:
authsocket exposes an authenticated WebSocket serverauthsocket-client connects with mutual authentication before any messages are exchangedMessageBox is a higher-level messaging substrate built on BRC-103/104:
sendMessage and getMessages@bsv/message-box-client is the client library. The MessageBox server is a separate deployable (see Infrastructure: MessageBox Server).
| Use case | Use |
|---|---|
| HTTP API mutual auth (REST/Express) | BRC-31 via @bsv/auth-express-middleware |
| Persistent WebSocket channel | BRC-103/104 via @bsv/authsocket |
| Store-and-forward messaging | MessageBox via @bsv/message-box-client (uses BRC-103/104 internally) |
| Payment + identity in one HTTP request | BRC-121 + BRC-31 together |
BRC-100's certificate methods (acquireCertificate, proveCertificate, listCertificates) integrate with the auth framework:
proveCertificate)@bsv/simple exposes Certifier, CredentialSchema, and CredentialIssuer for W3C Verifiable Credential workflows built on top of BRC certificate primitives.