Skip to main content

Module crypto

Module crypto 

Source
Expand description

Cryptographic operations — hashing, AEAD, KDF, signing (T-crypto).

This module defines the VibeScript crypto namespace. The actual crypto implementations live in the host (qualia-core-db’s cryptographic_library), so all operations dispatch through the Host ABI. vibe itself has no crypto dependencies — it defines the types and the dispatch contract.

§Namespace

import "crypto" as crypto;

fn main() {
  let h = crypto.sha256("hello");
  let sig = crypto.sign("key:ed25519:0", h);
  let ok = crypto.verify("key:ed25519:0", h, sig);
}

§Operations

  • Hashing: crypto.sha256, crypto.sha512, crypto.blake3 — pure, deterministic. Input: String or hex. Output: Record { algorithm, hex, bytes }.
  • KDF: crypto.hkdf_sha256(ikm, info, length) — key derivation.
  • AEAD encrypt: crypto.aead_encrypt(algorithm, key, nonce, plaintext, aad) — returns Record { ciphertext, tag, nonce }.
  • AEAD decrypt: crypto.aead_decrypt(algorithm, key, nonce, ciphertext, tag, aad) — returns plaintext or error.
  • Signing: crypto.sign(key_id, data) — returns signature.
  • Verification: crypto.verify(key_id, data, signature) — returns Bool.

§Fail-closed

Default Host behavior is E702 (no crypto provider on this host). A host with a crypto library overrides these methods.

Reference: qualia-core-db specialized_libs/cryptographic_library/.

Constants§

AEAD_ALGORITHMS
Supported AEAD algorithms.
CRYPTO_CAPABILITIES
The list of crypto namespace capability IDs.
HASH_ALGORITHMS
Supported hash algorithms.
SIGNING_ALGORITHMS
Supported signing algorithms.
ZK_CAPABILITIES
The list of ZK namespace capability IDs.

Functions§

encrypted_data_value
Build an encrypted data Record value. { ciphertext_hex: String, tag_hex: String, nonce_hex: String, algorithm: String }
extract_f64_arg
Extract an f64 argument from args, or return a diagnostic.
extract_string_arg
Extract a String argument from args, or return a diagnostic.
extract_u64_arg
Extract a U64 argument from args, or return a diagnostic.
from_hex
Convert a hex string to bytes. Returns None on invalid hex.
hash_result_value
Build a hash result Record value. { algorithm: String, hex: String, bytes: U64 }
sha256_bytes
Compute an exact FIPS 180-4 256-bit SHA-256 digest over data.
sha256_hex
Compute lowercase 64-character hex string of the FIPS 180-4 SHA-256 digest of data.
signature_value
Build a signature Record value. { key_id: String, signature_hex: String, algorithm: String }
to_hex
Convert bytes to a hex string.
zk_matmul_result_value
Build a ZK matmul proof Record value. { valid: Bool, result: List<I64> }
zk_proof_value
Build a ZK proof Record value. { proof_hex: String, vk_hex: String, proof_id: String, circuit_id: String }
zk_verification_value
Build a ZK verification result Record value. { valid: Bool, proof_id: String, verification_time_ms: U64 }