Skip to content

Commit

Permalink
Merge branch 'dev' into feat/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
l1h3r committed Feb 4, 2021
2 parents b46c6d5 + 2e3210d commit 3609254
Show file tree
Hide file tree
Showing 307 changed files with 16,422 additions and 11,631 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
matrix:
project:
[
identity_core,
identity_derive,
identity_diff,
identity_iota,
identity,
identity-core,
identity-credential,
identity-did,
identity-diff,
identity-iota,
]
os: [ubuntu-latest, windows-latest]

Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
matrix:
project:
[
identity_core,
identity_derive,
identity_diff,
identity_iota,
identity,
identity-core,
identity-credential,
identity-did,
identity-diff,
identity-iota,
bindings/wasm,
]

Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
matrix:
project:
[
identity_core,
identity_derive,
identity_diff,
identity_iota,
identity,
identity-core,
identity-credential,
identity-did,
identity-diff,
identity-iota,
bindings/wasm,
]

Expand Down
2 changes: 2 additions & 0 deletions .license_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Copyright {20\d{2}(-20\d{2})?} IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
[workspace]
members = [
"identity_core",
"identity_derive",
"identity_diff",
"identity_iota",
"identity",
"identity-core",
"identity-credential",
"identity-did",
"identity-diff",
"identity-iota",

"examples",
]

exclude = [
"bindings/wasm",
"bindings/wasm",
]
1 change: 1 addition & 0 deletions bindings/wasm/.license_template
18 changes: 9 additions & 9 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
name = "iota_identity_wasm"
version = "0.0.1"
authors = ["Team Identity"]
name = "identity-wasm"
version = "0.1.0"
authors = ["IOTA Identity"]
edition = "2018"
description = "Web Assembly bindings for the identity-rs crate."
readme = "README.md"
repository = "https://github.com/iotaledger/identity.rs"
description = "WASM version of Identity.rs"
license = "Apache-2.0"
keywords = ["iota", "tangle", "identity", "wasm"]
homepage = "https://www.iota.org"
license = "MIT"

[lib]
crate-type = ["cdylib"]

[dependencies]
console_error_panic_hook = "0.1"
console_error_panic_hook = { version = "0.1" }
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 }

identity_core = { path = "../../identity_core" }
identity_iota = { path = "../../identity_iota" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
rand = { version = "0.7", default-features = false, features = ["wasm-bindgen"] }

Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/build/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs')
const path = require('path')
const jsdoc2md = require('jsdoc-to-markdown')

const importFile = path.join(__dirname, '../node/iota_identity_wasm.js')
const importFile = path.join(__dirname, '../node/identity_wasm.js')
const exportFile = path.join(__dirname, '../docs/api-reference.md')

const docsRoot = path.join(__dirname, '../docs')
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/build/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path')
const fs = require('fs')

// Add node fetch stuff (https://github.com/seanmonstar/reqwest/issues/910)
const entryFilePathNode = path.join(__dirname, '../node/iota_identity_wasm.js')
const entryFilePathNode = path.join(__dirname, '../node/identity_wasm.js')
const entryFileNode = fs.readFileSync(entryFilePathNode).toString()
let changedFileNode = entryFileNode.replace(
"let imports = {};",
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/build/web.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')
const fs = require('fs')

const entryFilePath = path.join(__dirname, '../web/iota_identity_wasm.js')
const entryFilePath = path.join(__dirname, '../web/identity_wasm.js')
const entryFile = fs.readFileSync(entryFilePath).toString()
// comment out this code so it works for Webpack
let changedFile = entryFile.replace(
Expand All @@ -20,15 +20,15 @@ let changedFile = entryFile.replace(
// Create an init function which imports the wasm file
.replace(
"export default init;",
"let __initializedIotaWasm = false\r\n\r\nexport function init(path) {\r\n if (__initializedIotaWasm) {\r\n return Promise.resolve(wasm)\r\n }\r\n return initWasm(path || \'iota_identity_wasm_bg.wasm\').then(() => {\r\n __initializedIotaWasm = true\r\n return wasm\r\n })\r\n}\r\n"
"let __initializedIotaWasm = false\r\n\r\nexport function init(path) {\r\n if (__initializedIotaWasm) {\r\n return Promise.resolve(wasm)\r\n }\r\n return initWasm(path || \'identity_wasm_bg.wasm\').then(() => {\r\n __initializedIotaWasm = true\r\n return wasm\r\n })\r\n}\r\n"
)

fs.writeFileSync(
entryFilePath,
changedFile
)

const entryFilePathTs = path.join(__dirname, '../web/iota_identity_wasm.d.ts')
const entryFilePathTs = path.join(__dirname, '../web/identity_wasm.d.ts')
const entryFileTs = fs.readFileSync(entryFilePathTs).toString()
// Replace the init function in the ts file
let changedFileTs = entryFileTs.replace(
Expand Down
31 changes: 3 additions & 28 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
* [.toString()](#DID+toString) ⇒ <code>string</code>
* _static_
* [.fromBase58Key(key, network)](#DID.fromBase58Key)[<code>DID</code>](#DID)
* [.fromBase64Key(key, network)](#DID.fromBase64Key)[<code>DID</code>](#DID)
* [.parse(input)](#DID.parse)[<code>DID</code>](#DID)

<a name="new_DID_new"></a>
Expand Down Expand Up @@ -108,18 +107,6 @@ Creates a new `DID` from a base58-encoded public key.
| key | <code>string</code> |
| network | <code>string</code> \| <code>undefined</code> |

<a name="DID.fromBase64Key"></a>

### DID.fromBase64Key(key, network) ⇒ [<code>DID</code>](#DID)
Creates a new `DID` from a base64-encoded public key.

**Kind**: static method of [<code>DID</code>](#DID)

| Param | Type |
| --- | --- |
| key | <code>string</code> |
| network | <code>string</code> \| <code>undefined</code> |

<a name="DID.parse"></a>

### DID.parse(input) ⇒ [<code>DID</code>](#DID)
Expand All @@ -145,7 +132,7 @@ Parses a `DID` from the input string.
* [.proof](#Doc+proof) ⇒ <code>any</code>
* [.sign(key)](#Doc+sign) ⇒ <code>any</code>
* [.verify()](#Doc+verify) ⇒ <code>boolean</code>
* [.diff(other, key)](#Doc+diff) ⇒ <code>any</code>
* [.diff(other, key, prev_msg)](#Doc+diff) ⇒ <code>any</code>
* [.verifyDiff(diff)](#Doc+verifyDiff) ⇒ <code>boolean</code>
* [.updateService(did, url, service_type)](#Doc+updateService)
* [.clearServices()](#Doc+clearServices)
Expand Down Expand Up @@ -209,7 +196,7 @@ Verify the signature with the authentication_key
**Kind**: instance method of [<code>Doc</code>](#Doc)
<a name="Doc+diff"></a>

### doc.diff(other, key) ⇒ <code>any</code>
### doc.diff(other, key, prev_msg) ⇒ <code>any</code>
Generate the difference between two DID Documents and sign it

**Kind**: instance method of [<code>Doc</code>](#Doc)
Expand All @@ -218,6 +205,7 @@ Generate the difference between two DID Documents and sign it
| --- | --- |
| other | [<code>Doc</code>](#Doc) |
| key | [<code>Key</code>](#Key) |
| prev_msg | <code>string</code> |

<a name="Doc+verifyDiff"></a>

Expand Down Expand Up @@ -389,7 +377,6 @@ Deserializes a `Doc` object from a JSON object.
* _static_
* [.generateEd25519()](#Key.generateEd25519)[<code>Key</code>](#Key)
* [.fromBase58(public_key, private_key)](#Key.fromBase58)[<code>Key</code>](#Key)
* [.fromBase64(public_key, private_key)](#Key.fromBase64)[<code>Key</code>](#Key)
* [.fromJSON(json)](#Key.fromJSON)[<code>Key</code>](#Key)

<a name="new_Key_new"></a>
Expand Down Expand Up @@ -438,18 +425,6 @@ Parses a `Key` object from base58-encoded public/private keys.
| public_key | <code>string</code> |
| private_key | <code>string</code> |

<a name="Key.fromBase64"></a>

### Key.fromBase64(public_key, private_key) ⇒ [<code>Key</code>](#Key)
Parses a `Key` object from base64-encoded public/private keys.

**Kind**: static method of [<code>Key</code>](#Key)

| Param | Type |
| --- | --- |
| public_key | <code>string</code> |
| private_key | <code>string</code> |

<a name="Key.fromJSON"></a>

### Key.fromJSON(json) ⇒ [<code>Key</code>](#Key)
Expand Down
1 change: 1 addition & 0 deletions bindings/wasm/rustfmt.toml
104 changes: 51 additions & 53 deletions bindings/wasm/src/did.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use identity_core::utils::{decode_b58, decode_b64};
use identity_iota::did::IotaDID;
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

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 @@ -11,62 +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)
}

/// 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())
}
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 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 `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 base64-encoded public key.
#[wasm_bindgen(js_name = fromBase64Key)]
pub fn from_base64_key(key: &str, network: Option<String>) -> Result<DID, JsValue> {
Self::create(&decode_b64(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 3609254

Please sign in to comment.