txtx-addon-kit 0.4.14

Low level primitives for building addons for Txtx
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
use std::collections::HashMap;

use indexmap::IndexMap;

use crate::{
    constants::{MARKDOWN, MARKDOWN_FILEPATH, THIRD_PARTY_SIGNATURE_STATUS},
    types::{types::ThirdPartySignatureStatus, AuthorizationContext},
};

use super::{
    commands::CommandInput, diagnostics::Diagnostic, types::Value, ConstructDid, Did, CACHED_NONCE,
};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValueStore {
    pub uuid: Did,
    pub name: String,
    pub inputs: ValueMap,
    pub defaults: ValueMap,
}

impl ValueStore {
    pub fn new(name: &str, uuid: &Did) -> ValueStore {
        ValueStore {
            name: name.to_string(),
            uuid: uuid.clone(),
            inputs: ValueMap::new(),
            defaults: ValueMap::new(),
        }
    }
    pub fn tmp() -> ValueStore {
        ValueStore {
            name: "".to_string(),
            uuid: Did::zero(),
            inputs: ValueMap::new(),
            defaults: ValueMap::new(),
        }
    }
    pub fn with_inputs(mut self, inputs: &ValueMap) -> Self {
        self.inputs = inputs.clone();
        self
    }

    pub fn append_inputs(mut self, new_inputs: &ValueMap) -> Self {
        self.inputs = self.inputs.append_store(&new_inputs.store);
        self
    }

    pub fn with_defaults(mut self, defaults: &ValueMap) -> Self {
        self.defaults = defaults.clone();
        self
    }
    pub fn with_inputs_from_map(mut self, inputs: &HashMap<String, Value>) -> Self {
        for (key, value) in inputs.iter() {
            self.inputs.insert(key, value.clone());
        }
        self
    }
    pub fn with_inputs_from_vec(mut self, inputs: &Vec<(String, Value)>) -> Self {
        for (k, v) in inputs.iter() {
            self.inputs.insert(k, v.clone());
        }
        self
    }

    pub fn check(
        self,
        instance_name: &str,
        spec_inputs: &Vec<CommandInput>,
    ) -> Result<Self, Diagnostic> {
        for input in spec_inputs.iter() {
            match input.optional {
                true => continue,
                false => match self.inputs.get_value(&input.name) {
                    // Uncomment for strict type-checking on all values:
                    // Some(value) => match input.check_value(value) {
                    //     Ok(_) => continue,
                    //     Err(e) => return Err(e),
                    // },
                    Some(value) => match input.as_object() {
                        Some(_) => match input.check_value(value) {
                            Ok(_) => continue,
                            Err(e) => return Err(e),
                        },
                        None => continue,
                    },
                    None => match self.defaults.get_value(&input.name) {
                        // Uncomment for strict type-checking on all values:
                        // Some(value) => match input.check_value(value) {
                        //     Ok(_) => continue,
                        //     Err(e) => return Err(e),
                        // },
                        Some(value) => match input.as_object() {
                            Some(_) => match input.check_value(value) {
                                Ok(_) => continue,
                                Err(e) => return Err(e),
                            },
                            None => continue,
                        },
                        None => {
                            return Err(Diagnostic::error_from_string(format!(
                                "Could not execute command '{}': Required input '{}' missing",
                                instance_name, input.name
                            )));
                        }
                    },
                },
            };
        }
        Ok(self)
    }

    // Expected values: if both inputs/defaults yield an error, we should return the input's Diagnostic
    pub fn get_expected_value(&self, key: &str) -> Result<&Value, Diagnostic> {
        match self.inputs.get_expected_value(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_value(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_construct_did(&self, key: &str) -> Result<ConstructDid, Diagnostic> {
        match self.inputs.get_expected_construct_did(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_construct_did(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_string(&self, key: &str) -> Result<&str, Diagnostic> {
        match self.inputs.get_expected_string(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_string(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_integer(&self, key: &str) -> Result<i128, Diagnostic> {
        match self.inputs.get_expected_integer(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_integer(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_uint(&self, key: &str) -> Result<u64, Diagnostic> {
        match self.inputs.get_expected_uint(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_uint(key).or(Err(e)),
        }
        .map_err(|e| e)
    }
    pub fn get_expected_bool(&self, key: &str) -> Result<bool, Diagnostic> {
        match self.inputs.get_expected_bool(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_bool(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_array(&self, key: &str) -> Result<&Vec<Value>, Diagnostic> {
        match self.inputs.get_expected_array(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_array(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_map(&self, key: &str) -> Result<&Vec<Value>, Diagnostic> {
        match self.inputs.get_expected_map(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_map(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_object(&self, key: &str) -> Result<IndexMap<String, Value>, Diagnostic> {
        match self.inputs.get_expected_object(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_object(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_buffer_bytes(&self, key: &str) -> Result<Vec<u8>, Diagnostic> {
        match self.inputs.get_expected_buffer_bytes(key) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_buffer_bytes(key).or(Err(e)),
        }
        .map_err(|e| e)
    }

    // Optional values
    pub fn get_string(&self, key: &str) -> Option<&str> {
        self.inputs.get_string(key).or(self.defaults.get_string(key))
    }

    pub fn get_value(&self, key: &str) -> Option<&Value> {
        self.inputs.get_value(key).or(self.defaults.get_value(key))
    }

    pub fn get_uint(&self, key: &str) -> Result<Option<u64>, String> {
        self.inputs
            .get_uint(key)
            .map_or_else(|_| self.defaults.get_uint(key).map_err(|e| e), |val| Ok(val))
    }

    pub fn get_u8(&self, key: &str) -> Result<Option<u8>, String> {
        self.inputs
            .get_integer(key)
            .or(self.defaults.get_integer(key))
            .map(|v| {
                u8::try_from(v).map_err(|e| format!("invalid u8 for value '{key}': {e}").into())
            })
            .transpose()
    }

    pub fn get_bool(&self, key: &str) -> Option<bool> {
        self.inputs.get_bool(key).or(self.defaults.get_bool(key))
    }

    pub fn get_third_party_signature_status(&self) -> Option<ThirdPartySignatureStatus> {
        self.inputs
            .get_third_party_signature_status()
            .or(self.defaults.get_third_party_signature_status())
    }

    pub fn get_integer(&self, key: &str) -> Option<i128> {
        self.inputs.get_integer(key).or(self.defaults.get_integer(key))
    }

    pub fn get_i64(&self, key: &str) -> Result<Option<i64>, Diagnostic> {
        self.inputs
            .get_integer(key)
            .or(self.defaults.get_integer(key))
            .map(|v| {
                i64::try_from(v).map_err(|e| format!("invalid i64 for value '{key}': {e}").into())
            })
            .transpose()
    }

    pub fn get_array(&self, key: &str) -> Option<&Box<Vec<Value>>> {
        self.inputs.get_array(key).or(self.defaults.get_array(key))
    }

    pub fn get_map(&self, key: &str) -> Option<&Box<Vec<Value>>> {
        self.inputs.get_map(key).or(self.defaults.get_map(key))
    }

    pub fn get_object(&self, key: &str) -> Option<&IndexMap<String, Value>> {
        self.inputs.get_object(key).or(self.defaults.get_object(key))
    }

    // Scoped values
    pub fn insert_scoped_value(&mut self, scope: &str, key: &str, value: Value) {
        self.inputs.insert(&format!("{}:{}", scope, key), value);
    }

    pub fn clear_scoped_value(&mut self, scope: &str, key: &str) {
        self.inputs.store.swap_remove(&format!("{}:{}", scope, key));
    }

    pub fn remove_scoped_value(&mut self, scope: &str, key: &str) -> Option<Value> {
        self.inputs.store.shift_remove(&format!("{}:{}", scope, key))
    }

    pub fn get_scoped_value(&self, scope: &str, key: &str) -> Option<&Value> {
        self.inputs.get_value(&format!("{}:{}", scope, key))
    }

    pub fn get_scoped_integer(&self, scope: &str, key: &str) -> Option<i128> {
        self.inputs.get_integer(&format!("{}:{}", scope, key))
    }

    pub fn get_scoped_bool(&self, scope: &str, key: &str) -> Option<bool> {
        if let Some(Value::Bool(bool)) = self.get_scoped_value(scope, key) {
            Some(*bool)
        } else {
            None
        }
    }

    pub fn get_expected_scoped_value(&self, scope: &str, key: &str) -> Result<&Value, Diagnostic> {
        match self.inputs.get_expected_value(&format!("{}:{}", scope, key)) {
            Ok(val) => Ok(val),
            Err(e) => self.defaults.get_expected_value(&format!("{}:{}", scope, key)).or(Err(e)),
        }
        .map_err(|e| e)
    }

    pub fn get_expected_scoped_buffer_bytes(
        &self,
        scope: &str,
        key: &str,
    ) -> Result<Vec<u8>, Diagnostic> {
        match self.inputs.get_expected_buffer_bytes(&format!("{}:{}", scope, key)) {
            Ok(val) => Ok(val),
            Err(e) => {
                self.defaults.get_expected_buffer_bytes(&format!("{}:{}", scope, key)).or(Err(e))
            }
        }
        .map_err(|e| e)
    }

    // Nonce helpers
    pub fn clear_autoincrementable_nonce(&mut self) {
        self.inputs.clear_autoincrementable_nonce();
    }

    pub fn set_autoincrementable_nonce(&mut self, key: &str, initial_value: u64) {
        self.inputs.set_autoincrementable_nonce(key, initial_value);
    }

    pub fn get_autoincremented_nonce(&mut self, key: &str) -> Option<i128> {
        self.inputs.get_autoincremented_nonce(key)
    }

    // General helpers
    pub fn insert(&mut self, key: &str, value: Value) {
        self.inputs.insert(key, value);
    }

    pub fn iter(&self) -> indexmap::map::Iter<String, Value> {
        self.inputs.iter()
    }

    pub fn len(&self) -> usize {
        self.inputs.len()
    }
    pub fn get_mut(&mut self, key: &str) -> Option<&mut Value> {
        self.inputs.get_mut(key)
    }

    pub fn append_no_override(&mut self, other: &ValueStore) {
        for (key, value) in &other.inputs.store {
            if self.inputs.get_value(&key).is_none() {
                self.inputs.insert(&key, value.clone());
            }
        }
    }

    // Other
    pub fn get_markdown(
        &self,
        auth_context: &AuthorizationContext,
    ) -> Result<Option<String>, Diagnostic> {
        let markdown = self
            .inputs
            .get_value(MARKDOWN)
            .and_then(|v| v.as_string().map(|s| s.to_string()))
            .or_else(|| {
                self.defaults.get_value(MARKDOWN).and_then(|v| v.as_string().map(|s| s.to_string()))
            });

        if markdown.is_some() {
            return Ok(markdown);
        }

        let Some(markdown_filepath) = self
            .inputs
            .get_string(MARKDOWN_FILEPATH)
            .or_else(|| self.defaults.get_string(MARKDOWN_FILEPATH))
        else {
            return Ok(None);
        };

        let markdown_content_path_buf = std::path::PathBuf::from(markdown_filepath);
        let markdown_content = auth_context
            .get_file_location_from_path_buf(&markdown_content_path_buf)
            .map_err(|e| {
                Diagnostic::error_from_string(format!(
                    "Failed to get file location for markdown file: {}",
                    e
                ))
            })?
            .read_content_as_utf8()
            .map_err(|e| {
                Diagnostic::error_from_string(format!(
                    "Failed to read markdown file content: {}",
                    e
                ))
            })?;

        Ok(Some(markdown_content))
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddonDefaults {
    pub uuid: Did,
    pub name: String,
    pub store: ValueMap,
}

impl AddonDefaults {
    pub fn new(key: &str) -> AddonDefaults {
        AddonDefaults { store: ValueMap::new(), name: key.to_string(), uuid: Did::zero() }
    }
    pub fn insert(&mut self, key: &str, value: Value) {
        self.store.insert(key, value);
    }
    pub fn iter(&self) -> indexmap::map::Iter<String, Value> {
        self.store.iter()
    }
    pub fn contains_key(&self, key: &str) -> bool {
        self.store.contains_key(key)
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValueMap {
    pub store: IndexMap<String, Value>,
}
impl ValueMap {
    pub fn new() -> ValueMap {
        Self { store: IndexMap::new() }
    }
    pub fn with_store(mut self, store: &IndexMap<String, Value>) -> Self {
        self.store = store.clone();
        self
    }
    pub fn append_store(mut self, new_store: &IndexMap<String, Value>) -> Self {
        for (k, v) in new_store.into_iter() {
            if !self.store.contains_key(k) {
                self.store.insert(k.to_string(), v.clone());
            }
        }
        self
    }

    pub fn get_expected_value(&self, key: &str) -> Result<&Value, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve value '{}'",
                key
            )));
        };
        Ok(value)
    }

    pub fn get_expected_bool(&self, key: &str) -> Result<bool, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve bool '{}'",
                key,
            )));
        };
        let Some(value) = value.as_bool() else {
            return Err(Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected bool",
                key
            )));
        };
        Ok(value)
    }

    pub fn get_expected_construct_did(&self, key: &str) -> Result<ConstructDid, Diagnostic> {
        let value = self.get_expected_string(key)?;
        let construct_did = ConstructDid::from_hex_string(value);
        Ok(construct_did)
    }

    pub fn get_expected_string(&self, key: &str) -> Result<&str, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve string '{}'",
                key,
            )));
        };
        let Some(value) = value.as_string() else {
            return Err(Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected string",
                key
            )));
        };
        Ok(value)
    }

    pub fn get_expected_array(&self, key: &str) -> Result<&Vec<Value>, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve array '{}'",
                key,
            )));
        };
        let Some(value) = value.as_array() else {
            return Err(Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected array",
                key
            )));
        };
        Ok(value)
    }

    pub fn get_expected_map(&self, key: &str) -> Result<&Vec<Value>, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(
                format!("unable to retrieve map '{}'", key,),
            ));
        };
        let Some(value) = value.as_array() else {
            return Err(Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected map",
                key
            )));
        };
        Ok(value)
    }

    pub fn get_expected_object(&self, key: &str) -> Result<IndexMap<String, Value>, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve object '{}'",
                key,
            )));
        };
        let Some(result) = value.as_object() else {
            return Err(Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected object",
                key
            )));
        };
        Ok(result.clone())
    }

    pub fn get_expected_integer(&self, key: &str) -> Result<i128, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve integer '{}'",
                key,
            )));
        };
        let Some(value) = value.as_integer() else {
            return Err(Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected integer",
                key
            )));
        };
        Ok(value)
    }

    pub fn get_expected_uint(&self, key: &str) -> Result<u64, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve uint '{}'",
                key,
            )));
        };
        let Some(value) = value.as_uint() else {
            return Err(Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected positive integer",
                key
            )));
        };
        value.map_err(|e| {
            Diagnostic::error_from_string(format!(
                "value associated with '{}' type mismatch: expected positive integer: {}",
                key, e,
            ))
        })
    }

    pub fn get_expected_buffer_bytes(&self, key: &str) -> Result<Vec<u8>, Diagnostic> {
        let Some(value) = self.store.get(key) else {
            return Err(Diagnostic::error_from_string(format!(
                "unable to retrieve buffer '{}'",
                key,
            )));
        };

        let bytes = match value {
            Value::Buffer(bytes) => bytes.clone(),
            Value::String(bytes) => {
                let bytes = if bytes.starts_with("0x") {
                    crate::hex::decode(&bytes[2..]).unwrap()
                } else {
                    crate::hex::decode(&bytes).unwrap()
                };
                bytes
            }
            Value::Addon(data) => data.bytes.clone(),
            _ => {
                return Err(Diagnostic::error_from_string(format!(
                    "value associated with '{}' type mismatch: expected buffer",
                    key
                )))
            }
        };
        Ok(bytes)
    }

    pub fn get_scoped_value(&self, scope: &str, key: &str) -> Option<&Value> {
        self.store.get(&format!("{}:{}", scope, key))
    }

    pub fn get_scoped_bool(&self, scope: &str, key: &str) -> Option<bool> {
        if let Some(Value::Bool(bool)) = self.get_scoped_value(scope, key) {
            Some(*bool)
        } else {
            None
        }
    }

    pub fn clear_autoincrementable_nonce(&mut self) {
        self.store.swap_remove(&format!("{}:autoincrement", CACHED_NONCE));
    }

    pub fn set_autoincrementable_nonce(&mut self, key: &str, initial_value: u64) {
        self.store.insert(
            format!("{}:autoincrement", CACHED_NONCE),
            Value::integer((initial_value + 1).into()),
        );
        self.store
            .insert(format!("{}:{}", CACHED_NONCE, key), Value::integer(initial_value.into()));
    }

    pub fn get_autoincremented_nonce(&mut self, key: &str) -> Option<i128> {
        let value = match self.store.get(&format!("{}:{}", CACHED_NONCE, key)) {
            None => match self.store.get(&format!("{}:autoincrement", CACHED_NONCE)) {
                None => return None,
                Some(Value::Integer(value)) => {
                    let value_to_return = value.clone();
                    self.store.insert(
                        format!("{}:autoincrement", CACHED_NONCE),
                        Value::integer(value_to_return + 1),
                    );
                    self.store.insert(
                        format!("{}:{}", CACHED_NONCE, key),
                        Value::integer(value_to_return.clone()),
                    );
                    value_to_return
                }
                _ => unreachable!(),
            },
            Some(Value::Integer(value)) => *value,
            _ => unreachable!(),
        };
        Some(value)
    }

    pub fn get_value(&self, key: &str) -> Option<&Value> {
        self.store.get(key)
    }

    pub fn get_uint(&self, key: &str) -> Result<Option<u64>, String> {
        self.store.get(key).map(|v| v.expect_uint()).transpose()
    }

    pub fn get_integer(&self, key: &str) -> Option<i128> {
        self.store.get(key).and_then(|v| v.as_integer())
    }

    pub fn get_string(&self, key: &str) -> Option<&str> {
        self.store.get(key).and_then(|v| v.as_string())
    }

    pub fn get_bool(&self, key: &str) -> Option<bool> {
        self.store.get(key).and_then(|v| v.as_bool())
    }

    pub fn get_third_party_signature_status(&self) -> Option<ThirdPartySignatureStatus> {
        self.store
            .get(THIRD_PARTY_SIGNATURE_STATUS)
            .and_then(|v| v.as_third_party_signature_status())
    }

    pub fn get_array(&self, key: &str) -> Option<&Box<Vec<Value>>> {
        self.store.get(key).and_then(|v| v.as_array())
    }

    pub fn get_map(&self, key: &str) -> Option<&Box<Vec<Value>>> {
        self.store.get(key).and_then(|v| v.as_array())
    }

    pub fn get_object(&self, key: &str) -> Option<&IndexMap<String, Value>> {
        self.store.get(key).and_then(|v| v.as_object())
    }

    pub fn insert_scoped_value(&mut self, scope: &str, key: &str, value: Value) {
        self.store.insert(format!("{}:{}", scope, key), value);
    }
    pub fn insert(&mut self, key: &str, value: Value) {
        self.store.insert(key.to_string(), value);
    }

    pub fn iter(&self) -> indexmap::map::Iter<String, Value> {
        self.store.iter()
    }

    pub fn len(&self) -> usize {
        self.store.len()
    }
    pub fn get_mut(&mut self, key: &str) -> Option<&mut Value> {
        self.store.get_mut(key)
    }
    pub fn contains_key(&self, key: &str) -> bool {
        self.store.contains_key(key)
    }
}