/* SPDX-License-Identifier: Apache-2.0 */ /* The settlement kernel: the keystone loop as portable C. canonicalize -> key -> lookup -> verify -> decide -> record -> receipt (OER/2 draft 0.1 as profiled by extensions/oer-receipts.md). */ #ifndef SETTLE_H #define SETTLE_H #include #include #define SETTLE_RECORDS 4096 #define SETTLE_ANSWER 24 typedef struct { double compute_j, movement_j, idle_alloc_j, shared_alloc_j, upstream_j; double latency_s; const char *method; const char *weakest_how, *weakest_input; } settle_meter_t; typedef struct { uint8_t key[32]; char answer[SETTLE_ANSWER]; double created, valid_until, deriv_j; uint32_t reuse, id; uint8_t used; } settle_record_t; typedef struct { int status; const char *outcome; char answer[SETTLE_ANSWER]; uint32_t record_id; uint32_t reuse; char receipt_hash[72]; double joules_total; } settle_result_t; typedef struct { settle_record_t rec[SETTLE_RECORDS]; uint32_t rec_next, receipt_n; char prev_hash[72]; uint8_t pk[32], sk[64]; double temperature_k, validity_s, cycle_j; uint32_t bits_committed; const char *boundary, *rules_hash; } settle_ctx_t; int settle_init(settle_ctx_t *c, const uint8_t seed[32], double temperature_k, double validity_s); /* Runs the loop for one question. cls is 'A' (charging authorization) or 'B' (sensor check), id the canonical question id. Writes the full receipt JSON (with chain) into out. Returns 0 on success. */ int settle_decide(settle_ctx_t *c, char cls, uint32_t id, double now, const settle_meter_t *m, char *out, size_t outlen, settle_result_t *res); /* Records as a JSON object {id: {key, answer, created, valid_until}}, for vector files. */ int settle_records_json(const settle_ctx_t *c, char *out, size_t outlen); void settle_pk_hex(const settle_ctx_t *c, char out[65]); #endif