veko-lang.org
Download Free EPUB 3.0

Part V · Complete Tooling, CLI & Standard Library Reference

Appendix B.2

Standard Library Reference: Codecs, DEFLATE/Zstandard, PNG, Archives, VKP1 & Lockfiles

Complete AST-verified API reference for 19 serialization, wire framing, DEFLATE/Zstd, PNG, archive, and package lockfile modules

Binary and text codecs, compress/deflate, RFC 8878 compress/zstd, lossless image/png, archive/{tar,zip}, Ed25519/ML-DSA-65 pkg/vkp bundles, and homoiconic pkg/lock verification.

Module (use [...])Source FileCapabilitiesTypesFunctions
archive/tarlib/archive/tar.vkZero host capabilities14
archive/ziplib/archive/zip.vkZero host capabilities12
codec/cborlib/codec/cbor.vkZero host capabilities02
codec/csvlib/codec/csv.vkZero host capabilities03
codec/derlib/codec/der.vkZero host capabilities032
codec/hexlib/codec/hex.vkZero host capabilities07
codec/http1lib/codec/http1.vkZero host capabilities07
codec/http2lib/codec/http2.vkZero host capabilities323
codec/inilib/codec/ini.vkZero host capabilities03
codec/pemlib/codec/pem.vkZero host capabilities06
codec/tomllib/codec/toml.vkZero host capabilities02
codec/urllib/codec/url.vkZero host capabilities16
codec/vbinlib/codec/vbin.vkZero host capabilities02
codec/wirelib/codec/wire.vkZero host capabilities12
compress/deflatelib/compress/deflate.vkZero host capabilities06
compress/zstdlib/compress/zstd.vkZero host capabilities03
image/pnglib/image/png.vkZero host capabilities14
pkg/locklib/pkg/lock.vk..env, ..fs216
pkg/vkplib/pkg/vkp.vkZero host capabilities39

Module archive/tar

Exported Structs & Interfaces

  • TarEntry: TarEntry = struct { path str, data bytes, mode i64 = ..., mtime i64 = ... } — Single file entry stored in a .tar / .tar.gz archive.

Exported Functions

SymbolSignatureDescription
packpack = fn [entries block[TarEntry]] bytesPacks entries into a POSIX USTAR .tar archive.
unpackunpack = fn [raw bytes] block[TarEntry]Unpacks a POSIX USTAR .tar archive, verifying header checksums and path confinement.
pack-gzpack-gz = fn [entries block[TarEntry]] bytesPacks entries into a gzip-compressed .tar.gz archive.
unpack-gzunpack-gz = fn [gz bytes] block[TarEntry]Decompresses and unpacks a .tar.gz archive.

Verified Doctest (archive/tar/pack)

VEKO
use [tar = archive/tar]
raw = tar/pack [
  tar/TarEntry { path = 'hello.txt', data = bytes/from-str 'hello tar' }
  tar/TarEntry { path = 'sub/a.vk', data = bytes/from-str '1 + 2' }
]
out = tar/unpack raw
if (len out) != 2 or out[0].path != 'hello.txt' or (bytes/to-str out[1].data) != '1 + 2' [
  err 'tar roundtrip'
] else [ .ok ]

Module archive/zip

Exported Structs & Interfaces

  • ZipEntry: ZipEntry = struct { path str, data bytes, compress bool = ... } — Single file entry stored in a .zip archive.

Exported Functions

SymbolSignatureDescription
packpack = fn [entries block[ZipEntry]] bytesPacks entries into a standard PKZIP .zip archive (auto-falling back to STORE if DEFLATE is larger).
unpackunpack = fn [raw bytes] block[ZipEntry]Unpacks a .zip archive via its Central Directory, decompressing DEFLATE entries and verifying CRC-32 checksums.

Verified Doctest (archive/zip/pack)

VEKO
use [zip = archive/zip]
raw = zip/pack [
  zip/ZipEntry { path = 'readme.txt', data = bytes/from-str 'hello veko zip hello veko zip hello veko zip' }
  zip/ZipEntry { path = 'raw.bin', data = bytes/from-str 'abc', compress = false }
]
out = zip/unpack raw
if (len out) != 2 or (bytes/to-str out[0].data) != 'hello veko zip hello veko zip hello veko zip' or (bytes/to-str out[1].data) != 'abc' [
  err 'zip roundtrip'
] else [ .ok ]

Module codec/cbor

Exported Functions

SymbolSignatureDescription
encodeencode = fn [v any] bytesEncodes a Veko value into deterministic RFC 8949 CBOR bytes.
decodedecode = fn [data bytes] anyDecodes RFC 8949 CBOR bytes into a Veko value (CBOR null maps to .null).

Verified Doctest (codec/cbor/encode)

VEKO
use [cbor = codec/cbor]
raw = cbor/encode { count = -100, ok = true, empty = .null, tag = 'veko' }
dec = cbor/decode raw
if (map/get dec 'count') != -100 or (map/get dec 'empty') != .null or (map/get dec 'tag') != 'veko' [
  err 'cbor roundtrip'
] else [ .ok ]

Module codec/csv

Exported Functions

SymbolSignatureDescription
parseparse = fn [input str] block[block[str]]Parses RFC 4180 CSV text into rows of string fields (block[block[str]]). Supports quoted fields, embedded commas/newlines, and "" escaped quotes.
parse-recordsparse-records = fn [input str] block[map[str]]Parses CSV text whose first row contains column headers into block[map[str]].
encodeencode = fn [rows block[block[str]]] strEncodes rows (block[block[str]]) into RFC 4180 CSV text separated by \n.

Verified Doctest (codec/csv/parse)

VEKO
use [csv = codec/csv]
rows = csv/parse 'name,note\nalpha,"hello, ""world"""\nbeta,plain'
if (len rows) != 3 or rows[1][1] != 'hello, "world"' [ err 'csv/parse' ] else [ .ok ]

Module codec/der

Exported Functions

SymbolSignatureDescription
from-listfrom-list = fn [arr block] bytesBuilds a bytes buffer from an integer element block [0x01 0x02 ...].
u16-beu16-be = fn [b bytes, off i64] i64Reads a 16-bit big-endian integer from b at off.
u24-beu24-be = fn [b bytes, off i64] i64Exported codec/der/u24-be operation.
u32-beu32-be = fn [b bytes, off i64] i64Exported codec/der/u32-be operation.
put-u16-beput-u16-be = fn [mut out bytes, v i64]Exported codec/der/put-u16-be operation.
put-u24-beput-u24-be = fn [mut out bytes, v i64]Exported codec/der/put-u24-be operation.
put-u32-beput-u32-be = fn [mut out bytes, v i64]Exported codec/der/put-u32-be operation.
put-u16-vecput-u16-vec = fn [mut out bytes, data bytes]Exported codec/der/put-u16-vec operation.
put-u24-vecput-u24-vec = fn [mut out bytes, data bytes]Exported codec/der/put-u24-vec operation.
read-u8read-u8 = fn [b bytes, pos i64] anyExported codec/der/read-u8 operation.
read-u16read-u16 = fn [b bytes, pos i64] anyExported codec/der/read-u16 operation.
read-u24read-u24 = fn [b bytes, pos i64] anyExported codec/der/read-u24 operation.
read-bytesread-bytes = fn [b bytes, pos i64, n i64] anyExported codec/der/read-bytes operation.
read-u16-vecread-u16-vec = fn [b bytes, pos i64] anyExported codec/der/read-u16-vec operation.
read-u24-vecread-u24-vec = fn [b bytes, pos i64] anyExported codec/der/read-u24-vec operation.
decode-tlvdecode-tlv = fn [b bytes, pos i64] anyDecodes one DER TLV element starting at byte offset pos. Returns { tag, cls, constructed, hdr_len, content, raw, next } or err(...).
decode-alldecode-all = fn [b bytes] anyDecodes all consecutive DER TLVs inside b (typically the content of a SEQUENCE/SET).
decode-tlv-viewdecode-tlv-view = fn [b bytes, pos i64] anyDecodes one DER TLV element without slicing raw.
decode-all-viewdecode-all-view = fn [b bytes] anyExported codec/der/decode-all-view operation.
decode-seq-items-viewdecode-seq-items-view = fn [node map] anyExported codec/der/decode-seq-items-view operation.
decode-seq-itemsdecode-seq-items = fn [node map] anyDecodes an ASN.1 SEQUENCE TLV node into its child TLV block.
decode-oiddecode-oid = fn [content bytes] anyDecodes a DER OBJECT IDENTIFIER content byte slice into dotted decimal text (e.g. '1.2.840.113549.1.1.11').
decode-int-bytesdecode-int-bytes = fn [content bytes] anyDecodes a positive DER INTEGER into minimal big-endian unsigned magnitude bytes.
decode-int-i64decode-int-i64 = fn [content bytes] anyDecodes a non-negative DER INTEGER up to 63 bits into i64.
decode-bitstrdecode-bitstr = fn [content bytes] anyDecodes a DER BIT STRING content into { unused_bits, data }.
tag-to-enumtag-to-enum = fn [tag i64] anyReturns a homoiconic symbol/tag name for common ASN.1 DER tags for parse-block.
tlv-to-blocktlv-to-block = fn [node map] anyConverts a decoded DER TLV tree into a homoiconic Veko block [tag_enum payload] so downstream code can match DER structures directly using parse-block.
encode-lenencode-len = fn [mut out bytes, n i64]Exported codec/der/encode-len operation.
encode-tlvencode-tlv = fn [tag i64, content bytes] bytesExported codec/der/encode-tlv operation.
encode-seqencode-seq = fn [items block] bytesExported codec/der/encode-seq operation.
encode-intencode-int = fn [raw_be bytes] bytesExported codec/der/encode-int operation.
encode-bitstrencode-bitstr = fn [data bytes] bytesExported codec/der/encode-bitstr operation.

Verified Doctest (codec/der/u16-be)

VEKO
use [der = codec/der]
mut b = bytes/with-cap 8
der/put-u16-be mut b 0x0303
der/put-u32-be mut b 0x12345678
if (der/u16-be b 0) != 0x0303 or (der/u32-be b 2) != 0x12345678 [ err 'der be' ] else [ .ok ]

Module codec/hex

Exported Functions

SymbolSignatureDescription
encodeencode = fn [data bytes] strEncodes data into a lowercase hexadecimal string.
encode-upperencode-upper = fn [data bytes] strEncodes data into an uppercase hexadecimal string.
decodedecode = fn [s str] bytesDecodes a hexadecimal string (even length, uppercase or lowercase) into bytes.
b64-encodeb64-encode = fn [data bytes] strEncodes data into standard RFC 4648 Base64 with '=' padding.
b64url-encodeb64url-encode = fn [data bytes] strEncodes data into RFC 4648 URL-safe Base64 without padding (used by JWT/JWS/OAuth2).
b64-decodeb64-decode = fn [s str] bytesDecodes standard or URL-safe Base64 (with or without '=' padding) into bytes.
b64url-decodeb64url-decode = fn [s str] bytesAlias for b64-decode accepting unpadded URL-safe Base64 strings.

Verified Doctest (codec/hex/encode)

VEKO
use [hex = codec/hex]
enc = hex/encode (bytes/from-str 'Veko')
dec = hex/decode enc
if enc != '56656b6f' or (bytes/to-str dec) != 'Veko' [ err 'hex roundtrip' ] else [ .ok ]

Module codec/http1

Exported Functions

SymbolSignatureDescription
encode-requestencode-request = fn [method str, target str, headers map, body bytes] anyEncodes an HTTP/1.1 request wire frame (METHOD TARGET HTTP/1.1\r\n...).
encode-responseencode-response = fn [status i64, reason str, headers map, body bytes] anyEncodes an HTTP/1.1 response wire frame.
decode-responsedecode-response = fn [raw bytes] anyDecodes an HTTP/1.1 response message into { version, status, reason, headers, body, consumed }.
decode-response-headdecode-response-head = fn [raw bytes] anyDecodes an HTTP/1.1 HEAD response (status + headers with zero body bytes on the wire, preserving Content-Length).
decode-requestdecode-request = fn [raw bytes] anyDecodes an HTTP/1.1 request message into { method, target, version, headers, body, consumed }.
request-to-blockrequest-to-block = fn [req map] blockConverts a decoded request into [ .req method target version headers body ] for parse-block.
response-to-blockresponse-to-block = fn [resp map] blockConverts a decoded response into [ .resp version status reason headers body ] for parse-block.

Verified Doctest (codec/http1/encode-request)

VEKO
use [h1 = codec/http1]
req = h1/encode-request 'GET' '/health' { Host = 'api.local' } (bytes/with-cap 0)
dec = h1/decode-request req
if dec.method != 'GET' or dec.target != '/health' [ err 'http1 roundtrip' ] else [ .ok ]

Module codec/http2

Exported Structs & Interfaces

  • Frame: Frame = struct { ftype i64, flags i64, stream_id i64, payload bytes } — Decoded HTTP/2 binary frame (9-byte header + payload).
  • Header: Header = struct { name str, value str } — Single HTTP/2 header name/value pair.
  • HpackDecoder: HpackDecoder = struct { entries block = ..., cur_size i64 = ..., max_size i64 = ... } — Stateful RFC 7541 HPACK connection decoder maintaining the per-connection FIFO dynamic table.

Exported Functions

SymbolSignatureDescription
connection-prefaceconnection-preface = fn [] strHTTP/2 connection preface (PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n).
frame-dataframe-data = fn [] i64HTTP/2 frame type constants (RFC 9113 Section 6).
frame-headersframe-headers = fn [] i64Exported codec/http2/frame-headers operation.
frame-priorityframe-priority = fn [] i64Exported codec/http2/frame-priority operation.
frame-rst-streamframe-rst-stream = fn [] i64Exported codec/http2/frame-rst-stream operation.
frame-settingsframe-settings = fn [] i64Exported codec/http2/frame-settings operation.
frame-push-promiseframe-push-promise = fn [] i64Exported codec/http2/frame-push-promise operation.
frame-pingframe-ping = fn [] i64Exported codec/http2/frame-ping operation.
frame-goawayframe-goaway = fn [] i64Exported codec/http2/frame-goaway operation.
frame-window-updateframe-window-update = fn [] i64Exported codec/http2/frame-window-update operation.
frame-continuationframe-continuation = fn [] i64Exported codec/http2/frame-continuation operation.
flag-end-streamflag-end-stream = fn [] i64Common HTTP/2 frame flags.
flag-ackflag-ack = fn [] i64Exported codec/http2/flag-ack operation.
flag-end-headersflag-end-headers = fn [] i64Exported codec/http2/flag-end-headers operation.
encode-frameencode-frame = fn [f Frame] bytesEncodes an HTTP/2 Frame (24-bit length + type + flags + 31-bit stream ID + payload).
decode-framedecode-frame = fn [wire bytes] FrameDecodes a single HTTP/2 Frame from wire.
encode-settingsencode-settings = fn [settings map[i64]] bytesEncodes HTTP/2 SETTINGS pairs (map[i64] mapping setting ID -> 32-bit value) into a SETTINGS frame payload.
decode-settingsdecode-settings = fn [payload bytes] map[i64]Decodes an HTTP/2 SETTINGS payload into a map[i64] (ID -> value).
huffman-decodehuffman-decode = fn [enc bytes] strDecodes an RFC 7541 / RFC 9204 Huffman-compressed byte slice into UTF-8 str.
hpack-encodehpack-encode = fn [headers block[Header]] bytesEncodes headers (block[Header]) into an RFC 7541 HPACK header block using the static table and literal-without-indexing representations.
new-hpack-decodernew-hpack-decoder = fn [max_size i64] HpackDecoderCreates a new stateful HpackDecoder with max_size dynamic table capacity (4096 default per RFC 9113).
hpack-decode-ctxhpack-decode-ctx = fn [mut dec HpackDecoder, block_bytes bytes] block[Header]Decodes an RFC 7541 HPACK header block updating stateful dec (static + dynamic table + Huffman).
hpack-decodehpack-decode = fn [block_bytes bytes] block[Header]Decodes an RFC 7541 HPACK header block (static indexed + literal + Huffman) into block[Header].

Verified Doctest (codec/http2/encode-frame)

VEKO
use [h2 = codec/http2]
f = h2/Frame { ftype = h2/frame-data, flags = h2/flag-end-stream, stream_id = 1, payload = (bytes/from-str 'ok') }
wire = h2/encode-frame f
dec = h2/decode-frame wire
if dec.ftype != 0 or dec.stream_id != 1 or (bytes/to-str dec.payload) != 'ok' [ err 'h2 frame' ] else [ .ok ]

Module codec/ini

Exported Functions

SymbolSignatureDescription
parseparse = fn [input str] map[map[str]]Parses INI text into a two-level map { section_name = { key = value } }. Top-level keys outside any [section] are placed under the '' (root) section. Lines starting with # or ; are treated as comments.
getget = fn [cfg map[map[str]], section str, key str] strLooks up key inside section of parsed INI cfg, returning err if missing (combine with /or).
encodeencode = fn [cfg map[map[str]]] strSerializes a two-level INI section map back into .ini text.

Verified Doctest (codec/ini/parse)

VEKO
use [ini = codec/ini]
cfg = ini/parse '[server]\nhost = 127.0.0.1\nport = 8443\n# comment\n[tls]\nmin = 1.3'
if (ini/get cfg 'server' 'port') != '8443' or (ini/get cfg 'tls' 'min') != '1.3' [
  err 'ini/parse'
] else [ .ok ]

Module codec/pem

Exported Functions

SymbolSignatureDescription
b64-decodeb64-decode = fn [text str] anyDecodes a standard or URL-safe Base64 string into raw bytes (ignoring ASCII whitespace).
b64-encodeb64-encode = fn [data bytes] strEncodes data into standard RFC 4648 Base64 text.
pem-decode-allpem-decode-all = fn [text str] anyParses all PEM blocks in text, returning a block of { label, der } maps.
pem-decodepem-decode = fn [text str, expected_label str] anyExtracts the first PEM block matching expected_label (or any block if expected_label == '').
pem-encodepem-encode = fn [label str, der bytes] strEncodes der bytes into a standard 64-column wrapped PEM string.
pem-to-blockpem-to-block = fn [text str] anyConverts decoded PEM blocks to [ .pem label der ... ] for declarative parse-block matching.

Verified Doctest (codec/pem/b64-decode)

VEKO
use [pem = codec/pem]
enc = pem/b64-encode (bytes/from-str 'Veko 1.0')
dec = pem/b64-decode enc
if enc != 'VmVrbyAxLjA=' or (bytes/to-str dec) != 'Veko 1.0' [ err 'pem b64' ] else [ .ok ]

Module codec/toml

Exported Functions

SymbolSignatureDescription
decodedecode = fn [src str] mapDecodes a TOML v1.0 string into nested Veko maps, blocks, strings, integers, floats, and booleans.
encodeencode = fn [doc map] strEncodes a Veko map (including nested sub-tables) into a clean TOML v1.0 string.

Verified Doctest (codec/toml/decode)

VEKO
use [toml = codec/toml]
doc = toml/decode 'title = "Veko"\n[server]\nhost = "127.0.0.1"\nport = 8_080\ntls = true\ntags = ["pqc", "oro"]\n'
if doc.title != 'Veko' or doc.server.port != 8080 or doc.server.tls != true or (len doc.server.tags) != 2 [
  err 'toml decode'
] else [ .ok ]

Module codec/url

Exported Structs & Interfaces

  • Url: Url = struct { scheme str = ..., userinfo str = ..., host str = ..., port i64 = ..., path str = ..., query str = ..., fragment str = ... } — Structured representation of a parsed RFC 3986 URL.

Exported Functions

SymbolSignatureDescription
encode-componentencode-component = fn [s str] strPercent-encodes a URL component per RFC 3986 (spaces become %20).
decode-componentdecode-component = fn [s str] strDecodes a percent-encoded URL component (also converting + when plus_as_space is false -> leaves + literal).
parseparse = fn [raw_url str] UrlParses an RFC 3986 URL string into a Url struct.
formatformat = fn [u Url] strFormats a Url struct back into a canonical URL string.
parse-queryparse-query = fn [q str] map[str]Parses a URL query string ('a=1&b=hello%20world') into a map[str].
encode-queryencode-query = fn [params map[str]] strEncodes a map[str] into a percent-encoded query string.

Verified Doctest (codec/url/encode-component)

VEKO
use [url = codec/url]
e = url/encode-component 'hello world/v1'
if e != 'hello%20world%2Fv1' or (url/decode-component e) != 'hello world/v1' [ err 'url enc' ] else [ .ok ]

Module codec/vbin

Exported Functions

SymbolSignatureDescription
encodeencode = fn [v any] bytesEncodes any supported Veko value into canonical deterministic VBIN bytes.
decodedecode = fn [data bytes] anyDecodes VBIN bytes back into a Veko value (wire null maps to .null).

Verified Doctest (codec/vbin/encode)

VEKO
use [vbin = codec/vbin]
orig = { a = 1, b = -42, c = [true .null 'ok'], d = (bytes/from-str 'xy') }
enc = vbin/encode orig
dec = vbin/decode enc
if (map/get dec 'b') != -42 or (map/get dec 'c')[1] != .null [ err 'vbin roundtrip' ] else [ .ok ]

Module codec/wire

Exported Structs & Interfaces

  • Field: Field = struct { name str, kind enum, size i64 = ... } — Describes a single field in a binary wire packet schema.

Exported Functions

SymbolSignatureDescription
packpack = fn [schema block[Field], record map] bytesPacks a map of field values according to schema (block[Field]) into bytes.
unpackunpack = fn [schema block[Field], data bytes] mapUnpacks data according to schema (block[Field]) into a map of decoded values.

Verified Doctest (codec/wire/pack)

VEKO
use [w = codec/wire]
schema = [
  w/Field { name = 'version', kind = .u16_be }
  w/Field { name = 'flags',   kind = .u8 }
  w/Field { name = 'seq',     kind = .varint }
  w/Field { name = 'topic',   kind = .str_u16_be }
]
pkt = w/pack schema { version = 0x0303, flags = 5, seq = 300, topic = 'metrics' }
dec = w/unpack schema pkt
if (map/get dec 'version') != 0x0303 or (map/get dec 'seq') != 300 or (map/get dec 'topic') != 'metrics' [
  err 'wire roundtrip'
] else [ .ok ]

Module compress/deflate

Exported Functions

SymbolSignatureDescription
inflateinflate = fn [compressed bytes] bytesDecompresses raw RFC 1951 DEFLATE bytes (supports stored, fixed Huffman, and dynamic Huffman blocks).
deflatedeflate = fn [data bytes] bytesCompresses data into raw RFC 1951 DEFLATE bytes using LZ77 + Fixed Huffman (automatically selecting a Stored block if the input is incompressible).
zlib-compresszlib-compress = fn [data bytes] bytesCompresses data into RFC 1950 zlib format (0x78 0x9c + DEFLATE + Adler-32).
zlib-decompresszlib-decompress = fn [zbytes bytes] bytesDecompresses RFC 1950 zlib bytes and verifies the Adler-32 checksum.
gzip-compressgzip-compress = fn [data bytes] bytesCompresses data into RFC 1952 gzip format (10-byte header + DEFLATE + CRC-32 + ISIZE).
gzip-decompressgzip-decompress = fn [gz bytes] bytesDecompresses RFC 1952 gzip bytes and verifies both CRC-32 and ISIZE trailers.

Verified Doctest (compress/deflate/inflate)

VEKO
use [def = compress/deflate]
msg = bytes/from-str 'veko deflate deflate deflate compression test 12345 12345 12345'
comp = def/deflate msg
back = def/inflate comp
if back != msg or (len comp) >= (len msg) [ err 'deflate roundtrip' ] else [ .ok ]

Module compress/zstd

Exported Functions

SymbolSignatureDescription
zstd-frame?zstd-frame? = fn [data bytes] boolReturns true if data starts with the 4-byte RFC 8878 Zstandard frame magic 28 B5 2F FD.
compresscompress = fn [data bytes] bytesCompresses data into a wire-compliant RFC 8878 Zstandard frame.
decompressdecompress = fn [zbytes bytes] bytesDecompresses one or more concatenated RFC 8878 Zstandard frames (ignoring skippable frames).

Verified Doctest (compress/zstd/compress)

VEKO
use [zstd = compress/zstd]
mut msg = bytes/with-cap 256
_ = bytes/push-all mut msg (bytes/from-str 'Veko Zstd Frame Header: ')
mut i = 0
while i < 64 [
    _ = bytes/push mut msg 65
    i = i + 1
]
_ = bytes/push-all mut msg (bytes/from-str ' -- tail payload!')
z = zstd/compress msg
if (not (zstd/zstd-frame? z)) or (zstd/decompress z) != msg [ err 'zstd roundtrip' ] else [ .ok ]

Module image/png

Exported Structs & Interfaces

  • PngImage: PngImage = struct { width i64, height i64, pixels bytes } — Decoded RGBA32 PNG image surface (width * height * 4 bytes, top-down).

Exported Functions

SymbolSignatureDescription
encode-rgbaencode-rgba = fn [rgba bytes, w i64, h i64] bytesEncodes a top-down RGBA32 byte buffer (w * h * 4 bytes) into an RFC 2083 PNG byte stream. Uses adaptive per-row filtering (None, Sub, Up) for compact UI screenshot compression.
encodeencode = fn [c cv/Canvas] bytesEncodes a ui/canvas Canvas directly into PNG bytes.
decode-rgbadecode-rgba = fn [png_bytes bytes] PngImageDecodes an RFC 2083 8-bit PNG byte stream (Grayscale, RGB, Grayscale+Alpha, or RGBA; non-interlaced; all 5 scanline filters 0..4) into a top-down RGBA32 PngImage.
decodedecode = fn [png_bytes bytes] cv/CanvasDecodes a PNG byte stream directly into a ui/canvas Canvas.

Verified Doctest (image/png/encode-rgba)

VEKO
use [png = image/png, cv = ui/canvas]
mut c = cv/new-canvas 16 12
cv/clear mut c (cv/rgb 248 250 252)
cv/fill-rect mut c 2 2 8 6 (cv/rgb 2 132 199)
raw_png = png/encode c
dec = png/decode raw_png
p0 = cv/get-pixel dec 0 0
p1 = cv/get-pixel dec 4 4
if dec.width != 16 or dec.height != 12 or p0.r != 248 or p1.b != 199 [ err 'png roundtrip' ] else [ .ok ]

Module pkg/lock

Exported Structs & Interfaces

  • LockEntry: LockEntry = struct { name str, version str, source str, sha256 str, merkle_root str, signer str = ... } — One cryptographically pinned package dependency in veko.lock.
  • Lockfile: Lockfile = struct { version i64 = ..., packages block[LockEntry] } — Parsed representation of a veko.lock manifest.

Exported Functions

SymbolSignatureDescription
DEFAULT-REGISTRYDEFAULT-REGISTRY = fn [] strOfficial Veko HTTPS package registry root (veko-lang.org), overrideable via VEKO_REGISTRY.
registry-baseregistry-base = fn [] strReturns the active HTTPS registry base URL (VEKO_REGISTRY when set, otherwise https://veko-lang.org/pkg).
modules-homemodules-home = fn [] strResolves the shared user-level .veko_modules directory (VEKO_MODULES -> $HOME/.veko_modules / %USERPROFILE%\.veko_modules -> .veko/modules).
expand-spec-with-registryexpand-spec-with-registry = fn [spec str, reg_base str] strExpands a dependency specifier into its canonical source URL or local path: - 'http-extra@1.2.0' -> 'https://veko-lang.org/pkg/http-extra/1.2.0.vkp' (or VEKO_REGISTRY) - 'https://host/pkg.vkp' -> unchanged decentralized URL - '../shared' or 'vendor/pkg.vkp' -> unchanged local path
resolve-dep-specresolve-dep-spec = fn [spec str] strExpands spec using the active registry-base.
infer-dep-nameinfer-dep-name = fn [spec str] strExtracts the default dependency alias from a specifier ('sqlite-orm@1.0.2' -> 'sqlite-orm', 'https://.../foo-1.0.vkp' -> 'foo').
fetch-vkp-urlfetch-vkp-url = fn [url str] bytesDownloads raw binary .vkp bytes over HTTP/HTTPS across all 3 execution tracks (lib/net/client.vk).
encodeencode = fn [lf Lockfile] strFormats a Lockfile into canonical, idempotent homoiconic veko.lock text.
decodedecode = fn [src str] LockfileZero-eval deterministic parser for homoiconic veko.lock files.
lock-vkp-byteslock-vkp-bytes = fn [dep_name str, source_ref str, raw bytes, trust_keys block[str]] LockEntryBuilds a LockEntry from a signed .vkp bundle raw (verifying trust_keys when non-empty, or self-signature otherwise).
verify-locked-bytesverify-locked-bytes = fn [entry LockEntry, raw bytes, extra_trust block[str]] vkp/VkpBundleVerifies raw .vkp bytes against every cryptographic field pinned in entry (sha256, merkle_root, and signer + extra_trust).
global-cache-pathglobal-cache-path = fn [entry LockEntry] strReturns the global content-addressed cache path <~/.veko_modules>/cache/<sha256>.vkp for entry.
installed-pkg-pathinstalled-pkg-path = fn [entry LockEntry] strReturns the human-readable installed snapshot path <~/.veko_modules>/pkgs/<name>@<version>.vkp for entry.
cache-pathcache-path = fn [proj_dir str, entry LockEntry] strReturns the workspace-local content-addressed cache path <proj_dir>/.veko/pkg_cache/<sha256>.vkp for entry.
locate-cached-vkplocate-cached-vkp = fn [proj_dir str, entry LockEntry] strResolves cached .vkp path preferring ~/.veko_modules/cache/<sha256>.vkp if present, then <proj_dir>/.veko/pkg_cache/<sha256>.vkp.
find-entryfind-entry = fn [lf Lockfile, dep_name str] LockEntryLooks up dep_name inside lf (err if absent).

Verified Doctest (pkg/lock/expand-spec-with-registry)

VEKO
use [lk = pkg/lock]
u1 = lk/expand-spec-with-registry 'sqlite-orm@1.0.2' 'https://veko-lang.org/pkg'
u2 = lk/expand-spec-with-registry 'https://cdn.example.org/p.vkp' 'https://veko-lang.org/pkg'
if u1 != 'https://veko-lang.org/pkg/sqlite-orm/1.0.2.vkp' or u2 != 'https://cdn.example.org/p.vkp' [ err 'spec expand failed' ] else [ .ok ]

Module pkg/vkp

Exported Structs & Interfaces

  • VkpEntry: VkpEntry = struct { path str, source bytes, sha256 bytes } — One module source file stored inside a 'VKP1' bundle.
  • VkpSig: VkpSig = struct { alg enum, pubkey bytes, signature bytes } — One cryptographic signature attached to a 'VKP1' bundle.
  • VkpBundle: VkpBundle = struct { version i64, manifest map, entries block[VkpEntry], merkle_root bytes, payload_digest bytes, signatures block[VkpSig] } — Verified, unpacked representation of a 'VKP1' signed package bundle.

Exported Functions

SymbolSignatureDescription
merkle-rootmerkle-root = fn [entries block[VkpEntry]] bytesComputes the deterministic 32-byte SHA-256 Merkle root over entries (assumed sorted by path).
format-trust-keyformat-trust-key = fn [alg enum, pubkey bytes] strFormats a trust-key string ('ed25519:<hex>' or 'mldsa65:<hex>') for veko.vk trust-keys.
packpack = fn [manifest map, files map, ed25519_seed bytes, mldsa_kp any] bytesPacks manifest and files (map of logical path -> str/bytes) into a 'VKP1' bundle signed with Ed25519 and/or ML-DSA-65. Pass bytes/with-cap 0 for ed25519_seed or .none for mldsa_kp to omit that signature algorithm.
pack-ed25519pack-ed25519 = fn [manifest map, files map, ed25519_seed bytes] bytesConvenience wrapper that packs and signs a 'VKP1' bundle with a 32-byte Ed25519 seed.
pack-mldsa65pack-mldsa65 = fn [manifest map, files map, mldsa_kp dsa/KeyPair] bytesConvenience wrapper that packs and signs a 'VKP1' bundle with a FIPS 204 ML-DSA-65 keypair.
unpackunpack = fn [raw bytes] VkpBundleUnpacks a 'VKP1' bundle and verifies its structural integrity, path safety, per-entry SHA-256 hashes, and Merkle root.
verifyverify = fn [raw bytes, trusted_keys block[str]] VkpBundleUnpacks and cryptographically verifies a 'VKP1' bundle against trusted_keys (['ed25519:<hex>', 'mldsa65:<hex>']). Requires every embedded signature to be valid AND at least one signature to match a key in trusted_keys.
verify-selfverify-self = fn [raw bytes] VkpBundleVerifies that all embedded signatures in raw are cryptographically valid against their embedded public keys (no trust-anchor check).
extract-moduleextract-module = fn [bundle VkpBundle, rel_path str] strExtracts the UTF-8 .vk source string for rel_path from a verified VkpBundle.

Verified Doctest (pkg/vkp/pack)

VEKO
use [vkp = pkg/vkp, x25 = crypto/x25519]
seed = bytes/from-str '0123456789abcdef0123456789abcdef'
pk = x25/ed25519-pubkey seed
raw = vkp/pack-ed25519 { name = 'demo', version = '1.0.0' } { 'mod.vk' = 'pub answer = fn [] i64 [ 42 ]' } seed
b = vkp/verify raw [(vkp/format-trust-key .ed25519 pk)]
if (vkp/extract-module b 'mod.vk') != 'pub answer = fn [] i64 [ 42 ]' [ err 'vkp roundtrip' ] else [ .ok ]