provable-sdk 0.1.2

Provable SDK for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct ProveSingleHashResponse {
    pub success: bool,
    pub hash: Option<String>,
    pub timeuuid: Option<String>,
    pub encoding: Option<String>,
    pub error: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct GetRecordResponse {
    pub data_item: String,
    pub data_type: String,
    pub hash_item: String,
    pub hash_type: String,
    pub position: i64,
    pub prev_hash: Option<String>,
    pub ts: String,
    #[serde(default)]
    pub data_item_hex: Option<String>,
    #[serde(default)]
    pub hash_item_hex: Option<String>,
    #[serde(default)]
    pub prev_hash_hex: Option<String>,
    #[serde(default)]
    pub uuid_hex: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct GetRecordByDataItemResponse {
    #[serde(default)]
    pub records: Vec<GetRecordResponse>,
    pub count: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct ComputeHashRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prev_hash: Option<String>,
    pub data_type: String,
    pub data_item: String,
    pub timeuuid: String,
    pub hash_type: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct ComputeHashResponse {
    pub hash: String,
    pub hash_type: String,
    pub input_size: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct MerkleProofResponse {
    pub success: bool,
    pub data_type: String,
    pub hash_item: String,
    #[serde(default)]
    pub proof: Vec<String>,
    pub root: String,
    pub position: i64,
    pub levels: usize,
    #[serde(default)]
    pub level_counts: Vec<usize>,
    #[serde(default)]
    pub level_starts: Vec<i64>,
    #[serde(default)]
    pub message: Option<String>,
    #[serde(default)]
    pub error: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct HashExistenceRequest {
    pub data_type: String,
    pub level: usize,
    pub position: i64,
    pub hash: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct HashExistenceResponse {
    pub exists: bool,
    pub level: usize,
    pub position: i64,
    pub data_type: String,
    #[serde(default)]
    pub found_hash: Option<String>,
    #[serde(default)]
    pub message: Option<String>,
    #[serde(default)]
    pub error: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct HashBatchRequest {
    pub data_type: String,
    pub level: usize,
    pub start: i64,
    pub hashes: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct HashBatchResponse {
    pub data_type: String,
    pub level: usize,
    pub start: i64,
    pub count: usize,
    #[serde(default)]
    pub results: Vec<i32>,
    pub matches: usize,
    pub mismatches: usize,
    #[serde(default)]
    pub error: Option<String>,
    #[serde(default)]
    pub message: Option<String>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct VerifyRequest {
    pub data_type: Option<String>,
    pub data_item: Option<String>,
    pub kayros_hash: Option<String>,
    pub api_key: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct VerifyLevelCheck {
    pub level: usize,
    pub position: i64,
    #[serde(default)]
    pub hash: Option<String>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct VerifyWithInclusionRequest {
    pub verify_request: VerifyRequest,
    pub trusted_root_hash: Option<String>,
    pub trusted_level: Option<usize>,
    pub trusted_position: Option<i64>,
    pub levels_hash_type: Option<String>,
    pub verify_batch_existence: bool,
    pub level_checks: Vec<VerifyLevelCheck>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct VerifyMerkleProofWithDetailsRequest {
    pub proof: MerkleProofInput,
    pub levels_hash_type: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct NormalizedKayrosRecord {
    pub data_type: String,
    pub data_type_hex: String,
    pub data_item: String,
    pub kayros_hash: String,
    #[serde(default)]
    pub prev_hash: Option<String>,
    pub hash_type: String,
    pub uuid: String,
    pub timestamp: String,
    pub position: i64,
    pub raw: GetRecordResponse,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct NormalizedMerkleProof {
    pub data_type: String,
    pub hash_item: String,
    pub proof: Vec<String>,
    pub root: String,
    pub position: i64,
    pub levels: usize,
    pub level_counts: Vec<usize>,
    pub level_starts: Vec<i64>,
    pub raw: MerkleProofResponse,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MerkleProofInput {
    Response(MerkleProofResponse),
    Normalized(NormalizedMerkleProof),
}

impl Default for MerkleProofInput {
    fn default() -> Self {
        Self::Response(MerkleProofResponse::default())
    }
}

impl From<MerkleProofResponse> for MerkleProofInput {
    fn from(value: MerkleProofResponse) -> Self {
        Self::Response(value)
    }
}

impl From<NormalizedMerkleProof> for MerkleProofInput {
    fn from(value: NormalizedMerkleProof) -> Self {
        Self::Normalized(value)
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct MerkleProofLevel {
    pub level: usize,
    pub start: i64,
    pub count: usize,
    pub hashes: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct MerkleProofCompatibilityMismatch {
    pub kind: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub level: Option<usize>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub position: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub previous_index: Option<usize>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_index: Option<usize>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub previous_position: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_position: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub previous_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_hash: Option<String>,
    pub message: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct MerkleProofCompatibilityResult {
    pub compatible: bool,
    pub checked_entries: usize,
    pub previous: NormalizedMerkleProof,
    pub next: NormalizedMerkleProof,
    pub previous_levels: Vec<MerkleProofLevel>,
    pub next_levels: Vec<MerkleProofLevel>,
    pub mismatches: Vec<MerkleProofCompatibilityMismatch>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct LevelCheckResult {
    pub level: usize,
    pub position: i64,
    pub hash: String,
    pub valid: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub exists: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub found_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct BatchExistenceCheckResult {
    pub level: usize,
    pub start: i64,
    pub hashes: Vec<String>,
    pub valid: bool,
    pub results: Vec<i32>,
    pub matches: usize,
    pub mismatches: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct VerifyResultDetails {
    pub lookup_mode: String,
    pub record_found: bool,
    pub ambiguous: Option<bool>,
    pub ambiguous_count: Option<usize>,
    pub data_type_match: Option<bool>,
    pub data_item_match: Option<bool>,
    pub kayros_hash_match: Option<bool>,
    pub record_hash_match: Option<bool>,
    pub chain_link_match: Option<bool>,
    pub uuid_timestamp_match: Option<bool>,
    pub proof_fetched: Option<bool>,
    pub proof_data_type_match: Option<bool>,
    pub proof_hash_item_match: Option<bool>,
    pub proof_path_match: Option<bool>,
    pub target_position_match: Option<bool>,
    pub trusted_root_match: Option<bool>,
    pub trusted_level_match: Option<bool>,
    pub batch_existence_match: Option<bool>,
    pub levels_hash_type: Option<String>,
    pub pending: Option<bool>,
    pub max_level: Option<usize>,
    pub max_level_position: Option<i64>,
    pub max_level_hash: Option<String>,
    pub computed_record_hash: Option<String>,
    pub local_root_hash: Option<String>,
    pub record: Option<NormalizedKayrosRecord>,
    pub previous_record: Option<NormalizedKayrosRecord>,
    pub proof: Option<NormalizedMerkleProof>,
    pub level_checks: Option<Vec<LevelCheckResult>>,
    pub batch_checks: Option<Vec<BatchExistenceCheckResult>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct VerifyResult {
    pub valid: bool,
    #[serde(default)]
    pub error: Option<String>,
    #[serde(default)]
    pub details: Option<VerifyResultDetails>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct VerifyMerkleProofWithDetailsResult {
    pub valid: bool,
    pub pending: bool,
    pub status: String,
    pub message: String,
    #[serde(default)]
    pub error: Option<String>,
    #[serde(default)]
    pub details: Vec<String>,
    #[serde(default)]
    pub position_path: Vec<i64>,
    pub levels_hash_type: String,
    #[serde(default)]
    pub computed_root: Option<String>,
    pub max_level: i64,
    pub max_level_position: i64,
    pub max_level_hash: String,
    #[serde(default)]
    pub proof: Option<NormalizedMerkleProof>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct DatabaseQuery {
    #[serde(default)]
    pub data_type: Option<String>,
    #[serde(default)]
    pub hash_type: Option<String>,
    #[serde(default)]
    pub min_timestamp: Option<String>,
    #[serde(default)]
    pub max_timestamp: Option<String>,
    pub limit: usize,
    pub offset: usize,
    pub order_by: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct HashRecord {
    pub timestamp: String,
    pub data_type: String,
    pub data_item: String,
    pub hash_type: String,
    pub hash_item: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct DatabaseStats {
    pub total_hashes: i64,
    #[serde(default)]
    pub count_by_type: HashMap<String, i64>,
    pub min_timestamp: String,
    pub max_timestamp: String,
    pub timestamp_range: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct ColumnInfo {
    pub name: String,
    pub r#type: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct TableBrowseRequest {
    pub table_name: String,
    pub offset: usize,
    pub limit: usize,
    #[serde(default)]
    pub order_by: Option<String>,
    #[serde(default)]
    pub search_term: Option<String>,
    #[serde(default)]
    pub search_column: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct DatabaseRecord {
    pub data_type: String,
    pub data_item_hex: String,
    pub uuid_hex: String,
    pub hash_item_hex: String,
    #[serde(default)]
    pub prev_hash_hex: Option<String>,
    pub hash_type: String,
    pub timestamp: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct HashVerifyRequest {
    pub prev_hash: String,
    pub data_type: String,
    pub data_item: String,
    pub uuid: String,
    pub hash_type: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct HashVerifyResult {
    pub computed_hash: String,
    pub hash_input_hex: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct SingleHashRequest {
    pub data_type: String,
    pub data_item: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct SingleHashResponse {
    pub success: bool,
    pub message: String,
    pub data_type: String,
    pub data_item: String,
    pub computed_hash_hex: String,
    pub timeuuid_hex: String,
    pub data_type_hex: String,
    pub data_item_hex: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct ApiResponse<T> {
    pub success: bool,
    #[serde(default)]
    pub message: Option<String>,
    #[serde(default)]
    pub data: Option<T>,
    #[serde(default)]
    pub error: Option<String>,
}