iop_keyvault_wasm/
morpheus.rs1use super::*;
2
3#[wasm_bindgen(js_name = Morpheus)]
7#[derive(Clone, Debug)]
8pub struct JsMorpheus;
9
10#[wasm_bindgen(js_class = Morpheus)]
11impl JsMorpheus {
12 pub fn root(seed: &JsSeed) -> Result<JsMorpheusRoot, JsValue> {
14 let inner = Morpheus.root(seed.inner()).map_err_to_js()?;
15 Ok(JsMorpheusRoot::from(inner))
16 }
17}
18
19#[wasm_bindgen(js_name = MorpheusRoot)]
21#[derive(Clone, Debug)]
22pub struct JsMorpheusRoot {
23 inner: MorpheusRoot,
24}
25
26#[wasm_bindgen(js_class = MorpheusRoot)]
27impl JsMorpheusRoot {
28 #[wasm_bindgen(getter = path)]
30 pub fn bip32_path(&self) -> String {
31 self.inner.node().path().to_string()
32 }
33
34 pub fn kind(&self, did_kind: &str) -> Result<JsMorpheusKind, JsValue> {
37 let did_kind = did_kind.parse().map_err_to_js()?;
38 self.kind_impl(did_kind)
39 }
40
41 pub fn personas(&self) -> Result<JsMorpheusKind, JsValue> {
43 self.kind_impl(DidKind::Persona)
44 }
45
46 pub fn devices(&self) -> Result<JsMorpheusKind, JsValue> {
48 self.kind_impl(DidKind::Device)
49 }
50
51 pub fn groups(&self) -> Result<JsMorpheusKind, JsValue> {
53 self.kind_impl(DidKind::Group)
54 }
55
56 pub fn resources(&self) -> Result<JsMorpheusKind, JsValue> {
58 self.kind_impl(DidKind::Resource)
59 }
60
61 fn kind_impl(&self, did_kind: DidKind) -> Result<JsMorpheusKind, JsValue> {
62 let inner = self.inner.kind(did_kind).map_err_to_js()?;
63 Ok(JsMorpheusKind::from(inner))
64 }
65}
66
67impl From<MorpheusRoot> for JsMorpheusRoot {
68 fn from(inner: MorpheusRoot) -> Self {
69 Self { inner }
70 }
71}
72
73impl Wraps<MorpheusRoot> for JsMorpheusRoot {
74 fn inner(&self) -> &MorpheusRoot {
75 &self.inner
76 }
77}
78
79#[wasm_bindgen(js_name = MorpheusKind)]
81#[derive(Clone, Debug)]
82pub struct JsMorpheusKind {
83 inner: MorpheusKind,
84}
85
86#[wasm_bindgen(js_class = MorpheusKind)]
87impl JsMorpheusKind {
88 #[wasm_bindgen(getter = path)]
90 pub fn bip32_path(&self) -> String {
91 self.inner.node().path().to_string()
92 }
93
94 #[wasm_bindgen(getter)]
96 pub fn kind(&self) -> String {
97 format!("{:?}", self.inner.path())
98 }
99
100 pub fn key(&self, idx: i32) -> Result<JsMorpheusPrivateKey, JsValue> {
103 let inner = self.inner.key(idx).map_err_to_js()?;
104 Ok(JsMorpheusPrivateKey::from(inner))
105 }
106}
107
108impl From<MorpheusKind> for JsMorpheusKind {
109 fn from(inner: MorpheusKind) -> Self {
110 Self { inner }
111 }
112}
113
114impl Wraps<MorpheusKind> for JsMorpheusKind {
115 fn inner(&self) -> &MorpheusKind {
116 &self.inner
117 }
118}
119
120#[wasm_bindgen(js_name = MorpheusPrivateKey)]
122#[derive(Clone, Debug)]
123pub struct JsMorpheusPrivateKey {
124 inner: MorpheusPrivateKey,
125}
126
127#[wasm_bindgen(js_class = MorpheusPrivateKey)]
128impl JsMorpheusPrivateKey {
129 #[wasm_bindgen(getter = path)]
131 pub fn bip32_path(&self) -> String {
132 self.inner.node().path().to_string()
133 }
134
135 #[wasm_bindgen(getter)]
137 pub fn kind(&self) -> String {
138 format!("{:?}", self.inner.path().kind())
139 }
140
141 #[wasm_bindgen(getter)]
143 pub fn idx(&self) -> i32 {
144 self.inner().path().idx()
145 }
146
147 pub fn neuter(&self) -> JsMorpheusPublicKey {
149 let inner = self.inner.neuter();
150 JsMorpheusPublicKey::from(inner)
151 }
152
153 #[wasm_bindgen(js_name = privateKey)]
155 pub fn private_key(&self) -> JsMPrivateKey {
156 let inner = self.inner.private_key();
157 JsMPrivateKey::from(inner)
158 }
159}
160
161impl From<MorpheusPrivateKey> for JsMorpheusPrivateKey {
162 fn from(inner: MorpheusPrivateKey) -> Self {
163 Self { inner }
164 }
165}
166
167impl Wraps<MorpheusPrivateKey> for JsMorpheusPrivateKey {
168 fn inner(&self) -> &MorpheusPrivateKey {
169 &self.inner
170 }
171}
172
173#[wasm_bindgen(js_name = MorpheusPublicKey)]
175#[derive(Clone, Debug)]
176pub struct JsMorpheusPublicKey {
177 inner: MorpheusPublicKey,
178}
179
180#[wasm_bindgen(js_class = MorpheusPublicKey)]
181impl JsMorpheusPublicKey {
182 #[wasm_bindgen(getter = path)]
184 pub fn bip32_path(&self) -> String {
185 self.inner.node().path().to_string()
186 }
187
188 #[wasm_bindgen(getter)]
190 pub fn kind(&self) -> String {
191 format!("{:?}", self.inner.path().kind())
192 }
193
194 #[wasm_bindgen(getter)]
196 pub fn idx(&self) -> i32 {
197 self.inner().path().idx()
198 }
199
200 #[wasm_bindgen(js_name = publicKey)]
202 pub fn public_key(&self) -> JsMPublicKey {
203 let inner = self.inner.public_key();
204 JsMPublicKey::from(inner)
205 }
206}
207
208impl From<MorpheusPublicKey> for JsMorpheusPublicKey {
209 fn from(inner: MorpheusPublicKey) -> Self {
210 Self { inner }
211 }
212}
213
214impl Wraps<MorpheusPublicKey> for JsMorpheusPublicKey {
215 fn inner(&self) -> &MorpheusPublicKey {
216 &self.inner
217 }
218}