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

crypto/seal

lib/crypto/seal.vk

lib/crypto/seal.vk Pure-Veko authenticated envelope sealing (pub sealed Sealed) with RAII .secret unsealing. Prevents external construction or mutation of sealed envelopes and zeroizes plaintext after callback exit. Zero capabilities required.

Sealed struct sealed
signature
sealed Sealed = struct { version i64, algorithm enum, nonce bytes, aad bytes, ciphertext bytes }

Opaque sealed ciphertext envelope (cannot be constructed or mutated outside crypto/seal).

signature
encrypt = fn [key bytes, plaintext bytes, aad bytes] Sealed

Seals plaintext under a 32-byte AES-256-GCM key and associated data aad using a fresh 12-byte CSPRNG nonce.

Executable Example
veko
use [seal = crypto/seal]
key = bytes/fill 32 0x33
env = seal/encrypt key (bytes/from-str 'top-secret-token') (bytes/from-str 'ctx=vault')
ok_len = seal/with-open env key fn [pt] [ len pt ]
if ok_len != 16 [ err 'seal roundtrip' ] else [ .ok ]
signature
encrypt-with-nonce = fn [key bytes, nonce bytes, plaintext bytes, aad bytes] Sealed

Deterministic sealing with an explicit 12-byte nonce (for reproducible test vectors; never reuse a nonce!).

signature
with-open = fn [env Sealed, key bytes, use_fn fn[bytes->any]] any

Unseals env under key, passes the plaintext into use_fn, zeroizes the temporary plaintext buffer unconditionally via defer, and returns the non-secret result of (use_fn pt).

signature
to-bytes = fn [env Sealed] bytes

Serializes a Sealed envelope into portable wire bytes ('VKSL' || ver(u8) || nonce_len(u8) || aad_len(u16_be) || nonce || aad || ct).

signature
from-bytes = fn [wire bytes] Sealed

Parses portable wire bytes produced by seal/to-bytes back into a Sealed envelope.