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
//! ProverResult

use crate::ast::Constant;
use ergo_lib::sigma_protocol;
use wasm_bindgen::prelude::*;

extern crate derive_more;
use derive_more::{From, Into};

/// Proof of correctness of tx spending
#[wasm_bindgen]
#[derive(PartialEq, Debug, Clone, From, Into)]
pub struct ContextExtension(sigma_protocol::prover::ContextExtension);

#[wasm_bindgen]
impl ContextExtension {
    /// Returns the number of elements in the collection
    pub fn len(&self) -> usize {
        self.0.values.len()
    }
    /// get from map or fail if key is missing
    pub fn get(&self, key: u8) -> Constant {
        self.0.values.get(&key).unwrap().clone().into()
    }

    /// Returns all keys in the map
    pub fn keys(&self) -> Vec<u8> {
        self.0.values.keys().cloned().collect()
    }
}