2026-04-09 17:43:58 +02:00
|
|
|
#ifndef TYPES_HPP
|
|
|
|
|
#define TYPES_HPP
|
|
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2026-04-20 16:08:13 +02:00
|
|
|
#include <stdlib.h>
|
2026-04-10 18:09:23 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#define STATUS_MESSAGE_LENGTH 256
|
2026-04-10 16:22:33 +02:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
2026-04-09 17:43:58 +02:00
|
|
|
|
|
|
|
|
/// Mutable byte buffer.
|
2026-04-10 16:22:33 +02:00
|
|
|
typedef struct Bytes {
|
|
|
|
|
uint8_t* data;
|
|
|
|
|
size_t size;
|
|
|
|
|
} Bytes;
|
2026-04-09 17:43:58 +02:00
|
|
|
|
|
|
|
|
/// Immutable byte buffer.
|
2026-04-10 16:22:33 +02:00
|
|
|
typedef struct ConstBytes {
|
|
|
|
|
const uint8_t* data;
|
|
|
|
|
size_t size;
|
|
|
|
|
} ConstBytes;
|
2026-04-09 17:43:58 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
typedef enum StatusCode {
|
|
|
|
|
StatusCode_Ok = 0,
|
|
|
|
|
StatusCode_DynError = 1,
|
|
|
|
|
StatusCode_InvalidInput = 2,
|
|
|
|
|
StatusCode_OutOfMemory = 3,
|
|
|
|
|
} StatusCode;
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 18:09:23 +02:00
|
|
|
static inline bool status_code_is_ok(const StatusCode code) {
|
2026-04-10 16:22:33 +02:00
|
|
|
return code == StatusCode_Ok;
|
|
|
|
|
}
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 18:09:23 +02:00
|
|
|
static inline bool status_code_is_error(const StatusCode code) {
|
2026-04-10 16:22:33 +02:00
|
|
|
return !status_code_is_ok(code);
|
|
|
|
|
}
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
/// A status code with an optional human-readable description.
|
|
|
|
|
typedef struct Status {
|
|
|
|
|
StatusCode code;
|
2026-04-10 18:09:23 +02:00
|
|
|
char message[STATUS_MESSAGE_LENGTH];
|
2026-04-10 16:22:33 +02:00
|
|
|
} Status;
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 18:09:23 +02:00
|
|
|
static inline Status status_new(const StatusCode code, const char* message) {
|
|
|
|
|
Status status = {code, {}};
|
|
|
|
|
if (message != NULL) {
|
|
|
|
|
strncpy(status.message, message, STATUS_MESSAGE_LENGTH - 1);
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
static inline Status status_from_code(const StatusCode code) { return status_new(code, NULL); }
|
|
|
|
|
static inline Status status_ok() { return status_from_code(StatusCode_Ok); }
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 18:09:23 +02:00
|
|
|
static inline bool status_is_ok(const Status status) { return status_code_is_ok(status.code); }
|
|
|
|
|
static inline bool status_is_error(const Status status) { return status_code_is_error(status.code); }
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-20 16:08:13 +02:00
|
|
|
/// Inputs for witness generation.
|
|
|
|
|
typedef struct WitnessInput {
|
|
|
|
|
/// Contents of the circuit's .dat file.
|
|
|
|
|
const ConstBytes dat;
|
|
|
|
|
/// Null-terminated JSON string of circuit inputs.
|
|
|
|
|
const char* inputs_json;
|
|
|
|
|
} WitnessInput;
|
|
|
|
|
|
|
|
|
|
static inline void free_bytes(Bytes* bytes) {
|
|
|
|
|
if (bytes == NULL) return;
|
|
|
|
|
free(bytes->data);
|
|
|
|
|
bytes->data = NULL;
|
|
|
|
|
bytes->size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
#ifdef __cplusplus
|
2026-04-10 12:15:33 +02:00
|
|
|
}
|
2026-04-10 16:22:33 +02:00
|
|
|
#endif
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-09 17:43:58 +02:00
|
|
|
#endif // TYPES_HPP
|