@yozz.app/tls
v0.3.0
Published
A TLS 1.3 client in TypeScript over any byte duplex: record layer, handshake, key schedule, PSK resumption, KeyUpdate, TOFU pinning. Runs in Node and browsers, no native code.
Readme
@yozz.app/tls
A TLS 1.3 client (RFC 9846) in TypeScript, over any byte duplex. It is what the YOZZ mail client uses to reach IMAP and SMTP servers from inside a browser, where there is no socket API and no platform TLS to call.
- Record layer, handshake state machine, key schedule,
KeyUpdate,close_notify. - 1-RTT PSK resumption; never 0-RTT.
- Certificate validation through
@yozz.app/x509, plus trust-on-first-use public-key pinning as aValidatorwrapper. - WebCrypto only: runs in Node and in Chromium, Firefox and WebKit with no native code.
- Gates: RFC 8448 byte-exact on all five traces; BoringSSL's BoGo runner, 296/296 in scope.
pnpm add @yozz.app/tlsimport { startTls } from '@yozz.app/tls';
import { compileAnchors, ROOT_BUNDLE, YOZZ_VALIDATOR } from '@yozz.app/x509';
// `transport` is a ByteDuplex: { read(): Promise<Uint8Array | null>; write(bytes): Promise<void> }
// over whatever carries bytes to the server (a TCP socket in Node, a WebSocket relay in a browser).
const result = await startTls({
transport,
serverName: 'imap.example.com',
trustAnchors: compileAnchors(ROOT_BUNDLE).source,
validationTime: Temporal.Now.instant(),
validator: YOZZ_VALIDATOR,
});
if (result.ok) {
const { connection } = result; // read() / write() / close() over the encrypted channel
}HandshakeResult is a discriminated union, never a throw for a refused certificate; the refusal
says which check failed. A session handed to onSession can be offered once on a later
connection to resume. Its receivedAt and authenticatedAt are Temporal.Instants, which neither
structured clone nor JSON keeps, so a store encodes them. Before 0.3 they were Dates: a store
written by 0.2 must convert them, or startTls throws on the session before a byte goes out.
Requires a global Temporal. Times are Temporal.Instants (validationTime, the optional now clock, a session's
instants). Node 26, Chrome and Firefox ship it; where the runtime has none (Safari, Node 24), install
temporal-polyfill and load it before this package is
imported (import 'temporal-polyfill/global'). The package imports no polyfill itself.
src/index.ts is the whole public API and says why each export exists. The source is in
fishballapp/yozz, which takes issues but no pull requests.
MIT.
