iop_sdk_wasm/morpheus/
public.rs

1use super::*;
2
3/// Public keys of the Morpheus subtree in a vault.
4///
5/// @see MorpheusPlugin.priv
6#[wasm_bindgen(js_name = MorpheusPublic)]
7pub struct JsMorpheusPublic {
8    inner: MorpheusPublic,
9}
10
11#[wasm_bindgen(js_class = MorpheusPublic)]
12impl JsMorpheusPublic {
13    /// There can be several usages of DIDs differentiated inside the vault invisible externally, e.g. on a blockchain.
14    /// Each represents a separate subtree under the Morpheus subtree in the vault.
15    ///
16    /// Use 'persona', 'device', 'group' or 'resource' in singular as a parameter.
17    pub fn kind(&self, did_kind: &str) -> Result<JsMorpheusPublicKind, JsValue> {
18        let did_kind: DidKind = did_kind.parse().map_err_to_js()?;
19        self.kind_impl(did_kind)
20    }
21
22    /// Alias for {@link kind('persona')}
23    #[wasm_bindgen(getter)]
24    pub fn personas(&self) -> Result<JsMorpheusPublicKind, JsValue> {
25        self.kind_impl(DidKind::Persona)
26    }
27
28    /// Alias for {@link kind('device')}
29    #[wasm_bindgen(getter)]
30    pub fn devices(&self) -> Result<JsMorpheusPublicKind, JsValue> {
31        self.kind_impl(DidKind::Device)
32    }
33
34    /// Alias for {@link kind('group')}
35    #[wasm_bindgen(getter)]
36    pub fn groups(&self) -> Result<JsMorpheusPublicKind, JsValue> {
37        self.kind_impl(DidKind::Group)
38    }
39
40    /// Alias for {@link kind('resource')}
41    #[wasm_bindgen(getter)]
42    pub fn resources(&self) -> Result<JsMorpheusPublicKind, JsValue> {
43        self.kind_impl(DidKind::Resource)
44    }
45
46    /// Finds the multicipher {@link PublicKey} that belongs to the given multicipher {@link KeyId}.
47    ///
48    /// An error will be thrown if the key identifier has never been used yet in this vault.
49    #[wasm_bindgen(js_name = keyById)]
50    pub fn key_by_id(&self, id: &JsMKeyId) -> Result<JsMPublicKey, JsValue> {
51        let inner = self.inner.key_by_id(id.inner()).map_err_to_js()?;
52        Ok(JsMPublicKey::from(inner))
53    }
54
55    fn kind_impl(&self, did_kind: DidKind) -> Result<JsMorpheusPublicKind, JsValue> {
56        let inner = self.inner.kind(did_kind).map_err_to_js()?;
57        Ok(JsMorpheusPublicKind::from(inner))
58    }
59}
60
61impl From<MorpheusPublic> for JsMorpheusPublic {
62    fn from(inner: MorpheusPublic) -> Self {
63        Self { inner }
64    }
65}
66
67impl Wraps<MorpheusPublic> for JsMorpheusPublic {
68    fn inner(&self) -> &MorpheusPublic {
69        &self.inner
70    }
71}