This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InMemoryKeyManager, JSON stringify web5 parts over wasm ffi, remo…
…ve generate-mappings project (#135)
- Loading branch information
1 parent
15d44c4
commit 51cb75f
Showing
43 changed files
with
213 additions
and
1,489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,10 @@ | ||
use std::collections::HashMap; | ||
use crate::errors::{map_err, map_web5_err, Result}; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::JsValue; | ||
use web5::dids::did::Did; | ||
|
||
#[wasm_bindgen] | ||
pub struct WasmDid { | ||
inner: Did, | ||
} | ||
|
||
impl From<WasmDid> for Did { | ||
fn from(value: WasmDid) -> Self { | ||
value.inner | ||
} | ||
} | ||
|
||
impl From<Did> for WasmDid { | ||
fn from(value: Did) -> Self { | ||
WasmDid { inner: value } | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl WasmDid { | ||
#[allow(clippy::too_many_arguments)] | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
uri: String, | ||
url: String, | ||
method: String, | ||
id: String, | ||
params: JsValue, | ||
path: Option<String>, | ||
query: Option<String>, | ||
fragment: Option<String>, | ||
) -> Self { | ||
let params = if params.is_undefined() { | ||
None | ||
} else { | ||
serde_wasm_bindgen::from_value(params).unwrap_or(Some(HashMap::new())) | ||
}; | ||
|
||
Self { | ||
inner: Did { | ||
uri, | ||
url, | ||
method, | ||
id, | ||
params, | ||
path, | ||
query, | ||
fragment, | ||
}, | ||
} | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn uri(&self) -> String { | ||
self.inner.uri.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn url(&self) -> String { | ||
self.inner.url.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn method(&self) -> String { | ||
self.inner.method.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn id(&self) -> String { | ||
self.inner.id.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn params(&self) -> JsValue { | ||
match &self.inner.params { | ||
Some(map) => serde_wasm_bindgen::to_value(map).unwrap_or(JsValue::UNDEFINED), | ||
None => JsValue::UNDEFINED, | ||
} | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn path(&self) -> Option<String> { | ||
self.inner.path.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn query(&self) -> Option<String> { | ||
self.inner.query.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn fragment(&self) -> Option<String> { | ||
self.inner.fragment.clone() | ||
} | ||
pub fn parse_did(uri: &str) -> Result<String> { | ||
let did = Did::parse(uri).map_err(map_web5_err)?; | ||
let did_json = serde_json::to_string(&did).map_err(|e| map_err(e.into()))?; | ||
Ok(did_json) | ||
} |
Oops, something went wrong.