veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

net/tls13

lib/net/tls13.vk

lib/net/tls13.vk 100% Pure-Veko RFC 8446 TLS 1.3 client + deterministic loopback TLS 1.3 server helper. Cipher suite: TLS_CHACHA20_POLY1305_SHA256 (0x1303) | Key share: X25519 (0x001d). Zero OS TLS/crypto DLL dependencies; works over net/connect-tcp + random/bytes.

signature
build-client-hello-ext = fn [sni str, eph_pub bytes, mlkem_ek bytes, rnd bytes, sess_id bytes, alpn str] bytes

Builds an RFC 8446 ClientHello handshake payload supporting optional hybrid X25519MLKEM768 (0x11EC) PQC key share.

signature
build-client-hello = fn [sni str, eph_pub bytes, rnd bytes, sess_id bytes, alpn str] bytes

Builds an RFC 8446 ClientHello handshake payload (without TLS record header).

signature
build-quic-client-hello = fn [sni str, eph_pub bytes, rnd bytes, quic_tp bytes] bytes

Builds an RFC 9001 QUIC-TLS ClientHello (legacy_session_id = empty, alpn = 'h3', 0x0039 = quic_tp).

signature
parse-quic-server-hello = fn [msg bytes] any

Parses a QUIC-TLS ServerHello (legacy_session_id == empty), extracting cipher suite and extension-order-independent key_share.

client-handshake fn caps: .fs
signature
client-handshake = fn [sock i64, host str, opts map] any

Performs a full pure-Veko TLS 1.3 client handshake over an already-connected TCP socket sock. opts supports server_name, alpn, pqc (enables hybrid X25519MLKEM768 0x11EC), roots_pem, roots_der, pins_sha256, insecure_skip_verify.

connect fn caps: .net
signature
connect = fn [host str, port i64, opts map] any

Connects TCP (resolving DNS hostnames) + performs full pure-Veko TLS 1.3 handshake (opts: roots_pem, pins_sha256, alpn, server_name, timeout).

send fn
signature
send = fn [mut conn map, data bytes] any

Sends plaintext application data encrypted as TLS 1.3 ApplicationData records.

recv fn
signature
recv = fn [mut conn map] any

Receives decrypted application data (skips post-handshake NewSessionTicket records cleanly).

close fn caps: .net
signature
close = fn [mut conn map]

Sends encrypted close_notify alert and closes underlying TCP socket.

https-request fn caps: .net
signature
https-request = fn [host str, port i64, method str, target str, headers map, body bytes, opts map] any
signature
parse-pem-identity = fn [fullchain_pem str, privkey_pem str] any

Parses PEM certificate chain (fullchain_pem) and private key (privkey_pem: Ed25519, ECDSA P-256, or RSA). Returns { chain_ders, key_info = { kind, priv, n, d } }.

load-pem-identity fn caps: .fs
signature
load-pem-identity = fn [cert_path str, key_path str] any

Loads a TLS 1.3 PEM identity from cert_path and key_path on disk.

signature
ensure-dev-p256-identity = fn [cert_path str, key_path str, domain str] any

Ensures a bootstrap ECDSA P-256 certificate & PKCS#8 key exist at cert_path and key_path (generating them in pure Veko if absent).

signature
new-cert-reloader = fn [cert_path str, key_path str] any

Creates a zero-downtime CertReloader tracking file mtime changes on cert_path and key_path.

signature
get-identity = fn [mut rel map] any

Returns the active TLS identity, reloading automatically if either PEM file's mtime changed on disk.

signature
build-server-flight = fn [ch_msg bytes, ident map, srv_alpns block, srv_quic_tp bytes, is_quic bool] any

Pure-bytes TLS 1.3 / QUIC-TLS server flight builder (shared by server-handshake-identity and net/http3).

signature
verify-client-finished = fn [c_hs_sec bytes, th_srv_fin bytes, cfin_msg bytes] bool

Verifies a TLS 1.3 / QUIC-TLS client Finished handshake message (0x14 || u24(hlen) || verify_data).

server-handshake-identity-opts fn caps: .clocks .net
signature
server-handshake-identity-opts = fn [sock i64, ident map, srv_alpns block, hs_timeout dur, idle_timeout dur] any

Performs a browser-grade RFC 8446 TLS 1.3 server handshake with an enforced wall-clock deadline (hs_timeout, e.g. 5s).

signature
server-handshake-identity = fn [sock i64, ident map, srv_alpns block] any

Performs a browser-grade RFC 8446 TLS 1.3 server handshake using ident (parse-pem-identity: ECDSA P-256, RSA-PSS, or Ed25519) and negotiates srv_alpns (e.g. ['h2' 'http/1.1']) plus AES-128-GCM or CHACHA20-POLY1305 and optional X25519MLKEM768.

signature
server-handshake = fn [sock i64, chain_ders block, leaf_seed bytes] any

Performs a minimal pure-Veko RFC 8446 server handshake on accepted socket sock using Ed25519 leaf keypair. Automatically negotiates hybrid X25519MLKEM768 (0x11EC) and ALPN ('h2' / 'http/1.1') when offered by client. Returns a connection handle compatible with tls13/send, tls13/recv, tls13/close, and tls13/tls-stream.

signature
tls-stream = fn [conn map] io/Stream

Wraps an established TLS 1.3 connection (connect or server-handshake) as an ORO io/Stream.