-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pr/frederikrothenberger/1408
- Loading branch information
Showing
28 changed files
with
1,258 additions
and
138 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
109 changes: 109 additions & 0 deletions
109
bindings/wasm/src/credential/linked_verifiable_presentation_service.rs
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,109 @@ | ||
// Copyright 2020-2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::common::ArrayString; | ||
use crate::did::WasmService; | ||
use crate::error::Result; | ||
use crate::error::WasmResult; | ||
use identity_iota::core::Object; | ||
use identity_iota::core::OneOrSet; | ||
use identity_iota::core::Url; | ||
use identity_iota::credential::LinkedVerifiablePresentationService; | ||
use identity_iota::did::DIDUrl; | ||
use identity_iota::document::Service; | ||
use proc_typescript::typescript; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen::JsCast; | ||
|
||
#[wasm_bindgen(js_name = LinkedVerifiablePresentationService, inspectable)] | ||
pub struct WasmLinkedVerifiablePresentationService(LinkedVerifiablePresentationService); | ||
|
||
/// A service wrapper for a [Linked Verifiable Presentation Service Endpoint](https://identity.foundation/linked-vp/#linked-verifiable-presentation-service-endpoint). | ||
#[wasm_bindgen(js_class = LinkedVerifiablePresentationService)] | ||
impl WasmLinkedVerifiablePresentationService { | ||
/// Constructs a new {@link LinkedVerifiablePresentationService} that wraps a spec compliant [Linked Verifiable Presentation Service Endpoint](https://identity.foundation/linked-vp/#linked-verifiable-presentation-service-endpoint). | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(options: ILinkedVerifiablePresentationService) -> Result<WasmLinkedVerifiablePresentationService> { | ||
let ILinkedVerifiablePresentationServiceHelper { | ||
id, | ||
linked_vp, | ||
properties, | ||
} = options | ||
.into_serde::<ILinkedVerifiablePresentationServiceHelper>() | ||
.wasm_result()?; | ||
Ok(Self( | ||
LinkedVerifiablePresentationService::new(id, linked_vp, properties).wasm_result()?, | ||
)) | ||
} | ||
|
||
/// Returns the domains contained in the Linked Verifiable Presentation Service. | ||
#[wasm_bindgen(js_name = verifiablePresentationUrls)] | ||
pub fn vp_urls(&self) -> ArrayString { | ||
self | ||
.0 | ||
.verifiable_presentation_urls() | ||
.iter() | ||
.map(|url| url.to_string()) | ||
.map(JsValue::from) | ||
.collect::<js_sys::Array>() | ||
.unchecked_into::<ArrayString>() | ||
} | ||
|
||
/// Returns the inner service which can be added to a DID Document. | ||
#[wasm_bindgen(js_name = toService)] | ||
pub fn to_service(&self) -> WasmService { | ||
let service: Service = self.0.clone().into(); | ||
WasmService(service) | ||
} | ||
|
||
/// Creates a new {@link LinkedVerifiablePresentationService} from a {@link Service}. | ||
/// | ||
/// # Error | ||
/// | ||
/// Errors if `service` is not a valid Linked Verifiable Presentation Service. | ||
#[wasm_bindgen(js_name = fromService)] | ||
pub fn from_service(service: &WasmService) -> Result<WasmLinkedVerifiablePresentationService> { | ||
Ok(Self( | ||
LinkedVerifiablePresentationService::try_from(service.0.clone()).wasm_result()?, | ||
)) | ||
} | ||
|
||
/// Returns `true` if a {@link Service} is a valid Linked Verifiable Presentation Service. | ||
#[wasm_bindgen(js_name = isValid)] | ||
pub fn is_valid(service: &WasmService) -> bool { | ||
LinkedVerifiablePresentationService::check_structure(&service.0).is_ok() | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[wasm_bindgen(typescript_type = "ILinkedVerifiablePresentationService")] | ||
pub type ILinkedVerifiablePresentationService; | ||
} | ||
|
||
/// Fields for constructing a new {@link LinkedVerifiablePresentationService}. | ||
#[derive(Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
#[typescript(name = "ILinkedVerifiablePresentationService", readonly, optional)] | ||
struct ILinkedVerifiablePresentationServiceHelper { | ||
/// Service id. | ||
#[typescript(optional = false, type = "DIDUrl")] | ||
id: DIDUrl, | ||
/// A unique URI that may be used to identify the {@link Credential}. | ||
#[typescript(optional = false, type = "string | string[]")] | ||
linked_vp: OneOrSet<Url>, | ||
/// Miscellaneous properties. | ||
#[serde(flatten)] | ||
#[typescript(optional = false, name = "[properties: string]", type = "unknown")] | ||
properties: Object, | ||
} | ||
|
||
impl_wasm_clone!( | ||
WasmLinkedVerifiablePresentationService, | ||
LinkedVerifiablePresentationService | ||
); | ||
impl_wasm_json!( | ||
WasmLinkedVerifiablePresentationService, | ||
LinkedVerifiablePresentationService | ||
); |
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,105 @@ | ||
// Copyright 2020-2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use identity_iota::did::DIDJwk; | ||
use identity_iota::did::DID as _; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use super::wasm_core_did::get_core_did_clone; | ||
use super::IToCoreDID; | ||
use super::WasmCoreDID; | ||
use crate::error::Result; | ||
use crate::error::WasmResult; | ||
use crate::jose::WasmJwk; | ||
|
||
/// `did:jwk` DID. | ||
#[wasm_bindgen(js_name = DIDJwk)] | ||
pub struct WasmDIDJwk(pub(crate) DIDJwk); | ||
|
||
#[wasm_bindgen(js_class = DIDJwk)] | ||
impl WasmDIDJwk { | ||
#[wasm_bindgen(constructor)] | ||
/// Creates a new {@link DIDJwk} from a {@link CoreDID}. | ||
/// | ||
/// ### Errors | ||
/// Throws an error if the given did is not a valid `did:jwk` DID. | ||
pub fn new(did: IToCoreDID) -> Result<WasmDIDJwk> { | ||
let did = get_core_did_clone(&did).0; | ||
DIDJwk::try_from(did).wasm_result().map(Self) | ||
} | ||
/// Parses a {@link DIDJwk} from the given `input`. | ||
/// | ||
/// ### Errors | ||
/// | ||
/// Throws an error if the input is not a valid {@link DIDJwk}. | ||
#[wasm_bindgen] | ||
pub fn parse(input: &str) -> Result<WasmDIDJwk> { | ||
DIDJwk::parse(input).wasm_result().map(Self) | ||
} | ||
|
||
/// Returns the JSON WEB KEY (JWK) encoded inside this `did:jwk`. | ||
#[wasm_bindgen] | ||
pub fn jwk(&self) -> WasmJwk { | ||
self.0.jwk().into() | ||
} | ||
|
||
// =========================================================================== | ||
// DID trait | ||
// =========================================================================== | ||
|
||
/// Returns the {@link CoreDID} scheme. | ||
/// | ||
/// E.g. | ||
/// - `"did:example:12345678" -> "did"` | ||
/// - `"did:iota:smr:12345678" -> "did"` | ||
#[wasm_bindgen] | ||
pub fn scheme(&self) -> String { | ||
self.0.scheme().to_owned() | ||
} | ||
|
||
/// Returns the {@link CoreDID} authority: the method name and method-id. | ||
/// | ||
/// E.g. | ||
/// - `"did:example:12345678" -> "example:12345678"` | ||
/// - `"did:iota:smr:12345678" -> "iota:smr:12345678"` | ||
#[wasm_bindgen] | ||
pub fn authority(&self) -> String { | ||
self.0.authority().to_owned() | ||
} | ||
|
||
/// Returns the {@link CoreDID} method name. | ||
/// | ||
/// E.g. | ||
/// - `"did:example:12345678" -> "example"` | ||
/// - `"did:iota:smr:12345678" -> "iota"` | ||
#[wasm_bindgen] | ||
pub fn method(&self) -> String { | ||
self.0.method().to_owned() | ||
} | ||
|
||
/// Returns the {@link CoreDID} method-specific ID. | ||
/// | ||
/// E.g. | ||
/// - `"did:example:12345678" -> "12345678"` | ||
/// - `"did:iota:smr:12345678" -> "smr:12345678"` | ||
#[wasm_bindgen(js_name = methodId)] | ||
pub fn method_id(&self) -> String { | ||
self.0.method_id().to_owned() | ||
} | ||
|
||
/// Returns the {@link CoreDID} as a string. | ||
#[allow(clippy::inherent_to_string)] | ||
#[wasm_bindgen(js_name = toString)] | ||
pub fn to_string(&self) -> String { | ||
self.0.to_string() | ||
} | ||
|
||
// Only intended to be called internally. | ||
#[wasm_bindgen(js_name = toCoreDid, skip_typescript)] | ||
pub fn to_core_did(&self) -> WasmCoreDID { | ||
WasmCoreDID(self.0.clone().into()) | ||
} | ||
} | ||
|
||
impl_wasm_json!(WasmDIDJwk, DIDJwk); | ||
impl_wasm_clone!(WasmDIDJwk, DIDJwk); |
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
Oops, something went wrong.