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 }