generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
005bd3c
commit c1a8a4e
Showing
18 changed files
with
868 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::errors::{map_err, Result}; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use web5::dids::bearer_did::BearerDid; | ||
use crate::crypto::dsa::WasmSigner; | ||
use crate::crypto::key_managers::WasmKeyManager; | ||
use crate::dids::did::WasmDid; | ||
use crate::dids::document::WasmDocument; | ||
use crate::dids::portable_did::WasmPortableDid; | ||
|
||
#[wasm_bindgen] | ||
pub struct WasmBearerDid { | ||
inner: BearerDid, | ||
} | ||
|
||
impl From<WasmBearerDid> for BearerDid { | ||
fn from(value: WasmBearerDid) -> Self { | ||
value.inner | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl WasmBearerDid { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(did: WasmDid, document: WasmDocument, key_manager: WasmKeyManager) -> Self { | ||
Self { | ||
inner: BearerDid { | ||
did: did.into(), | ||
document: document.into(), | ||
key_manager: key_manager.into(), | ||
}, | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn from_portable_did(portable_did: WasmPortableDid) -> Result<WasmBearerDid> { | ||
Ok(Self { | ||
inner: BearerDid::from_portable_did(portable_did.into()).map_err(map_err)?, | ||
}) | ||
} | ||
|
||
// todo key exporter for to_portable_did | ||
|
||
#[wasm_bindgen] | ||
pub fn get_signer(&self, verification_method_id: &str) -> Result<WasmSigner> { | ||
Ok(self | ||
.inner | ||
.get_signer(verification_method_id) | ||
.map_err(map_err)? | ||
.into()) | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn did(&self) -> WasmDid { | ||
self.inner.did.clone().into() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn document(&self) -> WasmDocument { | ||
self.inner.document.clone().into() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn key_manager(&self) -> WasmKeyManager { | ||
self.inner.key_manager.clone().into() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use std::collections::HashMap; | ||
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() | ||
} | ||
} |
Oops, something went wrong.