/*
 * vault1984 CLI — QuickJS bridge
 * Exposes BearSSL crypto primitives to JavaScript.
 */

#ifndef V84_JSBRIDGE_H
#define V84_JSBRIDGE_H

#include <stddef.h>

/* Initialize QuickJS runtime and load crypto/*.js modules */
int jsbridge_init(void);

/* Cleanup QuickJS runtime */
void jsbridge_cleanup(void);

/*
 * Encrypt a field value. Key length determines tier (8=L1, 16=L2, 32=L3).
 * Uses crypto.js encrypt_field() — the single source of truth.
 * Returns base64-encoded ciphertext (caller frees). NULL on error.
 */
char *jsbridge_encrypt_field(const unsigned char *key, size_t key_len,
                             const char *field_label, const char *plaintext);

/*
 * Decrypt a field value. Key length determines tier (8=L1, 16=L2, 32=L3).
 * Uses crypto.js decrypt_field() — the single source of truth.
 * Returns plaintext string (caller frees). NULL on error.
 */
char *jsbridge_decrypt_field(const unsigned char *key, size_t key_len,
                             const char *field_label, const char *ciphertext_b64);

/*
 * Generate TOTP code from a base32-encoded seed.
 * Returns 6-digit code string (caller frees). NULL on error.
 */
char *jsbridge_totp(const char *seed_b32);

/* Evaluate JS code and return result as string (caller frees). NULL on error. */
char *jsbridge_eval(const char *code);

/* Load and evaluate a JS file. Returns 0 on success. */
int jsbridge_load(const char *filename);

#endif
