Skip to content

Commit

Permalink
Crate/Repo Organization (iotaledger#116)
Browse files Browse the repository at this point in the history
* Rename Crates

* Move examples to repo root (improves discoverability)

* Remove base16/base64 helpers (not used internally as we use base58)

* Rename vc modules -> credential

* Make crate metadata consistent (authors, naming, etc.)

* Add basic docs for everything in identity-core
  • Loading branch information
l1h3r authored Jan 22, 2021
1 parent 13d6cc0 commit 0de3989
Show file tree
Hide file tree
Showing 151 changed files with 433 additions and 278 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
matrix:
project:
[
identity_core,
identity_derive,
identity_diff,
identity_iota,
identity-core,
identity-diff,
identity-iota,
]
os: [ubuntu-latest, windows-latest]

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

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

Expand Down
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[workspace]
members = [
"identity_core",
"identity_derive",
"identity_diff",
"identity_iota",
"identity-core",
"identity-diff",
"identity-iota",

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

exclude = [
"bindings/wasm",
"bindings/wasm",
]
19 changes: 10 additions & 9 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
[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-core = { version = "=0.1.0", path = "../../identity-core" }
identity-iota = { version = "=0.1.0", path = "../../identity-iota" }
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
8 changes: 1 addition & 7 deletions bindings/wasm/src/did.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use identity_core::utils::{decode_b58, decode_b64};
use identity_core::utils::decode_b58;
use identity_iota::did::IotaDID;
use wasm_bindgen::prelude::*;

Expand Down Expand Up @@ -27,12 +27,6 @@ impl DID {
Self::create(&decode_b58(key).map_err(js_err)?, 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())
}

/// Parses a `DID` from the input string.
#[wasm_bindgen]
pub fn parse(input: String) -> Result<DID, JsValue> {
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/src/iota.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use identity_core::common::Object;
use identity_iota::{
client::{Client, ClientBuilder, Network, TxnPrinter},
credential::CredentialValidator,
did::IotaDID,
vc::CredentialValidator,
};
use serde::Deserialize;
use wasm_bindgen::prelude::*;
Expand Down
11 changes: 1 addition & 10 deletions bindings/wasm/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use identity_core::{
crypto::{KeyPair, PublicKey, SecretKey},
did_doc::MethodType,
proof::JcsEd25519Signature2020,
utils::{decode_b58, decode_b64, encode_b58},
utils::{decode_b58, encode_b58},
};
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -39,15 +39,6 @@ impl Key {
Ok(Self(KeyPair::new(public, private)))
}

/// Parses a `Key` object from base64-encoded public/private keys.
#[wasm_bindgen(js_name = fromBase64)]
pub fn from_base64(public_key: &str, private_key: &str) -> Result<Key, JsValue> {
let public: PublicKey = decode_b64(public_key).map_err(js_err)?.into();
let private: SecretKey = decode_b64(private_key).map_err(js_err)?.into();

Ok(Self(KeyPair::new(public, private)))
}

/// Returns the public key as a base58-encoded string.
#[wasm_bindgen(getter)]
pub fn public(&self) -> String {
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/src/vc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use identity_core::{
common::{OneOrMany, Url},
vc::{Credential, CredentialBuilder, CredentialSubject, VerifiableCredential as VC},
credential::{Credential, CredentialBuilder, CredentialSubject, VerifiableCredential as VC},
};
use wasm_bindgen::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/src/vp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use identity_core::{
common::{OneOrMany, Url},
vc::{Presentation, PresentationBuilder, VerifiableCredential, VerifiablePresentation as VP},
credential::{Presentation, PresentationBuilder, VerifiableCredential, VerifiablePresentation as VP},
};
use wasm_bindgen::prelude::*;

Expand Down
12 changes: 12 additions & 0 deletions examples/credential/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "identity-example-credential"
version = "0.1.0"
authors = ["IOTA Identity"]
edition = "2018"
publish = false

[dependencies]
identity-core = { path = "../../identity-core" }
identity-iota = { path = "../../identity-iota" }
smol = { version = "0.1.18", features = ["tokio02"] }
smol-potat = { version = "0.3" }
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
//! A basic example that generates and publishes subject and issuer DID
//! Documents, creates a VerifiableCredential specifying claims about the
//! subject, and retrieves information through the CredentialValidator API.
//!
//! cargo run --example credential
use identity_core::{
common::{Url, Value},
convert::{FromJson as _, ToJson as _},
credential::{Credential, CredentialBuilder, CredentialSubject, VerifiableCredential},
did_doc::MethodScope,
did_url::DID,
json,
vc::{Credential, CredentialBuilder, CredentialSubject, VerifiableCredential},
};
use identity_iota::{
client::Client,
credential::{CredentialValidation, CredentialValidator},
crypto::KeyPair,
did::IotaDocument,
error::Result,
vc::{CredentialValidation, CredentialValidator},
};

// A helper function to generate and new DID Document/KeyPair, sign the
Expand Down
12 changes: 12 additions & 0 deletions examples/diff-chain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "identity-example-diff-chain"
version = "0.1.0"
authors = ["IOTA Identity"]
edition = "2018"
publish = false

[dependencies]
identity-core = { path = "../../identity-core" }
identity-iota = { path = "../../identity-iota" }
smol = { version = "0.1.18", features = ["tokio02"] }
smol-potat = { version = "0.3" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! cargo run --example document_diff
//! An example that utilizes a diff and auth chain to publish updates to a
//! DID Document.
use identity_core::{
did_doc::{MethodBuilder, MethodData, MethodRef, MethodType},
proof::JcsEd25519Signature2020,
Expand Down
12 changes: 12 additions & 0 deletions examples/resolution/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "identity-example-resolution"
version = "0.1.0"
authors = ["IOTA Identity"]
edition = "2018"
publish = false

[dependencies]
identity-core = { path = "../../identity-core" }
identity-iota = { path = "../../identity-iota" }
smol = { version = "0.1.18", features = ["tokio02"] }
smol-potat = { version = "0.3" }
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! A basic example that generates a DID Document, publishes it to the Tangle,
//! and retrieves information through DID Document resolution/dereferencing.
//!
//! cargo run --example document
use identity_core::resolver::{dereference, resolve, Dereference, Resolution};
use identity_iota::{
client::Client,
Expand Down
Loading

0 comments on commit 0de3989

Please sign in to comment.