API Reference

Complete API documentation for NANO runtime

WinterTC APIs

NANO implements the WinterTC standard for edge runtimes. Unlike Node.js, WinterTC uses web-standard APIs like fetch, Request, and Response.

API Status Description
fetch() Full HTTP client with streaming
Request Full HTTP request constructor with body
Response Full HTTP response constructor
Headers Full Case-insensitive header map
URL Full URL parsing with all properties
URLSearchParams Full Query string manipulation
TextEncoder Full UTF-8 encoding to Uint8Array
TextDecoder Full UTF-8 decoding from Uint8Array
ReadableStream Full Streaming data interface
WritableStream Full Output streaming with backpressure
console Full log, error, warn, info, debug
setTimeout/setInterval Full Timer functions with clearing

WebAssembly

V8 built-in WASM engine for executing binary modules in isolates.

Module Compilation
const wasmBytes = await fetch('/module.wasm').then(r => r.arrayBuffer());
const wasmModule = await WebAssembly.compile(wasmBytes);
Instantiation with Memory
const memory = new WebAssembly.Memory({ initial: 1 });
const instance = await WebAssembly.instantiate(wasmModule, {
  env: { memory }
});

const result = instance.exports.add(1, 2);

WebAssembly API

Method Description
WebAssembly.compile()Compile bytes into a module
WebAssembly.instantiate()Create an instance with imports
WebAssembly.ModuleCompiled module class
WebAssembly.InstanceRuntime instance class
WebAssembly.MemoryLinear memory management
WebAssembly.TableFunction reference table

WebCrypto

Full crypto.subtle implementation via Rust crypto crates.

Hashing
const data = new TextEncoder().encode('hello');
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
AES-GCM Encryption
const key = await crypto.subtle.generateKey(
  { name: 'AES-GCM', length: 256 },
  true,
  ['encrypt', 'decrypt']
);

const iv = crypto.getRandomValues(new Uint8Array(12));
const encrypted = await crypto.subtle.encrypt(
  { name: 'AES-GCM', iv },
  key,
  data
);

Supported Algorithms

Algorithm Operations
SHA-256, SHA-384, SHA-512digest
AES-GCM, AES-CTR, AES-CBCencrypt, decrypt, generateKey
HMACsign, verify, generateKey
PBKDF2deriveKey, deriveBits
HKDFderiveKey, deriveBits
RSA-OAEP, RSA-PSS, RSASSA-PKCS1-v1_5encrypt, decrypt, sign, verify
ECDSA (P-256, P-384)sign, verify, importKey
ECDH (P-256, P-384)deriveKey, deriveBits

WebSocket v2.0a

WebSocket support follows the Cloudflare Workers API. See the WebSocket guide for full details.

Echo Server Example
export default {
  async fetch(request) {
    if (request.headers.get('Upgrade') !== 'websocket') {
      return new Response('Expected WebSocket', { status: 426 });
    }
    const [client, server] = new WebSocketPair();
    server.addEventListener('message', (event) => {
      server.send(`Echo: ${event.data}`);
    });
    server.addEventListener('close', (event) => {
      console.log('Closed:', event.code, event.reason);
    });
    server.accept();
    return new Response(null, { status: 101, webSocket: client });
  }
};

WebSocket API

Member Description
new WebSocketPair()Returns [client, server] linked pair
server.accept()Accept the connection (required before send)
server.send(data)Send text string or ArrayBuffer
server.close(code?, reason?)Send Close frame
server.addEventListener(type, fn)Register message / close / error handler
server.readyState0=CONNECTING 1=OPEN 2=CLOSING 3=CLOSED

Nano.fs (VFS)

Virtual File System API for per-isolate filesystem access.

Reading and Writing
// Read file
const data = await Nano.fs.readFile('/data/config.json', 'utf-8');
const config = JSON.parse(data);

// Write file
await Nano.fs.writeFile('/data/output.txt', 'Hello, World!');

// Check existence
const exists = await Nano.fs.exists('/data/config.json');

VFS Methods

Method Description
Nano.fs.readFile()Read file contents
Nano.fs.writeFile()Write file contents
Nano.fs.exists()Check if path exists
Nano.fs.readdir()List directory contents
Nano.fs.mkdir()Create directory
Nano.fs.unlink()Delete file