iop_sdk_wasm/morpheus/
plugin.rs

1use super::*;
2
3/// Represents the Morpheus subtree in a given vault.
4#[wasm_bindgen(js_name = MorpheusPlugin)]
5pub struct JsMorpheusPlugin {
6    inner: MorpheusBoundPlugin,
7}
8
9#[wasm_bindgen(js_class = MorpheusPlugin)]
10impl JsMorpheusPlugin {
11    /// Creates the Morpheus subtree in the vault. If the subtree already exists, an error will be
12    /// thrown. An existing subtree has to be retrieved from the vault using {@link get}.
13    pub fn init(vault: &mut JsVault, unlock_password: &str) -> Result<(), JsValue> {
14        hd_morpheus::Plugin::init(vault.inner_mut(), unlock_password).map_err_to_js()?;
15        Ok(())
16    }
17
18    /// Retrieves an existing Morpheus subtree from the vault. If the subtree is missing, an error will be thrown. A new subtree can be
19    /// created with {@link init}.
20    pub fn get(vault: &JsVault) -> Result<JsMorpheusPlugin, JsValue> {
21        let inner = hd_morpheus::Plugin::get(vault.inner()).map_err_to_js()?;
22        Ok(Self { inner })
23    }
24
25    /// Accessor for the public keys in the Morpheus subtree.
26    #[wasm_bindgen(getter = pub)]
27    pub fn public(&self) -> Result<JsMorpheusPublic, JsValue> {
28        let inner = self.inner.public().map_err_to_js()?;
29        Ok(JsMorpheusPublic::from(inner))
30    }
31
32    /// Accessor for the private keys in the Morpheus subtree. Needs the unlock password.
33    ///
34    /// @see Vault.unlock
35    #[wasm_bindgen(js_name = priv)]
36    pub fn private(&self, unlock_password: &str) -> Result<JsMorpheusPrivate, JsValue> {
37        let inner = self.inner.private(unlock_password).map_err_to_js()?;
38        Ok(JsMorpheusPrivate::from(inner))
39    }
40}
41
42impl From<MorpheusBoundPlugin> for JsMorpheusPlugin {
43    fn from(inner: MorpheusBoundPlugin) -> Self {
44        Self { inner }
45    }
46}
47
48impl Wraps<MorpheusBoundPlugin> for JsMorpheusPlugin {
49    fn inner(&self) -> &MorpheusBoundPlugin {
50        &self.inner
51    }
52}