Skip to main content
Voltaire compiles its core algorithms once in Zig, Rust, and C and exposes them across every target language through a stable C ABI defined in packages/voltaire-zig/src/c_api.zig and packages/voltaire-zig/src/primitives.h.

Language Responsibilities

C ABI Boundary (c_api.zig & primitives.h)

All foreign language callers cross the same flat C calling convention:
  • Fixed-size buffers (20-byte addresses, 32-byte hashes/U256s, 64/65-byte signatures) are passed by pointer from caller-allocated memory to avoid cross-allocator frees.
  • Return values are c_int status codes: 0 on success, negative constants on error (e.g. invalid hex, invalid length, invalid signature, buffer too small).
  • Regenerate the C header whenever c_api.zig signatures change:
This updates packages/voltaire-zig/src/primitives.h, which is mirrored into Swift (packages/voltaire-swift/Sources/CVoltaire/include/primitives.h), Go, Python, and C packages.

Zig to Rust (crypto_wrappers)

build.zig invokes cargo build automatically to compile libcrypto_wrappers.a (or crypto_wrappers.lib on MSVC) and links it into the crypto Zig module. Zig imports the Rust extern "C" functions via @cImport and translates negative status codes into Zig error unions (error.InvalidPoint, error.PairingFailed).

Zig to C (blst, c-kzg-4844, libwally-core)

packages/voltaire-zig/lib/c_libs.zig compiles vendored C sources directly with Zig’s bundled C compiler (zig cc):
  • blst — Compiled as libblst.a and linked into c_kzg and crypto.
  • c-kzg-4844 — Compiled as libc_kzg.a with Zig bindings at packages/voltaire-zig/lib/c-kzg-4844/bindings/zig/root.zig.
  • libwally-core — Lazily built only when -Dwith-c-api=true is passed.

Native FFI Bindings

Bun FFI (@tevm/voltaire/native)

Uses bun:ffi (dlopen) to load libprimitives_ts_native.{dylib,so,dll} directly from zig-out/native/ (or prebuilt platform binaries). Node.js does not support bun:ffi; use @tevm/voltaire (pure JS) or @tevm/voltaire/wasm in Node.

Swift (packages/voltaire-swift)

Package.swift defines a C system target CVoltaire pointing to zig-out/native (-lprimitives_ts_native) and a Swift target Voltaire wrapping C status codes into VoltaireError.

Go (packages/voltaire-go)

Uses CGo against primitives.h and the Zig-built static/dynamic library:

Cross-Language Error Mapping

  • Build System — Cross-compilation and generate-header
  • WASM — Compiling c_api.zig to WebAssembly
  • Swift Bindings — macOS/iOS usage and API reference