Skip to content

Commit

Permalink
Merge pull request iotaledger#119 from iotaledger/chore/organization
Browse files Browse the repository at this point in the history
Crate/Repo Organization Pt. 2
  • Loading branch information
l1h3r authored Feb 3, 2021
2 parents c1e7b20 + 14bd900 commit 3c37b4d
Show file tree
Hide file tree
Showing 240 changed files with 13,932 additions and 10,463 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:
matrix:
project:
[
identity,
identity-core,
identity-credential,
identity-did,
identity-diff,
identity-iota,
]
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:
matrix:
project:
[
identity,
identity-core,
identity-credential,
identity-did,
identity-diff,
identity-iota,
bindings/wasm,
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:
matrix:
project:
[
identity,
identity-core,
identity-credential,
identity-did,
identity-diff,
identity-iota,
bindings/wasm,
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[workspace]
members = [
"identity",
"identity-core",
"identity-credential",
"identity-did",
"identity-diff",
"identity-iota",

"examples/credential",
"examples/diff-chain",
"examples/resolution",
"examples",
]

exclude = [
Expand Down
3 changes: 1 addition & 2 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ crate-type = ["cdylib"]

[dependencies]
console_error_panic_hook = { version = "0.1" }
identity-core = { version = "=0.1.0", path = "../../identity-core" }
identity-iota = { version = "=0.1.0", path = "../../identity-iota" }
identity = { version = "=0.1.0", path = "../../identity" }
serde = { version = "1.0", features = ["derive"] }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4", default-features = false }
Expand Down
95 changes: 48 additions & 47 deletions bindings/wasm/src/did.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use identity_core::utils::decode_b58;
use identity_iota::did::IotaDID;
use identity::core::decode_b58;
use identity::iota::IotaDID;
use wasm_bindgen::prelude::*;

use crate::{js_err, key::Key};
use crate::js_err;
use crate::key::Key;

/// @typicalname did
#[wasm_bindgen(inspectable)]
Expand All @@ -14,56 +15,56 @@ pub struct DID(pub(crate) IotaDID);

#[wasm_bindgen]
impl DID {
fn create(pubkey: &[u8], network: Option<&str>) -> Result<DID, JsValue> {
IotaDID::with_network(pubkey, network).map_err(js_err).map(Self)
}
fn create(pubkey: &[u8], network: Option<&str>) -> Result<DID, JsValue> {
IotaDID::with_network(pubkey, network).map_err(js_err).map(Self)
}

/// Creates a new `DID` from a `Key` object.
#[wasm_bindgen(constructor)]
pub fn new(key: &Key, network: Option<String>) -> Result<DID, JsValue> {
Self::create(key.0.public().as_ref(), network.as_deref())
}
/// Creates a new `DID` from a `Key` object.
#[wasm_bindgen(constructor)]
pub fn new(key: &Key, network: Option<String>) -> Result<DID, JsValue> {
Self::create(key.0.public().as_ref(), network.as_deref())
}

/// Creates a new `DID` from a base58-encoded public key.
#[wasm_bindgen(js_name = fromBase58Key)]
pub fn from_base58_key(key: &str, network: Option<String>) -> Result<DID, JsValue> {
Self::create(&decode_b58(key).map_err(js_err)?, network.as_deref())
}
/// Creates a new `DID` from a base58-encoded public key.
#[wasm_bindgen(js_name = fromBase58Key)]
pub fn from_base58_key(key: &str, network: Option<String>) -> Result<DID, JsValue> {
Self::create(&decode_b58(key).map_err(js_err)?, network.as_deref())
}

/// Parses a `DID` from the input string.
#[wasm_bindgen]
pub fn parse(input: String) -> Result<DID, JsValue> {
IotaDID::parse(input).map_err(js_err).map(Self)
}
/// Parses a `DID` from the input string.
#[wasm_bindgen]
pub fn parse(input: String) -> Result<DID, JsValue> {
IotaDID::parse(input).map_err(js_err).map(Self)
}

/// Returns the IOTA tangle network of the `DID`.
#[wasm_bindgen(getter)]
pub fn network(&self) -> String {
self.0.network().into()
}
/// Returns the IOTA tangle network of the `DID`.
#[wasm_bindgen(getter)]
pub fn network(&self) -> String {
self.0.network().into()
}

/// Returns the IOTA tangle shard of the `DID` (if any).
#[wasm_bindgen(getter)]
pub fn shard(&self) -> Option<String> {
self.0.shard().map(Into::into)
}
/// Returns the IOTA tangle shard of the `DID` (if any).
#[wasm_bindgen(getter)]
pub fn shard(&self) -> Option<String> {
self.0.shard().map(Into::into)
}

/// Returns the unique tag of the `DID`.
#[wasm_bindgen(getter)]
pub fn tag(&self) -> String {
self.0.method_id().into()
}
/// Returns the unique tag of the `DID`.
#[wasm_bindgen(getter)]
pub fn tag(&self) -> String {
self.0.method_id().into()
}

/// Returns the IOTA tangle address of the `DID`.
#[wasm_bindgen(getter)]
pub fn address(&self) -> String {
self.0.address()
}
/// Returns the IOTA tangle address of the `DID`.
#[wasm_bindgen(getter)]
pub fn address(&self) -> String {
self.0.address()
}

/// Returns the `DID` object as a string.
#[allow(clippy::inherent_to_string)]
#[wasm_bindgen(js_name = toString)]
pub fn to_string(&self) -> String {
self.0.to_string()
}
/// Returns the `DID` object as a string.
#[allow(clippy::inherent_to_string)]
#[wasm_bindgen(js_name = toString)]
pub fn to_string(&self) -> String {
self.0.to_string()
}
}
Loading

0 comments on commit 3c37b4d

Please sign in to comment.