Skip to main content

provable_sdk/
types.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
5pub struct ProveSingleHashResponse {
6    pub success: bool,
7    pub hash: Option<String>,
8    pub timeuuid: Option<String>,
9    pub encoding: Option<String>,
10    pub error: Option<String>,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
14pub struct GetRecordResponse {
15    pub data_item: String,
16    pub data_type: String,
17    pub hash_item: String,
18    pub hash_type: String,
19    pub position: i64,
20    pub prev_hash: Option<String>,
21    pub ts: String,
22    #[serde(default)]
23    pub data_item_hex: Option<String>,
24    #[serde(default)]
25    pub hash_item_hex: Option<String>,
26    #[serde(default)]
27    pub prev_hash_hex: Option<String>,
28    #[serde(default)]
29    pub uuid_hex: Option<String>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
33pub struct GetRecordByDataItemResponse {
34    #[serde(default)]
35    pub records: Vec<GetRecordResponse>,
36    pub count: usize,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
40pub struct ComputeHashRequest {
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub prev_hash: Option<String>,
43    pub data_type: String,
44    pub data_item: String,
45    pub timeuuid: String,
46    pub hash_type: String,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
50pub struct ComputeHashResponse {
51    pub hash: String,
52    pub hash_type: String,
53    pub input_size: usize,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
57pub struct MerkleProofResponse {
58    pub success: bool,
59    pub data_type: String,
60    pub hash_item: String,
61    #[serde(default)]
62    pub proof: Vec<String>,
63    pub root: String,
64    pub position: i64,
65    pub levels: usize,
66    #[serde(default)]
67    pub level_counts: Vec<usize>,
68    #[serde(default)]
69    pub level_starts: Vec<i64>,
70    #[serde(default)]
71    pub message: Option<String>,
72    #[serde(default)]
73    pub error: Option<String>,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
77pub struct HashExistenceRequest {
78    pub data_type: String,
79    pub level: usize,
80    pub position: i64,
81    pub hash: String,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
85pub struct HashExistenceResponse {
86    pub exists: bool,
87    pub level: usize,
88    pub position: i64,
89    pub data_type: String,
90    #[serde(default)]
91    pub found_hash: Option<String>,
92    #[serde(default)]
93    pub message: Option<String>,
94    #[serde(default)]
95    pub error: Option<String>,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
99pub struct HashBatchRequest {
100    pub data_type: String,
101    pub level: usize,
102    pub start: i64,
103    pub hashes: Vec<String>,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
107pub struct HashBatchResponse {
108    pub data_type: String,
109    pub level: usize,
110    pub start: i64,
111    pub count: usize,
112    #[serde(default)]
113    pub results: Vec<i32>,
114    pub matches: usize,
115    pub mismatches: usize,
116    #[serde(default)]
117    pub error: Option<String>,
118    #[serde(default)]
119    pub message: Option<String>,
120}
121
122#[derive(Debug, Clone, Default, PartialEq, Eq)]
123pub struct VerifyRequest {
124    pub data_type: Option<String>,
125    pub data_item: Option<String>,
126    pub kayros_hash: Option<String>,
127    pub api_key: Option<String>,
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
131pub struct VerifyLevelCheck {
132    pub level: usize,
133    pub position: i64,
134    #[serde(default)]
135    pub hash: Option<String>,
136}
137
138#[derive(Debug, Clone, Default, PartialEq, Eq)]
139pub struct VerifyWithInclusionRequest {
140    pub verify_request: VerifyRequest,
141    pub trusted_root_hash: Option<String>,
142    pub trusted_level: Option<usize>,
143    pub trusted_position: Option<i64>,
144    pub levels_hash_type: Option<String>,
145    pub verify_batch_existence: bool,
146    pub level_checks: Vec<VerifyLevelCheck>,
147}
148
149#[derive(Debug, Clone, Default, PartialEq, Eq)]
150pub struct VerifyMerkleProofWithDetailsRequest {
151    pub proof: MerkleProofInput,
152    pub levels_hash_type: Option<String>,
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
156pub struct NormalizedKayrosRecord {
157    pub data_type: String,
158    pub data_type_hex: String,
159    pub data_item: String,
160    pub kayros_hash: String,
161    #[serde(default)]
162    pub prev_hash: Option<String>,
163    pub hash_type: String,
164    pub uuid: String,
165    pub timestamp: String,
166    pub position: i64,
167    pub raw: GetRecordResponse,
168}
169
170#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
171pub struct NormalizedMerkleProof {
172    pub data_type: String,
173    pub hash_item: String,
174    pub proof: Vec<String>,
175    pub root: String,
176    pub position: i64,
177    pub levels: usize,
178    pub level_counts: Vec<usize>,
179    pub level_starts: Vec<i64>,
180    pub raw: MerkleProofResponse,
181}
182
183#[derive(Debug, Clone, PartialEq, Eq)]
184pub enum MerkleProofInput {
185    Response(MerkleProofResponse),
186    Normalized(NormalizedMerkleProof),
187}
188
189impl Default for MerkleProofInput {
190    fn default() -> Self {
191        Self::Response(MerkleProofResponse::default())
192    }
193}
194
195impl From<MerkleProofResponse> for MerkleProofInput {
196    fn from(value: MerkleProofResponse) -> Self {
197        Self::Response(value)
198    }
199}
200
201impl From<NormalizedMerkleProof> for MerkleProofInput {
202    fn from(value: NormalizedMerkleProof) -> Self {
203        Self::Normalized(value)
204    }
205}
206
207#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
208pub struct MerkleProofLevel {
209    pub level: usize,
210    pub start: i64,
211    pub count: usize,
212    pub hashes: Vec<String>,
213}
214
215#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
216pub struct MerkleProofCompatibilityMismatch {
217    pub kind: String,
218    #[serde(skip_serializing_if = "Option::is_none")]
219    pub level: Option<usize>,
220    #[serde(skip_serializing_if = "Option::is_none")]
221    pub position: Option<i64>,
222    #[serde(skip_serializing_if = "Option::is_none")]
223    pub previous_index: Option<usize>,
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub next_index: Option<usize>,
226    #[serde(skip_serializing_if = "Option::is_none")]
227    pub previous_position: Option<i64>,
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub next_position: Option<i64>,
230    #[serde(skip_serializing_if = "Option::is_none")]
231    pub previous_hash: Option<String>,
232    #[serde(skip_serializing_if = "Option::is_none")]
233    pub next_hash: Option<String>,
234    pub message: String,
235}
236
237#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
238pub struct MerkleProofCompatibilityResult {
239    pub compatible: bool,
240    pub checked_entries: usize,
241    pub previous: NormalizedMerkleProof,
242    pub next: NormalizedMerkleProof,
243    pub previous_levels: Vec<MerkleProofLevel>,
244    pub next_levels: Vec<MerkleProofLevel>,
245    pub mismatches: Vec<MerkleProofCompatibilityMismatch>,
246}
247
248#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
249pub struct LevelCheckResult {
250    pub level: usize,
251    pub position: i64,
252    pub hash: String,
253    pub valid: bool,
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub exists: Option<bool>,
256    #[serde(skip_serializing_if = "Option::is_none")]
257    pub found_hash: Option<String>,
258    #[serde(skip_serializing_if = "Option::is_none")]
259    pub message: Option<String>,
260}
261
262#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
263pub struct BatchExistenceCheckResult {
264    pub level: usize,
265    pub start: i64,
266    pub hashes: Vec<String>,
267    pub valid: bool,
268    pub results: Vec<i32>,
269    pub matches: usize,
270    pub mismatches: usize,
271}
272
273#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
274#[serde(rename_all = "camelCase")]
275pub struct VerifyResultDetails {
276    pub lookup_mode: String,
277    pub record_found: bool,
278    pub ambiguous: Option<bool>,
279    pub ambiguous_count: Option<usize>,
280    pub data_type_match: Option<bool>,
281    pub data_item_match: Option<bool>,
282    pub kayros_hash_match: Option<bool>,
283    pub record_hash_match: Option<bool>,
284    pub chain_link_match: Option<bool>,
285    pub uuid_timestamp_match: Option<bool>,
286    pub proof_fetched: Option<bool>,
287    pub proof_data_type_match: Option<bool>,
288    pub proof_hash_item_match: Option<bool>,
289    pub proof_path_match: Option<bool>,
290    pub target_position_match: Option<bool>,
291    pub trusted_root_match: Option<bool>,
292    pub trusted_level_match: Option<bool>,
293    pub batch_existence_match: Option<bool>,
294    pub levels_hash_type: Option<String>,
295    pub pending: Option<bool>,
296    pub max_level: Option<usize>,
297    pub max_level_position: Option<i64>,
298    pub max_level_hash: Option<String>,
299    pub computed_record_hash: Option<String>,
300    pub local_root_hash: Option<String>,
301    pub record: Option<NormalizedKayrosRecord>,
302    pub previous_record: Option<NormalizedKayrosRecord>,
303    pub proof: Option<NormalizedMerkleProof>,
304    pub level_checks: Option<Vec<LevelCheckResult>>,
305    pub batch_checks: Option<Vec<BatchExistenceCheckResult>>,
306}
307
308#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
309pub struct VerifyResult {
310    pub valid: bool,
311    #[serde(default)]
312    pub error: Option<String>,
313    #[serde(default)]
314    pub details: Option<VerifyResultDetails>,
315}
316
317#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
318#[serde(rename_all = "camelCase")]
319pub struct VerifyMerkleProofWithDetailsResult {
320    pub valid: bool,
321    pub pending: bool,
322    pub status: String,
323    pub message: String,
324    #[serde(default)]
325    pub error: Option<String>,
326    #[serde(default)]
327    pub details: Vec<String>,
328    #[serde(default)]
329    pub position_path: Vec<i64>,
330    pub levels_hash_type: String,
331    #[serde(default)]
332    pub computed_root: Option<String>,
333    pub max_level: i64,
334    pub max_level_position: i64,
335    pub max_level_hash: String,
336    #[serde(default)]
337    pub proof: Option<NormalizedMerkleProof>,
338}
339
340#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
341pub struct DatabaseQuery {
342    #[serde(default)]
343    pub data_type: Option<String>,
344    #[serde(default)]
345    pub hash_type: Option<String>,
346    #[serde(default)]
347    pub min_timestamp: Option<String>,
348    #[serde(default)]
349    pub max_timestamp: Option<String>,
350    pub limit: usize,
351    pub offset: usize,
352    pub order_by: String,
353}
354
355#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
356pub struct HashRecord {
357    pub timestamp: String,
358    pub data_type: String,
359    pub data_item: String,
360    pub hash_type: String,
361    pub hash_item: String,
362}
363
364#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
365pub struct DatabaseStats {
366    pub total_hashes: i64,
367    #[serde(default)]
368    pub count_by_type: HashMap<String, i64>,
369    pub min_timestamp: String,
370    pub max_timestamp: String,
371    pub timestamp_range: String,
372}
373
374#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
375pub struct ColumnInfo {
376    pub name: String,
377    pub r#type: String,
378}
379
380#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
381pub struct TableBrowseRequest {
382    pub table_name: String,
383    pub offset: usize,
384    pub limit: usize,
385    #[serde(default)]
386    pub order_by: Option<String>,
387    #[serde(default)]
388    pub search_term: Option<String>,
389    #[serde(default)]
390    pub search_column: Option<String>,
391}
392
393#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
394pub struct DatabaseRecord {
395    pub data_type: String,
396    pub data_item_hex: String,
397    pub uuid_hex: String,
398    pub hash_item_hex: String,
399    #[serde(default)]
400    pub prev_hash_hex: Option<String>,
401    pub hash_type: String,
402    pub timestamp: String,
403}
404
405#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
406pub struct HashVerifyRequest {
407    pub prev_hash: String,
408    pub data_type: String,
409    pub data_item: String,
410    pub uuid: String,
411    pub hash_type: String,
412}
413
414#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
415pub struct HashVerifyResult {
416    pub computed_hash: String,
417    pub hash_input_hex: String,
418}
419
420#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
421pub struct SingleHashRequest {
422    pub data_type: String,
423    pub data_item: String,
424}
425
426#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
427pub struct SingleHashResponse {
428    pub success: bool,
429    pub message: String,
430    pub data_type: String,
431    pub data_item: String,
432    pub computed_hash_hex: String,
433    pub timeuuid_hex: String,
434    pub data_type_hex: String,
435    pub data_item_hex: String,
436}
437
438#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
439pub struct ApiResponse<T> {
440    pub success: bool,
441    #[serde(default)]
442    pub message: Option<String>,
443    #[serde(default)]
444    pub data: Option<T>,
445    #[serde(default)]
446    pub error: Option<String>,
447}