Files
dat-thang/extra/dat-dpi/inc/sleep_proof.h
T
divorce b735900f2e 0.0.002
ddat interop with dat js
cable interop with cabal js
ddat's frontend = dat-thang
cable fe = cable-thang
dillo support based on cel's dillo-dat
bootstrap node
xplatform support

Signed-off-by: divo <418@cryspace.space>
2026-10-19 00:17:02 -04:00

44 lines
1.5 KiB
C

#ifndef SLEEP_PROOF_H
#define SLEEP_PROOF_H
#include <stddef.h>
#include <stdint.h>
#include "sleep_feed.h"
#define SLEEP_PROOF_HASH_BYTES 32u
#define SLEEP_PROOF_MAX_NODES 64u
typedef struct sleep_proof_node {
uint64_t index;
uint64_t length;
uint8_t hash[SLEEP_PROOF_HASH_BYTES];
} sleep_proof_node_t;
typedef struct sleep_proof {
uint64_t block;
uint64_t block_length;
uint8_t block_hash[SLEEP_PROOF_HASH_BYTES];
sleep_proof_node_t nodes[SLEEP_PROOF_MAX_NODES];
size_t node_count;
sleep_proof_node_t roots[SLEEP_PROOF_MAX_NODES];
size_t root_count;
uint8_t signature[64];
int has_signature;
} sleep_proof_t;
void sleep_proof_init(sleep_proof_t *proof, uint64_t block);
int sleep_proof_add_node(sleep_proof_t *proof, uint64_t index,
uint64_t length, const uint8_t hash[32]);
int sleep_proof_add_root(sleep_proof_t *proof, uint64_t index,
uint64_t length, const uint8_t hash[32]);
int sleep_proof_create(const sleep_feed_t *feed, uint64_t block,
sleep_proof_t *proof);
int sleep_proof_from_nodes(uint64_t block, const uint8_t *value,
size_t value_len, const sleep_proof_node_t *nodes,
size_t node_count, const uint8_t signature[64],
uint64_t feed_length, sleep_proof_t *proof);
int sleep_proof_encode(const sleep_proof_t *proof, uint8_t *out,
size_t capacity, size_t *written);
int sleep_proof_decode(sleep_proof_t *proof, const uint8_t *input,
size_t input_len);
int sleep_proof_verify(const sleep_proof_t *proof, const uint8_t *block,
size_t block_len, const uint8_t public_key[32]);
#endif