Web Platform APIs
txiki.js implements a number of Web Platform APIs to provide a familiar environment for JavaScript developers.
Supported APIs
| API | Notes |
|---|---|
| AbortController / AbortSignal | Includes static AbortSignal.abort(), timeout(), any() |
| atob / btoa | Base64 encode/decode |
| Blob | |
| BroadcastChannel | Cross-worker pub/sub messaging |
| Channel Messaging API | MessageChannel / MessagePort, transferable across workers |
| CompressionStream / DecompressionStream | Formats: gzip, deflate, deflate-raw |
| Console | |
| Crypto | Includes SubtleCrypto |
| Direct Sockets | TCP, TLS, UDP and Unix pipe sockets — see the Networking guide |
| DOMException | |
| Encoding API | TextEncoder / TextDecoder, plus the streaming TextEncoderStream / TextDecoderStream |
| EventSource | Server-Sent Events over fetch; no CORS (withCredentials is a no-op) |
| EventTarget | |
| fetch | |
| File | |
| FileReader | |
| FormData | |
| Import attributes | JSON, text, and bytes |
| Navigator.userAgentData | |
| Performance | |
| queueMicrotask | |
| setTimeout, setInterval | |
| Storage API | localStorage persists to SQLite at $TJS_HOME/localStorage.db; sessionStorage is in-memory |
| Streams API | |
| structuredClone | |
| URL | |
| URLPattern | |
| URLSearchParams | |
| WebAssembly | Interpreter-based (WAMR); some limitations |
| WebSocket | Extensions |
| WebSocketStream | Extensions |
| Web Workers | Structured-clone messaging with transferables (ArrayBuffer, MessagePort) |
| XMLHttpRequest |
Web Crypto (SubtleCrypto)
The global crypto object implements both getRandomValues() / randomUUID() and the full crypto.subtle (SubtleCrypto) API.
All twelve SubtleCrypto methods are available: digest, encrypt, decrypt, sign, verify, generateKey, deriveBits, deriveKey, importKey, exportKey, wrapKey, and unwrapKey.
| Category | Algorithms |
|---|---|
| Digest | SHA-1, SHA-256, SHA-384, SHA-512 |
| Symmetric encryption | AES-CBC, AES-CTR, AES-GCM |
| Key wrapping | AES-KW, plus wrapKey/unwrapKey with the encryption algorithms |
| Asymmetric encryption | RSA-OAEP |
| Signatures | RSASSA-PKCS1-v1_5, RSA-PSS, ECDSA, Ed25519, HMAC |
| Key agreement | ECDH, X25519 |
| Key derivation | PBKDF2, HKDF |
// Hash some bytes.
const data = new TextEncoder().encode('hello world');
const digest = await crypto.subtle.digest('SHA-256', data);
console.log(new Uint8Array(digest));
// Generate an AES-GCM key and encrypt.
const key = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, data);
For synchronous, streaming, or MD5/SHA-3 hashing, see the tjs:hashing standard-library module.
Extensions
WebSocket / WebSocketStream headers
Both WebSocket and WebSocketStream support setting custom HTTP headers on the client handshake request. This is a non-standard extension useful for authentication, API keys, and other scenarios where you need to send headers during the WebSocket upgrade.
Certain headers related to the WebSocket handshake itself (e.g. Connection, Upgrade, Sec-WebSocket-*) are forbidden and will throw a TypeError.
WebSocket
Instead of passing protocols as the second argument, pass an options object with headers (and optionally protocols):
const ws = new WebSocket('wss://example.com/ws', {
protocols: ['chat'],
headers: {
'Authorization': 'Bearer my-token',
'X-Custom-Header': 'value',
},
});
The headers option accepts a plain object, a Headers instance, or an array of [name, value] pairs.
WebSocketStream
Pass headers in the options object:
const wss = new WebSocketStream('wss://example.com/ws', {
protocols: ['chat'],
headers: {
'Authorization': 'Bearer my-token',
},
});
const { readable, writable } = await wss.opened;
WebAssembly
WebAssembly is powered by the WAMR interpreter. Most of the JavaScript API is implemented:
WebAssembly.validate(),compile(),instantiate(), and thecompileStreaming()/instantiateStreaming()variants.Module(includingModule.exports()andModule.imports()),Instance,Memory,Table,Global, and theCompileError/LinkError/RuntimeErrortypes.- Function, global, and memory imports.
- The reference-types, SIMD, and bulk-memory proposals.
externref/funcrefwork for exported functions, globals, and tables.
The following are not currently supported:
- Table imports — a
Tablecannot be supplied through the import object. Table exports work. - Reference types in imported functions —
externref/funcrefas parameters or results of JS-backed imported functions. - Multi-value returns from imported functions — multi-value returns from exported functions work.
- Re-instantiating a
Modulewith different imports — imports are resolved at the module level, so passing a new import object to a secondnew WebAssembly.Instance(module, ...)reuses the first set. UseWebAssembly.instantiate(bytes, importObject)to get independent instances.
To run WASI modules, see tjs:wasi.
WinterTC compliance
txiki.js aims to be WinterTC compliant. You can track the progress here.