diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a0a2244c1d..ba313b06f2 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -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] diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index b08d10fd1a..b25fdf9862 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -20,10 +20,9 @@ jobs: matrix: project: [ - identity_core, - identity_derive, - identity_diff, - identity_iota, + identity-core, + identity-diff, + identity-iota, bindings/wasm, ] diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 9dbcbe79f4..c49591c4b7 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -20,10 +20,9 @@ jobs: matrix: project: [ - identity_core, - identity_derive, - identity_diff, - identity_iota, + identity-core, + identity-diff, + identity-iota, bindings/wasm, ] diff --git a/Cargo.toml b/Cargo.toml index ef680b3619..92b7abada3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", ] diff --git a/bindings/wasm/Cargo.toml b/bindings/wasm/Cargo.toml index ac015b5e89..3669f1dcb8 100644 --- a/bindings/wasm/Cargo.toml +++ b/bindings/wasm/Cargo.toml @@ -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"] } diff --git a/bindings/wasm/build/docs.js b/bindings/wasm/build/docs.js index 57db88a182..5504feb30a 100644 --- a/bindings/wasm/build/docs.js +++ b/bindings/wasm/build/docs.js @@ -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') diff --git a/bindings/wasm/build/node.js b/bindings/wasm/build/node.js index 3b86e0509b..57495ed763 100644 --- a/bindings/wasm/build/node.js +++ b/bindings/wasm/build/node.js @@ -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 = {};", diff --git a/bindings/wasm/build/web.js b/bindings/wasm/build/web.js index b168d37e9e..693242db0c 100644 --- a/bindings/wasm/build/web.js +++ b/bindings/wasm/build/web.js @@ -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( @@ -20,7 +20,7 @@ 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( @@ -28,7 +28,7 @@ fs.writeFileSync( 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( diff --git a/bindings/wasm/docs/api-reference.md b/bindings/wasm/docs/api-reference.md index d071e8b033..ab7adba579 100644 --- a/bindings/wasm/docs/api-reference.md +++ b/bindings/wasm/docs/api-reference.md @@ -52,7 +52,6 @@ * [.toString()](#DID+toString) ⇒ string * _static_ * [.fromBase58Key(key, network)](#DID.fromBase58Key) ⇒ [DID](#DID) - * [.fromBase64Key(key, network)](#DID.fromBase64Key) ⇒ [DID](#DID) * [.parse(input)](#DID.parse) ⇒ [DID](#DID) @@ -108,18 +107,6 @@ Creates a new `DID` from a base58-encoded public key. | key | string | | network | string \| undefined | - - -### DID.fromBase64Key(key, network) ⇒ [DID](#DID) -Creates a new `DID` from a base64-encoded public key. - -**Kind**: static method of [DID](#DID) - -| Param | Type | -| --- | --- | -| key | string | -| network | string \| undefined | - ### DID.parse(input) ⇒ [DID](#DID) @@ -145,7 +132,7 @@ Parses a `DID` from the input string. * [.proof](#Doc+proof) ⇒ any * [.sign(key)](#Doc+sign) ⇒ any * [.verify()](#Doc+verify) ⇒ boolean - * [.diff(other, key)](#Doc+diff) ⇒ any + * [.diff(other, key, prev_msg)](#Doc+diff) ⇒ any * [.verifyDiff(diff)](#Doc+verifyDiff) ⇒ boolean * [.updateService(did, url, service_type)](#Doc+updateService) * [.clearServices()](#Doc+clearServices) @@ -209,7 +196,7 @@ Verify the signature with the authentication_key **Kind**: instance method of [Doc](#Doc) -### doc.diff(other, key) ⇒ any +### doc.diff(other, key, prev_msg) ⇒ any Generate the difference between two DID Documents and sign it **Kind**: instance method of [Doc](#Doc) @@ -218,6 +205,7 @@ Generate the difference between two DID Documents and sign it | --- | --- | | other | [Doc](#Doc) | | key | [Key](#Key) | +| prev_msg | string | @@ -389,7 +377,6 @@ Deserializes a `Doc` object from a JSON object. * _static_ * [.generateEd25519()](#Key.generateEd25519) ⇒ [Key](#Key) * [.fromBase58(public_key, private_key)](#Key.fromBase58) ⇒ [Key](#Key) - * [.fromBase64(public_key, private_key)](#Key.fromBase64) ⇒ [Key](#Key) * [.fromJSON(json)](#Key.fromJSON) ⇒ [Key](#Key) @@ -438,18 +425,6 @@ Parses a `Key` object from base58-encoded public/private keys. | public_key | string | | private_key | string | - - -### Key.fromBase64(public_key, private_key) ⇒ [Key](#Key) -Parses a `Key` object from base64-encoded public/private keys. - -**Kind**: static method of [Key](#Key) - -| Param | Type | -| --- | --- | -| public_key | string | -| private_key | string | - ### Key.fromJSON(json) ⇒ [Key](#Key) diff --git a/bindings/wasm/src/did.rs b/bindings/wasm/src/did.rs index 10e03512a5..4fc1cf3ea4 100644 --- a/bindings/wasm/src/did.rs +++ b/bindings/wasm/src/did.rs @@ -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::*; @@ -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) -> Result { - 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 { diff --git a/bindings/wasm/src/iota.rs b/bindings/wasm/src/iota.rs index c60525e3e7..4734d5013e 100644 --- a/bindings/wasm/src/iota.rs +++ b/bindings/wasm/src/iota.rs @@ -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::*; diff --git a/bindings/wasm/src/key.rs b/bindings/wasm/src/key.rs index eda47e5f22..db821c678a 100644 --- a/bindings/wasm/src/key.rs +++ b/bindings/wasm/src/key.rs @@ -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::*; @@ -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 { - 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 { diff --git a/bindings/wasm/src/vc.rs b/bindings/wasm/src/vc.rs index 4f1ff6a7e3..2c6b9277bf 100644 --- a/bindings/wasm/src/vc.rs +++ b/bindings/wasm/src/vc.rs @@ -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::*; diff --git a/bindings/wasm/src/vp.rs b/bindings/wasm/src/vp.rs index 44d3fcaa75..ed23714e42 100644 --- a/bindings/wasm/src/vp.rs +++ b/bindings/wasm/src/vp.rs @@ -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::*; diff --git a/examples/credential/Cargo.toml b/examples/credential/Cargo.toml new file mode 100644 index 0000000000..bfe7e2c0b7 --- /dev/null +++ b/examples/credential/Cargo.toml @@ -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" } diff --git a/identity_iota/examples/credential.rs b/examples/credential/src/main.rs similarity index 94% rename from identity_iota/examples/credential.rs rename to examples/credential/src/main.rs index 0939e13588..3e888b447d 100644 --- a/identity_iota/examples/credential.rs +++ b/examples/credential/src/main.rs @@ -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 diff --git a/examples/diff-chain/Cargo.toml b/examples/diff-chain/Cargo.toml new file mode 100644 index 0000000000..97a0f810f1 --- /dev/null +++ b/examples/diff-chain/Cargo.toml @@ -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" } diff --git a/identity_iota/examples/document_diff.rs b/examples/diff-chain/src/main.rs similarity index 98% rename from identity_iota/examples/document_diff.rs rename to examples/diff-chain/src/main.rs index 3e8a49e024..7b5655f3e2 100644 --- a/identity_iota/examples/document_diff.rs +++ b/examples/diff-chain/src/main.rs @@ -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, diff --git a/examples/resolution/Cargo.toml b/examples/resolution/Cargo.toml new file mode 100644 index 0000000000..bd42da12f3 --- /dev/null +++ b/examples/resolution/Cargo.toml @@ -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" } diff --git a/identity_iota/examples/document.rs b/examples/resolution/src/main.rs similarity index 97% rename from identity_iota/examples/document.rs rename to examples/resolution/src/main.rs index 2f85f12261..1953b4e592 100644 --- a/identity_iota/examples/document.rs +++ b/examples/resolution/src/main.rs @@ -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, diff --git a/identity_core/Cargo.toml b/identity-core/Cargo.toml similarity index 59% rename from identity_core/Cargo.toml rename to identity-core/Cargo.toml index 00e3558950..9fda71d41c 100644 --- a/identity_core/Cargo.toml +++ b/identity-core/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "identity_core" +name = "identity-core" version = "0.1.0" authors = ["IOTA Identity"] edition = "2018" -description = "An implementation of the Decentralized Identifiers (DID) standard" +description = "The core traits and types for the identity-rs library." readme = "../README.md" repository = "https://github.com/iotaledger/identity.rs" license = "Apache-2.0" @@ -11,23 +11,20 @@ keywords = ["iota", "tangle", "identity"] homepage = "https://www.iota.org" [dependencies] -anyhow = { version = "1.0" } +anyhow = { version = "1.0", default-features = false } async-trait = { version = "0.1", default-features = false } -base64 = { version = "0.12", default-features = false, features = ["std"] } -bs58 = { version = "0.3", default-features = false, features = ["std"] } +bs58 = { version = "0.4", default-features = false, features = ["std"] } chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } did_doc = { git = "https://github.com/l1h3r/did_doc", rev = "bb8bda8f6d39451b08e3cc198f956c212a3b87f8", default-features = false, features = ["std"] } did_url = { version = "0.1", default-features = false, features = ["std", "serde"] } ed25519-zebra = { version = "2.2", default-features = false } -hex = { version = "0.4", default-features = false , features = ["std"] } +identity-diff = { version = "=0.1.0", path = "../identity-diff", default-features = false } lazy_static = { version = "1.4", default-features = false } rand = { version = "0.7", default-features = false, features = ["getrandom"] } -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", default-features = false, features = ["std", "derive"] } serde_jcs = { version = "0.1", default-features = false } -serde_json = { version = "1.0", features = ["preserve_order"] } -sha2 = { version = "0.9" } +serde_json = { version = "1.0", default-features = false, features = ["preserve_order", "std"] } +sha2 = { version = "0.9", default-features = false } subtle = { version = "2.4" } -thiserror = { version = "1.0" } -zeroize = { version = "1.1" } - -identity_diff = { path = "../identity_diff", version = "0.1.0", features = ["diff_derive"] } +thiserror = { version = "1.0", default-features = false } +zeroize = { version = "1.1", default-features = false } diff --git a/identity_core/src/common/context.rs b/identity-core/src/common/context.rs similarity index 91% rename from identity_core/src/common/context.rs rename to identity-core/src/common/context.rs index 90cd785692..f19fa5b73a 100644 --- a/identity_core/src/common/context.rs +++ b/identity-core/src/common/context.rs @@ -9,7 +9,9 @@ use crate::common::{Object, Url}; #[derive(Clone, PartialEq, Deserialize, Serialize)] #[serde(untagged)] pub enum Context { + /// A JSON-LD context expressed as a Url. Url(Url), + /// A JSON-LD context expressed as a JSON object. Obj(Object), } diff --git a/identity_core/src/common/mod.rs b/identity-core/src/common/mod.rs similarity index 61% rename from identity_core/src/common/mod.rs rename to identity-core/src/common/mod.rs index 5f5dd66be2..98de9328e5 100644 --- a/identity_core/src/common/mod.rs +++ b/identity-core/src/common/mod.rs @@ -1,7 +1,9 @@ -pub mod context; -pub mod one_or_many; -pub mod timestamp; -pub mod url; +//! Definitions of common types. + +mod context; +mod one_or_many; +mod timestamp; +mod url; pub use context::Context; pub use did_doc::{Object, Value}; diff --git a/identity_core/src/common/one_or_many.rs b/identity-core/src/common/one_or_many.rs similarity index 96% rename from identity_core/src/common/one_or_many.rs rename to identity-core/src/common/one_or_many.rs index 5ebc0c6d91..b917799371 100644 --- a/identity_core/src/common/one_or_many.rs +++ b/identity-core/src/common/one_or_many.rs @@ -10,7 +10,9 @@ use core::{ #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] #[serde(untagged)] pub enum OneOrMany { + /// A single instance of `T`. One(T), + /// Multiple instances of `T`. Many(Vec), } @@ -83,7 +85,7 @@ impl OneOrMany { &*self } - /// Consumes the `OneOrMany` and returns the contents as a `Vec`. + /// Consumes the [`OneOrMany`] and returns the contents as a [`Vec`]. pub fn into_vec(self) -> Vec { match self { Self::One(inner) => vec![inner], diff --git a/identity_core/src/common/timestamp.rs b/identity-core/src/common/timestamp.rs similarity index 91% rename from identity_core/src/common/timestamp.rs rename to identity-core/src/common/timestamp.rs index 1173dc985c..b819ff5e37 100644 --- a/identity_core/src/common/timestamp.rs +++ b/identity-core/src/common/timestamp.rs @@ -14,7 +14,7 @@ use crate::error::{Error, Result}; pub struct Timestamp(DateTime); impl Timestamp { - /// Parses a `Timestamp` from the provided input string. + /// Parses a [`Timestamp`] from the provided input string. pub fn parse(input: &str) -> Result { DateTime::parse_from_rfc3339(input) .map_err(Into::into) @@ -22,17 +22,17 @@ impl Timestamp { .map(Self) } - /// Creates a new `Timestamp` with the current date and time. + /// Creates a new [`Timestamp`] with the current date and time. pub fn now() -> Self { Self::parse(&Self::to_rfc3339(&Self(Utc::now()))).unwrap() } - /// Returns the `Timestamp` as a Unix timestamp. + /// Returns the [`Timestamp`] as a Unix timestamp. pub fn to_unix(&self) -> i64 { self.0.timestamp() } - /// Returns the `Timestamp` as an RFC 3339 `String`. + /// Returns the [`Timestamp`] as an RFC 3339 `String`. pub fn to_rfc3339(&self) -> String { self.0.to_rfc3339_opts(SecondsFormat::Secs, true) } diff --git a/identity_core/src/common/url.rs b/identity-core/src/common/url.rs similarity index 87% rename from identity_core/src/common/url.rs rename to identity-core/src/common/url.rs index 7af6ac673c..40383aeaed 100644 --- a/identity_core/src/common/url.rs +++ b/identity-core/src/common/url.rs @@ -14,17 +14,17 @@ use crate::error::{Error, Result}; pub struct Url(url::Url); impl Url { - /// Parses an absolute `Url` from the given input string. + /// Parses an absolute [`Url`] from the given input string. pub fn parse(input: impl AsRef) -> Result { url::Url::parse(input.as_ref()).map_err(Into::into).map(Self) } - /// Consumes the `Url` and returns the value as a `String`. + /// Consumes the [`Url`] and returns the value as a `String`. pub fn into_string(self) -> String { self.0.into_string() } - /// Parses the given input string as a `Url`, with `self` as the base `Url`. + /// Parses the given input string as a [`Url`], with `self` as the base Url. pub fn join(&self, input: impl AsRef) -> Result { self.0.join(input.as_ref()).map_err(Into::into).map(Self) } diff --git a/identity_core/src/convert/as_json.rs b/identity-core/src/convert/json.rs similarity index 60% rename from identity_core/src/convert/as_json.rs rename to identity-core/src/convert/json.rs index 4b8caf7c31..330b597ad5 100644 --- a/identity_core/src/convert/as_json.rs +++ b/identity-core/src/convert/json.rs @@ -1,22 +1,33 @@ use crate::error::{Error, Result}; use serde::{Deserialize, Serialize}; +/// A convenience-trait for types that can be serialized as JSON. pub trait ToJson: Serialize { + /// Serialize `self` as a string of JSON. fn to_json(&self) -> Result { serde_json::to_string(self).map_err(Error::EncodeJSON) } + /// Serialize `self` as a JSON byte vector. fn to_json_vec(&self) -> Result> { serde_json::to_vec(self).map_err(Error::EncodeJSON) } + /// Serialize `self` as a [`serde_json::Value`]. fn to_json_value(&self) -> Result { serde_json::to_value(self).map_err(Error::EncodeJSON) } + /// Serialize `self` as a pretty-printed string of JSON. fn to_json_pretty(&self) -> Result { serde_json::to_string_pretty(self).map_err(Error::EncodeJSON) } + + /// Serialize `self` as a JSON byte vector, normalized using JSON + /// Canonicalization Scheme (JCS). + fn to_jcs(&self) -> Result> { + serde_jcs::to_vec(self).map_err(Error::EncodeJSON) + } } impl ToJson for T where T: Serialize {} @@ -24,15 +35,19 @@ impl ToJson for T where T: Serialize {} // ============================================================================= // ============================================================================= +/// A convenience-trait for types that can be deserialized from JSON. pub trait FromJson: for<'de> Deserialize<'de> + Sized { + /// Deserialize `Self` from a string of JSON text. fn from_json(json: &(impl AsRef + ?Sized)) -> Result { serde_json::from_str(json.as_ref()).map_err(Error::DecodeJSON) } + /// Deserialize `Self` from bytes of JSON text. fn from_json_slice(json: &(impl AsRef<[u8]> + ?Sized)) -> Result { serde_json::from_slice(json.as_ref()).map_err(Error::DecodeJSON) } + /// Deserialize `Self` from a [`serde_json::Value`]. fn from_json_value(json: serde_json::Value) -> Result { serde_json::from_value(json).map_err(Error::DecodeJSON) } @@ -43,30 +58,48 @@ impl FromJson for T where T: for<'de> Deserialize<'de> + Sized {} // ============================================================================= // ============================================================================= +/// A convenience-trait for types that can be converted to and from JSON. pub trait AsJson: FromJson + ToJson { + /// Deserialize `Self` from a string of JSON text. fn from_json(json: &(impl AsRef + ?Sized)) -> Result { ::from_json(json) } + /// Deserialize `Self` from bytes of JSON text. fn from_json_slice(json: &(impl AsRef<[u8]> + ?Sized)) -> Result { ::from_json_slice(json) } + /// Deserialize `Self` from a [`serde_json::Value`]. + fn from_json_value(json: serde_json::Value) -> Result { + ::from_json_value(json) + } + + /// Serialize `self` as a string of JSON. fn to_json(&self) -> Result { ::to_json(self) } + /// Serialize `self` as a JSON byte vector. fn to_json_vec(&self) -> Result> { ::to_json_vec(self) } + /// Serialize `self` as a [`serde_json::Value`]. fn to_json_value(&self) -> Result { ::to_json_value(self) } + /// Serialize `self` as a pretty-printed string of JSON. fn to_json_pretty(&self) -> Result { ::to_json_pretty(self) } + + /// Serialize `self` as a JSON byte vector, normalized using JSON + /// Canonicalization Scheme (JCS). + fn to_jcs(&self) -> Result> { + ::to_jcs(self) + } } impl AsJson for T where T: FromJson + ToJson {} diff --git a/identity-core/src/convert/mod.rs b/identity-core/src/convert/mod.rs new file mode 100644 index 0000000000..4c573a4f9f --- /dev/null +++ b/identity-core/src/convert/mod.rs @@ -0,0 +1,6 @@ +//! Traits for conversions between types. + +mod json; +mod serde_into; + +pub use self::{json::*, serde_into::*}; diff --git a/identity-core/src/convert/serde_into.rs b/identity-core/src/convert/serde_into.rs new file mode 100644 index 0000000000..4a679f3b63 --- /dev/null +++ b/identity-core/src/convert/serde_into.rs @@ -0,0 +1,18 @@ +use crate::{ + convert::{AsJson, ToJson}, + error::Result, +}; + +/// An escape-hatch for converting between types that represent the same JSON +/// structure. +pub trait SerdeInto: ToJson { + /// Converts `self` to `T` by converting to/from JSON. + fn serde_into(&self) -> Result + where + T: AsJson, + { + ::to_json_value(self).and_then(::from_json_value) + } +} + +impl SerdeInto for T where T: ToJson {} diff --git a/identity_core/src/vc/credential.rs b/identity-core/src/credential/credential.rs similarity index 98% rename from identity_core/src/vc/credential.rs rename to identity-core/src/credential/credential.rs index adc771b369..03ff08ccfe 100644 --- a/identity_core/src/vc/credential.rs +++ b/identity-core/src/credential/credential.rs @@ -5,13 +5,13 @@ use serde::Serialize; use crate::{ common::{Context, Object, OneOrMany, Timestamp, Url}, convert::ToJson as _, - crypto::SecretKey, - error::{Error, Result}, - proof::JcsEd25519Signature2020, - vc::{ + credential::{ CredentialBuilder, CredentialSchema, CredentialStatus, CredentialSubject, Evidence, Issuer, RefreshService, TermsOfUse, VerifiableCredential, }, + crypto::SecretKey, + error::{Error, Result}, + proof::JcsEd25519Signature2020, }; lazy_static! { @@ -139,6 +139,8 @@ impl Credential { Ok(()) } + /// Creates a new [`VerifiableCredential`] by signing `self` with `document` + /// and `secret`. pub fn sign<'a, Q, D1, D2, D3>( self, document: &Document, @@ -182,7 +184,7 @@ where #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::Credential}; + use crate::{convert::FromJson as _, credential::Credential}; const JSON1: &str = include_str!("../../tests/fixtures/vc/credential-1.json"); const JSON2: &str = include_str!("../../tests/fixtures/vc/credential-2.json"); diff --git a/identity_core/src/vc/credential_builder.rs b/identity-core/src/credential/credential_builder.rs similarity index 98% rename from identity_core/src/vc/credential_builder.rs rename to identity-core/src/credential/credential_builder.rs index 13b9c5d3dc..21943d480f 100644 --- a/identity_core/src/vc/credential_builder.rs +++ b/identity-core/src/credential/credential_builder.rs @@ -1,9 +1,9 @@ use crate::{ common::{Context, Object, Timestamp, Url, Value}, - error::Result, - vc::{ + credential::{ Credential, CredentialSchema, CredentialStatus, CredentialSubject, Evidence, Issuer, RefreshService, TermsOfUse, }, + error::Result, }; /// A `CredentialBuilder` is used to create a customized `Credential`. @@ -185,7 +185,7 @@ mod tests { use crate::{ common::{Object, Timestamp, Url}, convert::FromJson as _, - vc::{Credential as Credential_, CredentialBuilder, CredentialSubject}, + credential::{Credential as Credential_, CredentialBuilder, CredentialSubject}, }; type Credential = Credential_; diff --git a/identity_core/src/vc/mod.rs b/identity-core/src/credential/mod.rs similarity index 77% rename from identity_core/src/vc/mod.rs rename to identity-core/src/credential/mod.rs index c674f4c677..a8969e9044 100644 --- a/identity_core/src/vc/mod.rs +++ b/identity-core/src/credential/mod.rs @@ -1,3 +1,7 @@ +//! Types and traits for working with Verifiable Credentials. + +#![allow(clippy::module_inception)] + mod credential; mod credential_builder; mod presentation; diff --git a/identity_core/src/vc/presentation.rs b/identity-core/src/credential/presentation.rs similarity index 96% rename from identity_core/src/vc/presentation.rs rename to identity-core/src/credential/presentation.rs index 77796d646f..6bb45287b9 100644 --- a/identity_core/src/vc/presentation.rs +++ b/identity-core/src/credential/presentation.rs @@ -4,8 +4,8 @@ use serde::Serialize; use crate::{ common::{Context, Object, OneOrMany, Url}, convert::ToJson as _, + credential::{Credential, PresentationBuilder, RefreshService, TermsOfUse, VerifiableCredential}, error::{Error, Result}, - vc::{Credential, PresentationBuilder, RefreshService, TermsOfUse, VerifiableCredential}, }; /// A `Presentation` represents a bundle of one or more `VerifiableCredential`s. @@ -115,7 +115,7 @@ where mod tests { use crate::{ convert::FromJson as _, - vc::{CredentialSubject, VerifiableCredential, VerifiablePresentation}, + credential::{CredentialSubject, VerifiableCredential, VerifiablePresentation}, }; const JSON: &str = include_str!("../../tests/fixtures/vc/presentation-1.json"); diff --git a/identity_core/src/vc/presentation_builder.rs b/identity-core/src/credential/presentation_builder.rs similarity index 98% rename from identity_core/src/vc/presentation_builder.rs rename to identity-core/src/credential/presentation_builder.rs index dd5e120f9e..6ac409e255 100644 --- a/identity_core/src/vc/presentation_builder.rs +++ b/identity-core/src/credential/presentation_builder.rs @@ -1,7 +1,7 @@ use crate::{ common::{Context, Object, Url, Value}, + credential::{Presentation, RefreshService, TermsOfUse, VerifiableCredential}, error::Result, - vc::{Presentation, RefreshService, TermsOfUse, VerifiableCredential}, }; /// A `PresentationBuilder` is used to create a customized `Presentation`. @@ -131,13 +131,13 @@ mod tests { use crate::{ common::{Object, Url}, convert::FromJson as _, - crypto::KeyPair, - proof::JcsEd25519Signature2020, - utils::encode_b58, - vc::{ + credential::{ Credential as Credential_, CredentialBuilder, CredentialSubject, Presentation as Presentation_, PresentationBuilder, VerifiableCredential, }, + crypto::KeyPair, + proof::JcsEd25519Signature2020, + utils::encode_b58, }; type Credential = Credential_; diff --git a/identity_core/src/vc/types/credential_schema.rs b/identity-core/src/credential/types/credential_schema.rs similarity index 84% rename from identity_core/src/vc/types/credential_schema.rs rename to identity-core/src/credential/types/credential_schema.rs index 44bfc1f85d..2d96240b3e 100644 --- a/identity_core/src/vc/types/credential_schema.rs +++ b/identity-core/src/credential/types/credential_schema.rs @@ -5,14 +5,18 @@ use crate::common::{Object, OneOrMany, Url}; /// [More Info](https://www.w3.org/TR/vc-data-model/#data-schemas) #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct CredentialSchema { + /// A Url identifying the credential schema file. pub id: Url, + /// The type(s) of the credential schema. #[serde(rename = "type")] pub types: OneOrMany, + /// Additional properties of the credential schema. #[serde(flatten)] pub properties: Object, } impl CredentialSchema { + /// Creates a new [`CredentialSchema`]. pub fn new(id: Url, types: T) -> Self where T: Into>, @@ -20,6 +24,7 @@ impl CredentialSchema { Self::with_properties(id, types, Object::new()) } + /// Creates a new [`CredentialSchema`] with the given `properties`. pub fn with_properties(id: Url, types: T, properties: Object) -> Self where T: Into>, @@ -34,7 +39,7 @@ impl CredentialSchema { #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::CredentialSchema}; + use crate::{convert::FromJson as _, credential::CredentialSchema}; const JSON1: &str = include_str!("../../../tests/fixtures/vc/credential-schema-1.json"); const JSON2: &str = include_str!("../../../tests/fixtures/vc/credential-schema-2.json"); diff --git a/identity_core/src/vc/types/credential_status.rs b/identity-core/src/credential/types/credential_status.rs similarity index 78% rename from identity_core/src/vc/types/credential_status.rs rename to identity-core/src/credential/types/credential_status.rs index b4031bd285..19a07aaaf5 100644 --- a/identity_core/src/vc/types/credential_status.rs +++ b/identity-core/src/credential/types/credential_status.rs @@ -5,14 +5,18 @@ use crate::common::{Object, OneOrMany, Url}; /// [More Info](https://www.w3.org/TR/vc-data-model/#status) #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct CredentialStatus { + /// A Url identifying the credential status. pub id: Url, + /// The type(s) of the credential status. #[serde(rename = "type")] pub types: OneOrMany, + /// Additional properties of the credential status. #[serde(flatten)] pub properties: Object, } impl CredentialStatus { + /// Creates a new [`CredentialStatus`]. pub fn new(id: Url, types: T) -> Self where T: Into>, @@ -20,6 +24,7 @@ impl CredentialStatus { Self::with_properties(id, types, Object::new()) } + /// Creates a new [`CredentialStatus`] with the given `properties`. pub fn with_properties(id: Url, types: T, properties: Object) -> Self where T: Into>, @@ -34,7 +39,7 @@ impl CredentialStatus { #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::CredentialStatus}; + use crate::{convert::FromJson as _, credential::CredentialStatus}; const JSON: &str = include_str!("../../../tests/fixtures/vc/credential-status-1.json"); diff --git a/identity_core/src/vc/types/credential_subject.rs b/identity-core/src/credential/types/credential_subject.rs similarity index 93% rename from identity_core/src/vc/types/credential_subject.rs rename to identity-core/src/credential/types/credential_subject.rs index 11c7dc11d8..4a5b6f201e 100644 --- a/identity_core/src/vc/types/credential_subject.rs +++ b/identity-core/src/credential/types/credential_subject.rs @@ -5,25 +5,31 @@ use crate::common::{Object, Url}; /// [More Info](https://www.w3.org/TR/vc-data-model/#credential-subject) #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct CredentialSubject { + /// A Url identifying the credential subject. #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, + /// Additional properties of the credential subject. #[serde(flatten)] pub properties: Object, } impl CredentialSubject { + /// Creates a new [`CredentialSubject`]. pub fn new() -> Self { Self::with_properties(Object::new()) } + /// Creates a new [`CredentialSubject`] with the given `id`. pub fn with_id(id: Url) -> Self { Self::with_id_and_properties(id, Object::new()) } + /// Creates a new [`CredentialSubject`] with the given `properties`. pub fn with_properties(properties: Object) -> Self { Self { id: None, properties } } + /// Creates a new [`CredentialSubject`] with the given `id` and `properties`. pub fn with_id_and_properties(id: Url, properties: Object) -> Self { Self { id: Some(id), @@ -34,7 +40,7 @@ impl CredentialSubject { #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::CredentialSubject}; + use crate::{convert::FromJson as _, credential::CredentialSubject}; const JSON1: &str = include_str!("../../../tests/fixtures/vc/credential-subject-1.json"); const JSON2: &str = include_str!("../../../tests/fixtures/vc/credential-subject-2.json"); diff --git a/identity_core/src/vc/types/evidence.rs b/identity-core/src/credential/types/evidence.rs similarity index 84% rename from identity_core/src/vc/types/evidence.rs rename to identity-core/src/credential/types/evidence.rs index cc69ab8216..61ebc344b7 100644 --- a/identity_core/src/vc/types/evidence.rs +++ b/identity-core/src/credential/types/evidence.rs @@ -5,15 +5,19 @@ use crate::common::{Object, OneOrMany}; /// [More Info](https://www.w3.org/TR/vc-data-model/#evidence) #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct Evidence { + /// A Url that allows retrieval of information about the evidence. #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, + /// The type(s) of the credential evidence. #[serde(rename = "type")] pub types: OneOrMany, + /// Additional properties of the credential evidence. #[serde(flatten)] pub properties: Object, } impl Evidence { + /// Creates a new [`Evidence`] instance. pub fn new(types: T) -> Self where T: Into>, @@ -21,6 +25,7 @@ impl Evidence { Self::with_properties(types, Object::new()) } + /// Creates a new [`Evidence`] instance with the given `id`. pub fn with_id(types: T, id: U) -> Self where T: Into>, @@ -33,6 +38,7 @@ impl Evidence { } } + /// Creates a new [`Evidence`] instance with the given `properties`. pub fn with_properties(types: T, properties: Object) -> Self where T: Into>, @@ -44,6 +50,7 @@ impl Evidence { } } + /// Creates a new [`Evidence`] instance with the given `id` and `properties`. pub fn with_id_and_properties(types: T, id: U, properties: Object) -> Self where T: Into>, @@ -59,7 +66,7 @@ impl Evidence { #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::Evidence}; + use crate::{convert::FromJson as _, credential::Evidence}; const JSON1: &str = include_str!("../../../tests/fixtures/vc/evidence-1.json"); const JSON2: &str = include_str!("../../../tests/fixtures/vc/evidence-2.json"); diff --git a/identity_core/src/vc/types/issuer.rs b/identity-core/src/credential/types/issuer.rs similarity index 81% rename from identity_core/src/vc/types/issuer.rs rename to identity-core/src/credential/types/issuer.rs index c2b50a830b..506deddd0b 100644 --- a/identity_core/src/vc/types/issuer.rs +++ b/identity-core/src/credential/types/issuer.rs @@ -5,7 +5,9 @@ use crate::common::{Object, Url}; /// [More Info](https://www.w3.org/TR/vc-data-model/#issuer) #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct IssuerData { + /// A Url identifying the credential issuer. pub id: Url, + /// Additional properties of the credential issuer. #[serde(flatten)] pub properties: Object, } @@ -16,11 +18,14 @@ pub struct IssuerData { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[serde(untagged)] pub enum Issuer { + /// A credential issuer expressed as a Url. Url(Url), + /// A credential issuer expressed as a JSON object. Obj(IssuerData), } impl Issuer { + /// Returns a reference to the credential issuer Url. pub fn url(&self) -> &Url { match self { Self::Url(url) => url, @@ -40,7 +45,7 @@ where #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::Issuer}; + use crate::{convert::FromJson as _, credential::Issuer}; const JSON1: &str = include_str!("../../../tests/fixtures/vc/issuer-1.json"); const JSON2: &str = include_str!("../../../tests/fixtures/vc/issuer-2.json"); diff --git a/identity_core/src/vc/types/mod.rs b/identity-core/src/credential/types/mod.rs similarity index 100% rename from identity_core/src/vc/types/mod.rs rename to identity-core/src/credential/types/mod.rs diff --git a/identity_core/src/vc/types/refresh_service.rs b/identity-core/src/credential/types/refresh_service.rs similarity index 77% rename from identity_core/src/vc/types/refresh_service.rs rename to identity-core/src/credential/types/refresh_service.rs index 9bdfa7dd48..ddc41f0c26 100644 --- a/identity_core/src/vc/types/refresh_service.rs +++ b/identity-core/src/credential/types/refresh_service.rs @@ -5,14 +5,18 @@ use crate::common::{Object, OneOrMany, Url}; /// [More Info](https://www.w3.org/TR/vc-data-model/#refreshing) #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct RefreshService { + /// The Url of the credential refresh service. pub id: Url, + /// The type(s) of the credential refresh service. #[serde(rename = "type")] pub types: OneOrMany, + /// Additional properties of the credential refresh service. #[serde(flatten)] pub properties: Object, } impl RefreshService { + /// Creates a new [`RefreshService`]. pub fn new(id: Url, types: T) -> Self where T: Into>, @@ -20,6 +24,7 @@ impl RefreshService { Self::with_properties(id, types, Object::new()) } + /// Creates a new [`RefreshService`] with the given `properties`. pub fn with_properties(id: Url, types: T, properties: Object) -> Self where T: Into>, @@ -34,7 +39,7 @@ impl RefreshService { #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::RefreshService}; + use crate::{convert::FromJson as _, credential::RefreshService}; const JSON: &str = include_str!("../../../tests/fixtures/vc/refresh-service-1.json"); diff --git a/identity_core/src/vc/types/terms_of_use.rs b/identity-core/src/credential/types/terms_of_use.rs similarity index 86% rename from identity_core/src/vc/types/terms_of_use.rs rename to identity-core/src/credential/types/terms_of_use.rs index 7130449152..b3c4310e3b 100644 --- a/identity_core/src/vc/types/terms_of_use.rs +++ b/identity-core/src/credential/types/terms_of_use.rs @@ -6,15 +6,19 @@ use crate::common::{Object, OneOrMany, Url}; /// [More Info](https://www.w3.org/TR/vc-data-model/#terms-of-use) #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct TermsOfUse { + /// The instance id of the credential terms-of-use. #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, + /// The type(s) of the credential terms-of-use. #[serde(rename = "type")] pub types: OneOrMany, + /// Additional properties of the credential terms-of-use. #[serde(flatten)] pub properties: Object, } impl TermsOfUse { + /// Creates a new [`TermsOfUse`] instance. pub fn new(types: T) -> Self where T: Into>, @@ -26,6 +30,7 @@ impl TermsOfUse { } } + /// Creates a new [`TermsOfUse`] instance with the given `id`. pub fn with_id(types: T, id: Url) -> Self where T: Into>, @@ -37,6 +42,7 @@ impl TermsOfUse { } } + /// Creates a new [`TermsOfUse`] instance with the given `properties`. pub fn with_properties(types: T, properties: Object) -> Self where T: Into>, @@ -48,6 +54,7 @@ impl TermsOfUse { } } + /// Creates a new [`TermsOfUse`] instance with the given `id` and `properties`. pub fn with_id_and_properties(types: T, id: Url, properties: Object) -> Self where T: Into>, @@ -62,7 +69,7 @@ impl TermsOfUse { #[cfg(test)] mod tests { - use crate::{convert::FromJson as _, vc::TermsOfUse}; + use crate::{convert::FromJson as _, credential::TermsOfUse}; const JSON1: &str = include_str!("../../../tests/fixtures/vc/terms-of-use-1.json"); const JSON2: &str = include_str!("../../../tests/fixtures/vc/terms-of-use-2.json"); diff --git a/identity_core/src/vc/verifiable_credential.rs b/identity-core/src/credential/verifiable_credential.rs similarity index 98% rename from identity_core/src/vc/verifiable_credential.rs rename to identity-core/src/credential/verifiable_credential.rs index 7f935bac83..be2ac2a3a3 100644 --- a/identity_core/src/vc/verifiable_credential.rs +++ b/identity-core/src/credential/verifiable_credential.rs @@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize}; use crate::{ common::{Object, OneOrMany}, convert::ToJson as _, + credential::Credential, did_doc::{SetSignature, Signature, TrySignature, TrySignatureMut}, - vc::Credential, }; /// A `VerifiableCredential` represents a `Credential` with an associated diff --git a/identity_core/src/vc/verifiable_presentation.rs b/identity-core/src/credential/verifiable_presentation.rs similarity index 98% rename from identity_core/src/vc/verifiable_presentation.rs rename to identity-core/src/credential/verifiable_presentation.rs index 7e5e47205f..d83c84f268 100644 --- a/identity_core/src/vc/verifiable_presentation.rs +++ b/identity-core/src/credential/verifiable_presentation.rs @@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize}; use crate::{ common::{Object, OneOrMany}, convert::ToJson as _, + credential::Presentation, did_doc::{SetSignature, Signature, TrySignature, TrySignatureMut}, - vc::Presentation, }; /// A `VerifiablePresentation` represents a `Presentation` with an associated diff --git a/identity_core/src/crypto/key_impl.rs b/identity-core/src/crypto/key_impl.rs similarity index 71% rename from identity_core/src/crypto/key_impl.rs rename to identity-core/src/crypto/key_impl.rs index 41083c89f5..5c69ca61a4 100644 --- a/identity_core/src/crypto/key_impl.rs +++ b/identity-core/src/crypto/key_impl.rs @@ -1,22 +1,9 @@ macro_rules! impl_bytes { ($ident:ident) => { + /// A cryptographic key. #[derive(Clone)] pub struct $ident(Vec); - impl $ident { - pub fn len(&self) -> usize { - self.0.len() - } - - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - - pub fn to_hex(&self) -> String { - $crate::utils::encode_hex(self) - } - } - impl From> for $ident { fn from(other: Vec) -> $ident { Self(other) @@ -44,13 +31,13 @@ macro_rules! impl_bytes { impl ::core::fmt::Debug for $ident { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - write!(f, "{:?}", self.to_hex()) + f.write_str(stringify!($ident)) } } impl ::core::fmt::Display for $ident { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - write!(f, "{}", self.to_hex()) + f.write_str(stringify!($ident)) } } }; diff --git a/identity_core/src/crypto/key_pair.rs b/identity-core/src/crypto/key_pair.rs similarity index 80% rename from identity_core/src/crypto/key_pair.rs rename to identity-core/src/crypto/key_pair.rs index 78de10b03e..0fdf18abeb 100644 --- a/identity_core/src/crypto/key_pair.rs +++ b/identity-core/src/crypto/key_pair.rs @@ -7,17 +7,17 @@ use crate::crypto::{PublicKey, SecretKey}; pub struct KeyPair(PublicKey, SecretKey); impl KeyPair { - /// Creates a new `KeyPair` from the given keys. + /// Creates a new [`KeyPair`] from the given keys. pub const fn new(public: PublicKey, secret: SecretKey) -> Self { Self(public, secret) } - /// Returns a reference to the `PublicKey` object. + /// Returns a reference to the [`PublicKey`] object. pub const fn public(&self) -> &PublicKey { &self.0 } - /// Returns a reference to the `SecretKey` object. + /// Returns a reference to the [`SecretKey`] object. pub const fn secret(&self) -> &SecretKey { &self.1 } diff --git a/identity_core/src/crypto/mod.rs b/identity-core/src/crypto/mod.rs similarity index 71% rename from identity_core/src/crypto/mod.rs rename to identity-core/src/crypto/mod.rs index 31bd42a33d..8f0cac8916 100644 --- a/identity_core/src/crypto/mod.rs +++ b/identity-core/src/crypto/mod.rs @@ -1,3 +1,5 @@ +//! Cryptographic Utilities + mod key_impl; mod key_pair; diff --git a/identity_core/src/error.rs b/identity-core/src/error.rs similarity index 50% rename from identity_core/src/error.rs rename to identity-core/src/error.rs index 0d41f2debc..5749615cb5 100644 --- a/identity_core/src/error.rs +++ b/identity-core/src/error.rs @@ -1,35 +1,45 @@ -/// The main crate result type derived from the `anyhow::Result` type. -pub type Result = anyhow::Result; +//! Errors that may occur when Self-sovereign Identity goes wrong. -/// The main crate Error type; uses `thiserror`. +/// Alias for a `Result` with the error type [`Error`]. +pub type Result = ::core::result::Result; + +/// This type represents all possible errors that can occur in the library. #[derive(Debug, thiserror::Error)] pub enum Error { + /// Caused by a failure to encode Rust types as JSON. #[error("Failed to encode JSON: {0}")] EncodeJSON(serde_json::Error), + /// Caused by a failure to decode Rust types from JSON. #[error("Failed to decode JSON: {0}")] DecodeJSON(serde_json::Error), - #[error("Failed to decode base16 data: {0}")] - DecodeBase16(#[from] hex::FromHexError), + /// Caused by a failure to decode base58-encoded data. #[error("Failed to decode base58 data: {0}")] DecodeBase58(#[from] bs58::decode::Error), - #[error("Failed to decode base64 data: {0}")] - DecodeBase64(#[from] base64::DecodeError), + /// Caused by attempting to perform an invalid `DID` operation. #[error("Invalid DID: {0}")] InvalidDID(#[from] did_url::Error), + /// Caused by attempting to perform an invalid DID `Document` operation. #[error("Invalid DID Document: {0}")] InvalidDocument(#[from] did_doc::Error), + /// Caused by attempting to perform an invalid `Diff` operation. #[error("Invalid Document Diff: {0}")] InvalidDiff(#[from] identity_diff::Error), + /// Caused by attempting to parse an invalid `Url`. #[error("Invalid Url: {0}")] InvalidUrl(#[from] did_doc::url::ParseError), + /// Caused by attempting to parse an invalid `Timestamp`. #[error("Invalid Timestamp: {0}")] InvalidTimestamp(#[from] chrono::ParseError), + /// Caused by attempting to perform an invalid `Credential` operation. #[error("Invalid Credential: {0}")] InvalidCredential(String), + /// Caused by attempting to perform an invalid `Presentation` operation. #[error("Invalid Presentation: {0}")] InvalidPresentation(String), + /// Caused by a failure to resolve a DID. #[error("DID Resolution Error: {0}")] ResolutionError(anyhow::Error), + /// Caused by a failure to dereference a DID URL. #[error("DID Dereference Error: {0}")] DereferenceError(anyhow::Error), } diff --git a/identity_core/src/lib.rs b/identity-core/src/lib.rs similarity index 56% rename from identity_core/src/lib.rs rename to identity-core/src/lib.rs index d9d7631252..b283bde351 100644 --- a/identity_core/src/lib.rs +++ b/identity-core/src/lib.rs @@ -1,3 +1,15 @@ +//! Identity Core + +#![warn( + missing_docs, + missing_crate_level_docs, + broken_intra_doc_links, + private_intra_doc_links, + private_doc_tests, + clippy::missing_safety_doc, + // clippy::missing_errors_doc +)] + #[macro_use] extern crate lazy_static; @@ -12,11 +24,11 @@ pub use serde_json::json; #[macro_use] pub mod common; pub mod convert; +pub mod credential; pub mod crypto; pub mod error; pub mod proof; pub mod resolver; pub mod utils; -pub mod vc; pub use error::{Error, Result}; diff --git a/identity_core/src/proof/jcsed25519signature2020.rs b/identity-core/src/proof/jcsed25519signature2020.rs similarity index 86% rename from identity_core/src/proof/jcsed25519signature2020.rs rename to identity-core/src/proof/jcsed25519signature2020.rs index 34b500f256..b4e036ec4e 100644 --- a/identity_core/src/proof/jcsed25519signature2020.rs +++ b/identity-core/src/proof/jcsed25519signature2020.rs @@ -3,15 +3,12 @@ use did_doc::{Error, Method, Result, Sign, SignatureData, SuiteName, Verify}; use ed25519_zebra::{Signature, SigningKey, VerificationKey, VerificationKeyBytes}; use rand::rngs::OsRng; use serde::Serialize; -use sha2::{ - digest::{consts::U32, generic_array::GenericArray}, - Digest as _, Sha256, -}; +use sha2::{digest::Output, Sha256}; use subtle::ConstantTimeEq; use crate::{ crypto::KeyPair, - utils::{decode_b58, encode_b58}, + utils::{decode_b58, encode_b58, jcs_sha256}, }; const SIGNATURE_NAME: &str = "JcsEd25519Signature2020"; @@ -19,12 +16,19 @@ const SIGNATURE_SIZE: usize = 64; const PUBLIC_KEY_BYTES: usize = 32; const SECRET_KEY_BYTES: usize = 32; +/// An implementation of the [JCS Ed25519 Signature 2020][SPEC1] signature suite +/// for [Linked Data Proofs][SPEC2]. +/// +/// [SPEC1]: https://identity.foundation/JcsEd25519Signature2020/ +/// [SPEC2]: https://w3c-ccg.github.io/ld-proofs/ #[derive(Clone, Copy, Debug)] pub struct JcsEd25519Signature2020; impl JcsEd25519Signature2020 { + /// The name of the signature suite. pub const NAME: &'static str = SIGNATURE_NAME; + /// Generates a new [`KeyPair`] appropriate for this signature suite. pub fn new_keypair() -> KeyPair { let secret: SigningKey = SigningKey::new(OsRng); let public: VerificationKey = (&secret).into(); @@ -33,6 +37,7 @@ impl JcsEd25519Signature2020 { KeyPair::new(public.as_ref().to_vec().into(), secret.as_ref().to_vec().into()) } + /// Signs the given `data` with `secret` and returns a digital signature. pub fn sign_data(data: &T, secret: &[u8]) -> Result where T: Serialize, @@ -44,6 +49,7 @@ impl JcsEd25519Signature2020 { .map(SignatureData::Signature) } + /// Verifies the authenticity of `data` using `signature` and `public`. pub fn verify_data(data: &T, signature: &SignatureData, public: &[u8]) -> Result<()> where T: Serialize, @@ -54,22 +60,20 @@ impl JcsEd25519Signature2020 { let signature: Vec = decode_b58(&signature).map_err(|_| Error::message("Invalid Signature Data"))?; let verified: Vec = ed25519_verify(&signature, public)?; - let digest: GenericArray = Self::normalize(data)?; + let digest: _ = Self::normalize(data)?; - if digest[..].ct_eq(&verified[..]).unwrap_u8() == 1 { + if digest[..].ct_eq(&verified[..]).into() { Ok(()) } else { Err(Error::message("Invalid Signature Digest")) } } - fn normalize(data: &T) -> Result> + fn normalize(data: &T) -> Result> where T: Serialize, { - serde_jcs::to_vec(data) - .map_err(|_| Error::message("Cannot Serialize Document")) - .map(|json| Sha256::digest(&json)) + jcs_sha256(data).map_err(|_| Error::message("Cannot Serialize Document")) } } @@ -196,25 +200,26 @@ mod tests { use crate::{ convert::FromJson as _, did_doc::{LdSuite, SignatureData, SignatureOptions, VerifiableDocument}, - utils::{decode_b58, decode_hex, encode_hex}, + utils::decode_b58, }; const PUBLIC_B58: &str = "6b23ioXQSAayuw13PGFMCAKqjgqoLTpeXWCy5WRfw28c"; const SECRET_B58: &str = "3qsrFcQqVuPpuGrRkU4wkQRvw1tc1C5EmEDPioS1GzQ2pLoThy5TYS2BsrwuzHYDnVqcYhMSpDhTXGst6H5ttFkG"; - const SIGNATURE_HELLO: &str = "0ccbeb905006a327b5112c7bfaa2a5918784209818a83750548b9965661b9d1d467c4078faacbaa36c1bd0f88673039adea51f5d216cd45cbf0e1528fb67f10a68656c6c6f"; + #[rustfmt::skip] + const SIGNATURE_HELLO: &[u8] = &[12, 203, 235, 144, 80, 6, 163, 39, 181, 17, 44, 123, 250, 162, 165, 145, 135, 132, 32, 152, 24, 168, 55, 80, 84, 139, 153, 101, 102, 27, 157, 29, 70, 124, 64, 120, 250, 172, 186, 163, 108, 27, 208, 248, 134, 115, 3, 154, 222, 165, 31, 93, 33, 108, 212, 92, 191, 14, 21, 40, 251, 103, 241, 10, 104, 101, 108, 108, 111]; + const SIGNATURE_DOCUMENT: &str = "piKnvB438vWsinW1dqq2EYRzcYFuR7Qm9X8t2S6TPPLDokLwcFBXnnERk6jmS8RXKTJnXKWw1Q9oNhYTwbR7vJkaJT8ZGgwDHNxa6mrMNsQsWkM4rg6EYY99xQko7FnpAMn"; #[test] fn test_ed25519_can_sign_and_verify() { let public: Vec = decode_b58(PUBLIC_B58).unwrap(); let secret: Vec = decode_b58(SECRET_B58).unwrap(); - let expected: Vec = decode_hex(SIGNATURE_HELLO).unwrap(); let signature = ed25519_sign(b"hello", &secret).unwrap(); - let verified = ed25519_verify(&expected, &public).unwrap(); + let verified = ed25519_verify(&signature, &public).unwrap(); - assert_eq!(encode_hex(&signature), SIGNATURE_HELLO); + assert_eq!(&signature, SIGNATURE_HELLO); assert_eq!(&verified, b"hello"); } diff --git a/identity-core/src/proof/mod.rs b/identity-core/src/proof/mod.rs new file mode 100644 index 0000000000..2df7f6edce --- /dev/null +++ b/identity-core/src/proof/mod.rs @@ -0,0 +1,6 @@ +//! Types and traits for helping ensure the authenticity and integrity of +//! DID Documents and Verifiable Credentials. + +mod jcsed25519signature2020; + +pub use self::jcsed25519signature2020::*; diff --git a/identity_core/src/resolver/dereference.rs b/identity-core/src/resolver/dereference.rs similarity index 69% rename from identity_core/src/resolver/dereference.rs rename to identity-core/src/resolver/dereference.rs index 4844c1e728..89b4a56e91 100644 --- a/identity_core/src/resolver/dereference.rs +++ b/identity-core/src/resolver/dereference.rs @@ -2,17 +2,24 @@ use serde::{Deserialize, Serialize}; use crate::resolver::{DocumentMetadata, ResolutionMetadata, Resource}; +/// The output returned from [DID URL dereferencing][SPEC]. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-url-dereferencing #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct Dereference { + /// Metadata regarding the base resolution process. #[serde(rename = "did-url-dereferencing-metadata")] pub metadata: ResolutionMetadata, + /// The output resource of a successful dereference. #[serde(rename = "content-stream", skip_serializing_if = "Option::is_none")] pub content: Option, + /// Content-specific metadata. #[serde(rename = "content-metadata", skip_serializing_if = "Option::is_none")] pub content_metadata: Option, } impl Dereference { + /// Creates a new [`Dereference`]. pub fn new() -> Self { Self { metadata: ResolutionMetadata::new(), diff --git a/identity_core/src/resolver/document_metadata.rs b/identity-core/src/resolver/document_metadata.rs similarity index 90% rename from identity_core/src/resolver/document_metadata.rs rename to identity-core/src/resolver/document_metadata.rs index 3c21d40991..cd2ec88f47 100644 --- a/identity_core/src/resolver/document_metadata.rs +++ b/identity-core/src/resolver/document_metadata.rs @@ -1,6 +1,7 @@ use crate::common::{Object, Timestamp}; use serde::{Deserialize, Serialize}; +/// Metadata associated with a resolved DID Document. #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct DocumentMetadata { /// The timestamp of the Create operation. @@ -19,6 +20,7 @@ pub struct DocumentMetadata { } impl DocumentMetadata { + /// Creates a new [`DocumentMetadata`]. pub fn new() -> Self { Self { created: None, diff --git a/identity_core/src/resolver/error_kind.rs b/identity-core/src/resolver/error_kind.rs similarity index 80% rename from identity_core/src/resolver/error_kind.rs rename to identity-core/src/resolver/error_kind.rs index 20b82409ff..1f74ccaee0 100644 --- a/identity_core/src/resolver/error_kind.rs +++ b/identity-core/src/resolver/error_kind.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; +/// Types of errors that be returned from a [DID resolution][SPEC] process. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-resolution #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] pub enum ErrorKind { /// The DID supplied to the DID resolution function does not conform to diff --git a/identity_core/src/resolver/impls.rs b/identity-core/src/resolver/impls.rs similarity index 96% rename from identity_core/src/resolver/impls.rs rename to identity-core/src/resolver/impls.rs index fc8db2074b..47aab89fa1 100644 --- a/identity_core/src/resolver/impls.rs +++ b/identity-core/src/resolver/impls.rs @@ -11,6 +11,11 @@ use crate::{ }, }; +/// Resolves a DID into a DID Document by using the "Read" operation of the DID method. +/// +/// See [DID Resolution][SPEC] for more information. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#did-resolution pub async fn resolve(did: &str, input: InputMetadata, method: R) -> Result where R: ResolverMethod, @@ -52,6 +57,11 @@ where Ok(context.finish()) } +/// Dereferences a DID URL into a primary or secondary resource. +/// +/// See [DID Url Dereferencing][SPEC] for more information. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#did-url-dereferencing pub async fn dereference(did: &str, input: InputMetadata, method: R) -> Result where R: ResolverMethod, diff --git a/identity_core/src/resolver/input_metadata.rs b/identity-core/src/resolver/input_metadata.rs similarity index 77% rename from identity_core/src/resolver/input_metadata.rs rename to identity-core/src/resolver/input_metadata.rs index 49cfdedd04..8f01b619ac 100644 --- a/identity_core/src/resolver/input_metadata.rs +++ b/identity-core/src/resolver/input_metadata.rs @@ -2,12 +2,18 @@ use serde::{Deserialize, Serialize}; use crate::common::Object; -pub const MIME_ANY: &str = "*/*"; +/// The content type of a JSON DID Document. pub const MIME_DID: &str = "application/did+json"; + +/// The content type of a JSON-LD DID Document. pub const MIME_DID_LD: &str = "application/did+ld+json"; // TODO: Support versioning via `version-id`/`version-time` // TODO: Support caching via `no-cache` + +/// Input options used to configure a [DID resolution][SPEC] process. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-resolution #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct InputMetadata { /// The MIME type of the preferred representation of the DID document. @@ -23,6 +29,7 @@ pub struct InputMetadata { } impl InputMetadata { + /// Creates a new [`InputMetadata`]. pub fn new() -> Self { Self { accept: None, diff --git a/identity_core/src/resolver/mod.rs b/identity-core/src/resolver/mod.rs similarity index 85% rename from identity_core/src/resolver/mod.rs rename to identity-core/src/resolver/mod.rs index 2a99c203ff..023a4afc7a 100644 --- a/identity_core/src/resolver/mod.rs +++ b/identity-core/src/resolver/mod.rs @@ -1,3 +1,5 @@ +//! Types and traits for supporting DID Document resolution. + mod dereference; mod document_metadata; mod error_kind; diff --git a/identity_core/src/resolver/resolution.rs b/identity-core/src/resolver/resolution.rs similarity index 72% rename from identity_core/src/resolver/resolution.rs rename to identity-core/src/resolver/resolution.rs index 4652222220..40dc35e546 100644 --- a/identity_core/src/resolver/resolution.rs +++ b/identity-core/src/resolver/resolution.rs @@ -3,17 +3,24 @@ use serde::{Deserialize, Serialize}; use crate::resolver::{DocumentMetadata, ResolutionMetadata}; +/// The output returned from [DID resolution][SPEC]. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-resolution #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct Resolution { + /// Resolution-specific metadata. #[serde(rename = "did-resolution-metadata")] pub metadata: ResolutionMetadata, + /// The DID Document of a successful resolution. #[serde(rename = "did-document", skip_serializing_if = "Option::is_none")] pub document: Option, + /// Document-specific metadata. #[serde(rename = "did-document-metadata", skip_serializing_if = "Option::is_none")] pub document_metadata: Option, } impl Resolution { + /// Creates a new [`Resolution`]. pub fn new() -> Self { Self { metadata: ResolutionMetadata::new(), diff --git a/identity_core/src/resolver/resolution_metadata.rs b/identity-core/src/resolver/resolution_metadata.rs similarity index 88% rename from identity_core/src/resolver/resolution_metadata.rs rename to identity-core/src/resolver/resolution_metadata.rs index dc829625e8..7d3b5a9065 100644 --- a/identity_core/src/resolver/resolution_metadata.rs +++ b/identity-core/src/resolver/resolution_metadata.rs @@ -4,6 +4,9 @@ use serde::{Deserialize, Serialize}; use crate::{common::Object, resolver::ErrorKind}; +/// Metadata associated with a [DID resolution][SPEC] process. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-resolution #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct ResolutionMetadata { /// The error code from the resolution process, if an error occurred. @@ -29,6 +32,7 @@ pub struct ResolutionMetadata { } impl ResolutionMetadata { + /// Creates a new [`ResolutionMetadata`]. pub fn new() -> Self { Self { error: None, diff --git a/identity_core/src/resolver/resource.rs b/identity-core/src/resolver/resource.rs similarity index 73% rename from identity_core/src/resolver/resource.rs rename to identity-core/src/resolver/resource.rs index 2302c6e2d9..d36720af38 100644 --- a/identity_core/src/resolver/resource.rs +++ b/identity-core/src/resolver/resource.rs @@ -2,9 +2,14 @@ use did_doc::{url::Url, DIDKey, Document, Method, MethodRef, Service}; use did_url::DID; use serde::{Deserialize, Serialize}; +/// A resource returned from a [DID URL dereferencing][SPEC] process. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-url-dereferencing #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum Resource { + /// A dereferenced primary resource. Primary(PrimaryResource), + /// A dereferenced secondary resource. Secondary(SecondaryResource), } @@ -20,10 +25,15 @@ impl From for Resource { } } +/// A primary resource returned from a [DID URL dereferencing][SPEC] process. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-url-dereferencing #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[serde(untagged)] pub enum PrimaryResource { + /// A dereferenced DID Document. Document(Document), + /// A dereferenced DID Document service endpoint. Service(Url), } @@ -39,12 +49,18 @@ impl From for PrimaryResource { } } +/// A secondary resource returned from a [DID URL dereferencing][SPEC] process. +/// +/// [SPEC]: https://www.w3.org/TR/did-core/#dfn-did-url-dereferencing #[allow(clippy::large_enum_variant)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[serde(untagged)] pub enum SecondaryResource { + /// A DID Document Method Id. VerificationDID(DID), + /// A DID Document Verification Method. VerificationKey(Method), + /// A DID Document Service. Service(Service), } diff --git a/identity_core/src/resolver/traits.rs b/identity-core/src/resolver/traits.rs similarity index 71% rename from identity_core/src/resolver/traits.rs rename to identity-core/src/resolver/traits.rs index e3248cb0d3..554c4e596b 100644 --- a/identity_core/src/resolver/traits.rs +++ b/identity-core/src/resolver/traits.rs @@ -8,16 +8,22 @@ use crate::{ resolver::{DocumentMetadata, InputMetadata}, }; +/// A resolved [`Document`] and associated [`DocumentMetadata`]. #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct MetaDocument { + /// A resolved DID Document. pub data: Document, + /// Information regarding the associated Documents resolution process. pub meta: DocumentMetadata, } +/// A trait for generic DID Resolvers. #[async_trait(?Send)] pub trait ResolverMethod { + /// Returns `true` if the given `did` is supported by this DID Resolver. fn is_supported(&self, did: &DID) -> bool; + /// Performs the "Read" operation of the DID method. async fn read(&self, did: &DID, input: InputMetadata) -> Result>; } diff --git a/identity-core/src/utils/base58.rs b/identity-core/src/utils/base58.rs new file mode 100644 index 0000000000..6701505bf8 --- /dev/null +++ b/identity-core/src/utils/base58.rs @@ -0,0 +1,20 @@ +use crate::error::{Error, Result}; + +/// Decodes the given `data` as base58-btc. +pub fn decode_b58(data: &T) -> Result> +where + T: AsRef<[u8]> + ?Sized, +{ + bs58::decode(data) + .with_alphabet(bs58::Alphabet::BITCOIN) + .into_vec() + .map_err(Error::DecodeBase58) +} + +/// Encodes the given `data` as base58-btc. +pub fn encode_b58(data: &T) -> String +where + T: AsRef<[u8]> + ?Sized, +{ + bs58::encode(data).with_alphabet(bs58::Alphabet::BITCOIN).into_string() +} diff --git a/identity-core/src/utils/jcs_sha256.rs b/identity-core/src/utils/jcs_sha256.rs new file mode 100644 index 0000000000..24f8d01092 --- /dev/null +++ b/identity-core/src/utils/jcs_sha256.rs @@ -0,0 +1,12 @@ +use sha2::{digest::Output, Digest, Sha256}; + +use crate::{convert::ToJson, error::Result}; + +/// Returns the given `data` serialized using JSON Canonicalization Scheme and +/// hashed using SHA-256. +pub fn jcs_sha256(data: &T) -> Result> +where + T: ToJson, +{ + data.to_jcs().map(|json| Sha256::digest(&json)) +} diff --git a/identity-core/src/utils/mod.rs b/identity-core/src/utils/mod.rs new file mode 100644 index 0000000000..6c3470eced --- /dev/null +++ b/identity-core/src/utils/mod.rs @@ -0,0 +1,6 @@ +//! Misc. utility functions. + +mod base58; +mod jcs_sha256; + +pub use self::{base58::*, jcs_sha256::*}; diff --git a/identity_core/tests/fixtures/vc/credential-1.json b/identity-core/tests/fixtures/vc/credential-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-1.json rename to identity-core/tests/fixtures/vc/credential-1.json diff --git a/identity_core/tests/fixtures/vc/credential-10.json b/identity-core/tests/fixtures/vc/credential-10.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-10.json rename to identity-core/tests/fixtures/vc/credential-10.json diff --git a/identity_core/tests/fixtures/vc/credential-11.json b/identity-core/tests/fixtures/vc/credential-11.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-11.json rename to identity-core/tests/fixtures/vc/credential-11.json diff --git a/identity_core/tests/fixtures/vc/credential-12.json b/identity-core/tests/fixtures/vc/credential-12.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-12.json rename to identity-core/tests/fixtures/vc/credential-12.json diff --git a/identity_core/tests/fixtures/vc/credential-2.json b/identity-core/tests/fixtures/vc/credential-2.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-2.json rename to identity-core/tests/fixtures/vc/credential-2.json diff --git a/identity_core/tests/fixtures/vc/credential-3.json b/identity-core/tests/fixtures/vc/credential-3.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-3.json rename to identity-core/tests/fixtures/vc/credential-3.json diff --git a/identity_core/tests/fixtures/vc/credential-4.json b/identity-core/tests/fixtures/vc/credential-4.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-4.json rename to identity-core/tests/fixtures/vc/credential-4.json diff --git a/identity_core/tests/fixtures/vc/credential-5.json b/identity-core/tests/fixtures/vc/credential-5.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-5.json rename to identity-core/tests/fixtures/vc/credential-5.json diff --git a/identity_core/tests/fixtures/vc/credential-6.json b/identity-core/tests/fixtures/vc/credential-6.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-6.json rename to identity-core/tests/fixtures/vc/credential-6.json diff --git a/identity_core/tests/fixtures/vc/credential-7.json b/identity-core/tests/fixtures/vc/credential-7.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-7.json rename to identity-core/tests/fixtures/vc/credential-7.json diff --git a/identity_core/tests/fixtures/vc/credential-8.json b/identity-core/tests/fixtures/vc/credential-8.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-8.json rename to identity-core/tests/fixtures/vc/credential-8.json diff --git a/identity_core/tests/fixtures/vc/credential-9.json b/identity-core/tests/fixtures/vc/credential-9.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-9.json rename to identity-core/tests/fixtures/vc/credential-9.json diff --git a/identity_core/tests/fixtures/vc/credential-schema-1.json b/identity-core/tests/fixtures/vc/credential-schema-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-schema-1.json rename to identity-core/tests/fixtures/vc/credential-schema-1.json diff --git a/identity_core/tests/fixtures/vc/credential-schema-2.json b/identity-core/tests/fixtures/vc/credential-schema-2.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-schema-2.json rename to identity-core/tests/fixtures/vc/credential-schema-2.json diff --git a/identity_core/tests/fixtures/vc/credential-schema-3.json b/identity-core/tests/fixtures/vc/credential-schema-3.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-schema-3.json rename to identity-core/tests/fixtures/vc/credential-schema-3.json diff --git a/identity_core/tests/fixtures/vc/credential-status-1.json b/identity-core/tests/fixtures/vc/credential-status-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-status-1.json rename to identity-core/tests/fixtures/vc/credential-status-1.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-1.json b/identity-core/tests/fixtures/vc/credential-subject-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-1.json rename to identity-core/tests/fixtures/vc/credential-subject-1.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-10.json b/identity-core/tests/fixtures/vc/credential-subject-10.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-10.json rename to identity-core/tests/fixtures/vc/credential-subject-10.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-2.json b/identity-core/tests/fixtures/vc/credential-subject-2.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-2.json rename to identity-core/tests/fixtures/vc/credential-subject-2.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-3.json b/identity-core/tests/fixtures/vc/credential-subject-3.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-3.json rename to identity-core/tests/fixtures/vc/credential-subject-3.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-4.json b/identity-core/tests/fixtures/vc/credential-subject-4.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-4.json rename to identity-core/tests/fixtures/vc/credential-subject-4.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-5.json b/identity-core/tests/fixtures/vc/credential-subject-5.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-5.json rename to identity-core/tests/fixtures/vc/credential-subject-5.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-6.json b/identity-core/tests/fixtures/vc/credential-subject-6.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-6.json rename to identity-core/tests/fixtures/vc/credential-subject-6.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-7.json b/identity-core/tests/fixtures/vc/credential-subject-7.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-7.json rename to identity-core/tests/fixtures/vc/credential-subject-7.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-8.json b/identity-core/tests/fixtures/vc/credential-subject-8.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-8.json rename to identity-core/tests/fixtures/vc/credential-subject-8.json diff --git a/identity_core/tests/fixtures/vc/credential-subject-9.json b/identity-core/tests/fixtures/vc/credential-subject-9.json similarity index 100% rename from identity_core/tests/fixtures/vc/credential-subject-9.json rename to identity-core/tests/fixtures/vc/credential-subject-9.json diff --git a/identity_core/tests/fixtures/vc/evidence-1.json b/identity-core/tests/fixtures/vc/evidence-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/evidence-1.json rename to identity-core/tests/fixtures/vc/evidence-1.json diff --git a/identity_core/tests/fixtures/vc/evidence-2.json b/identity-core/tests/fixtures/vc/evidence-2.json similarity index 100% rename from identity_core/tests/fixtures/vc/evidence-2.json rename to identity-core/tests/fixtures/vc/evidence-2.json diff --git a/identity_core/tests/fixtures/vc/issuer-1.json b/identity-core/tests/fixtures/vc/issuer-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/issuer-1.json rename to identity-core/tests/fixtures/vc/issuer-1.json diff --git a/identity_core/tests/fixtures/vc/issuer-2.json b/identity-core/tests/fixtures/vc/issuer-2.json similarity index 100% rename from identity_core/tests/fixtures/vc/issuer-2.json rename to identity-core/tests/fixtures/vc/issuer-2.json diff --git a/identity_core/tests/fixtures/vc/presentation-1.json b/identity-core/tests/fixtures/vc/presentation-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/presentation-1.json rename to identity-core/tests/fixtures/vc/presentation-1.json diff --git a/identity_core/tests/fixtures/vc/refresh-service-1.json b/identity-core/tests/fixtures/vc/refresh-service-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/refresh-service-1.json rename to identity-core/tests/fixtures/vc/refresh-service-1.json diff --git a/identity_core/tests/fixtures/vc/terms-of-use-1.json b/identity-core/tests/fixtures/vc/terms-of-use-1.json similarity index 100% rename from identity_core/tests/fixtures/vc/terms-of-use-1.json rename to identity-core/tests/fixtures/vc/terms-of-use-1.json diff --git a/identity_core/tests/fixtures/vc/terms-of-use-2.json b/identity-core/tests/fixtures/vc/terms-of-use-2.json similarity index 100% rename from identity_core/tests/fixtures/vc/terms-of-use-2.json rename to identity-core/tests/fixtures/vc/terms-of-use-2.json diff --git a/identity_diff/Cargo.toml b/identity-diff/Cargo.toml similarity index 62% rename from identity_diff/Cargo.toml rename to identity-diff/Cargo.toml index 651b3ca7f4..ca3c92e6db 100644 --- a/identity_diff/Cargo.toml +++ b/identity-diff/Cargo.toml @@ -1,32 +1,23 @@ [package] -name = "identity_diff" +name = "identity-diff" version = "0.1.0" authors = ["IOTA Identity"] edition = "2018" -description = "A library for diffing Rust Structs" +description = "The `Diff` trait for the identity-rs library." readme = "../README.md" repository = "https://github.com/iotaledger/identity.rs" license = "Apache-2.0" keywords = ["iota", "tangle", "identity"] homepage = "https://www.iota.org" -[features] -default = ["serde_value"] -serde_value = ["serde_json"] -diff_derive = ["identity_derive"] - [dependencies] -serde = { version = "1.0", features = [ "derive" ] } -serde_json = {version = "1.0", optional = true } - -# error handling -anyhow = "1.0" -thiserror = "1.0" - -identity_derive = {version = "0.1.0", path = "../identity_derive", optional = true} - +anyhow = { version = "1.0" } did_doc = { git = "https://github.com/l1h3r/did_doc", rev = "bb8bda8f6d39451b08e3cc198f956c212a3b87f8", default-features = false, features = ["std"] } did_url = { version = "0.1", default-features = false, features = ["std", "serde"] } +identity-derive = { version = "=0.1.0", path = "derive" } +serde = { version = "1.0", features = [ "derive" ] } +serde_json = { version = "1.0" } +thiserror = { version = "1.0" } [dev-dependencies] serde_json = "1.0" diff --git a/identity_derive/Cargo.toml b/identity-diff/derive/Cargo.toml similarity index 52% rename from identity_derive/Cargo.toml rename to identity-diff/derive/Cargo.toml index 45b13acc5e..e28ec6b773 100644 --- a/identity_derive/Cargo.toml +++ b/identity-diff/derive/Cargo.toml @@ -1,27 +1,21 @@ [package] -name = "identity_derive" +name = "identity-derive" version = "0.1.0" authors = ["IOTA Identity"] edition = "2018" -description = "A proc macro library for Diffing Structures" +description = "Derive `Diff` support for the identity-rs library." readme = "../README.md" repository = "https://github.com/iotaledger/identity.rs" license = "Apache-2.0" keywords = ["iota", "tangle", "identity"] homepage = "https://www.iota.org" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [lib] name = "identity_derive" proc-macro = true [dependencies] +proc-macro2 = { version = "1.0" } +quote = { version = "1.0" } +serde = { version = "1.0" } syn = { version = "1.0", features = ["extra-traits", "parsing", "derive"] } -proc-macro2 = "1.0" -quote = "1.0" -serde = "1.0" - -[dev-dependencies] -identity_diff = {path = "../identity_diff", version = "0.1.0", features = ["diff_derive"]} -serde_json = "1.0" \ No newline at end of file diff --git a/identity_derive/src/impls.rs b/identity-diff/derive/src/impls.rs similarity index 100% rename from identity_derive/src/impls.rs rename to identity-diff/derive/src/impls.rs diff --git a/identity_derive/src/impls/enums.rs b/identity-diff/derive/src/impls/enums.rs similarity index 100% rename from identity_derive/src/impls/enums.rs rename to identity-diff/derive/src/impls/enums.rs diff --git a/identity_derive/src/impls/structs.rs b/identity-diff/derive/src/impls/structs.rs similarity index 100% rename from identity_derive/src/impls/structs.rs rename to identity-diff/derive/src/impls/structs.rs diff --git a/identity_derive/src/lib.rs b/identity-diff/derive/src/lib.rs similarity index 100% rename from identity_derive/src/lib.rs rename to identity-diff/derive/src/lib.rs diff --git a/identity_derive/src/model.rs b/identity-diff/derive/src/model.rs similarity index 100% rename from identity_derive/src/model.rs rename to identity-diff/derive/src/model.rs diff --git a/identity_derive/src/utils.rs b/identity-diff/derive/src/utils.rs similarity index 100% rename from identity_derive/src/utils.rs rename to identity-diff/derive/src/utils.rs diff --git a/identity_diff/src/did_doc.rs b/identity-diff/src/did_doc.rs similarity index 100% rename from identity_diff/src/did_doc.rs rename to identity-diff/src/did_doc.rs diff --git a/identity_diff/src/error.rs b/identity-diff/src/error.rs similarity index 100% rename from identity_diff/src/error.rs rename to identity-diff/src/error.rs diff --git a/identity_diff/src/hashmap.rs b/identity-diff/src/hashmap.rs similarity index 100% rename from identity_diff/src/hashmap.rs rename to identity-diff/src/hashmap.rs diff --git a/identity_diff/src/hashset.rs b/identity-diff/src/hashset.rs similarity index 100% rename from identity_diff/src/hashset.rs rename to identity-diff/src/hashset.rs diff --git a/identity_diff/src/lib.rs b/identity-diff/src/lib.rs similarity index 78% rename from identity_diff/src/lib.rs rename to identity-diff/src/lib.rs index 31a05de818..f166d46dc4 100644 --- a/identity_diff/src/lib.rs +++ b/identity-diff/src/lib.rs @@ -12,19 +12,11 @@ mod macros; pub mod option; pub mod string; mod traits; -#[cfg(feature = "serde_value")] mod value; pub mod vec; pub use error::{Error, Result}; pub use traits::Diff; -/// feature `diff_derive` imports `identity_derive` with this crate. -#[cfg(feature = "diff_derive")] -#[allow(unused_imports)] -#[macro_use] -extern crate identity_derive; - -#[cfg(feature = "diff_derive")] #[doc(hidden)] pub use identity_derive::*; diff --git a/identity_diff/src/macros.rs b/identity-diff/src/macros.rs similarity index 100% rename from identity_diff/src/macros.rs rename to identity-diff/src/macros.rs diff --git a/identity_diff/src/option.rs b/identity-diff/src/option.rs similarity index 100% rename from identity_diff/src/option.rs rename to identity-diff/src/option.rs diff --git a/identity_diff/src/string.rs b/identity-diff/src/string.rs similarity index 100% rename from identity_diff/src/string.rs rename to identity-diff/src/string.rs diff --git a/identity_diff/src/traits.rs b/identity-diff/src/traits.rs similarity index 100% rename from identity_diff/src/traits.rs rename to identity-diff/src/traits.rs diff --git a/identity_diff/src/value.rs b/identity-diff/src/value.rs similarity index 100% rename from identity_diff/src/value.rs rename to identity-diff/src/value.rs diff --git a/identity_diff/src/vec.rs b/identity-diff/src/vec.rs similarity index 100% rename from identity_diff/src/vec.rs rename to identity-diff/src/vec.rs diff --git a/identity_derive/tests/derive_enum_test.rs b/identity-diff/tests/derive_enum_test.rs similarity index 100% rename from identity_derive/tests/derive_enum_test.rs rename to identity-diff/tests/derive_enum_test.rs diff --git a/identity_derive/tests/derive_struct_test.rs b/identity-diff/tests/derive_struct_test.rs similarity index 100% rename from identity_derive/tests/derive_struct_test.rs rename to identity-diff/tests/derive_struct_test.rs diff --git a/identity_iota/Cargo.toml b/identity-iota/Cargo.toml similarity index 59% rename from identity_iota/Cargo.toml rename to identity-iota/Cargo.toml index f6b4d8d286..f127f109b4 100644 --- a/identity_iota/Cargo.toml +++ b/identity-iota/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "identity_iota" +name = "identity-iota" version = "0.1.0" authors = ["IOTA Identity"] edition = "2018" -description = "A DID to ledger intergration library for IOTA" +description = "An IOTA Tangle intergration for the identity-rs library." readme = "../README.md" repository = "https://github.com/iotaledger/identity.rs" license = "Apache-2.0" @@ -13,20 +13,12 @@ homepage = "https://www.iota.org" [dependencies] anyhow = { version = "1.0", default-features = false, features = ["std"] } async-trait = { version = "0.1", default-features = false } +identity-core = { version = "=0.1.0", path = "../identity-core" } iota-constants = { version = "0.2", default-features = false } iota-conversion = { version = "0.5", default-features = false } -# iota-core = { git = "https://github.com/iotaledger/iota.rs", branch = "dev" } -iota-core = { git = "https://github.com/Thoralf-M/iota.rs", branch = "works" } +iota-core = { git = "https://github.com/Thoralf-M/iota.rs", rev = "d7c8c64fc3ac2340f0148708a916c245f42fd454" } lazy_static = { version = "1.4", default-features = false } log = { version = "0.4", default-features = false } multihash = { version = "0.11", default-features = false } -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", default-features = false, features = ["std", "derive"] } thiserror = { version = "1.0", default-features = false } - -identity_core = { path = "../identity_core" } - -[dev-dependencies] -smol-potat = { version = "0.3.3" } -smol = { version = "0.1.18", features = ["tokio02"] } -hex = "0.4.2" -identity_diff = { path = "../identity_diff" } diff --git a/identity_iota/src/chain/auth.rs b/identity-iota/src/chain/auth.rs similarity index 100% rename from identity_iota/src/chain/auth.rs rename to identity-iota/src/chain/auth.rs diff --git a/identity_iota/src/chain/diff.rs b/identity-iota/src/chain/diff.rs similarity index 100% rename from identity_iota/src/chain/diff.rs rename to identity-iota/src/chain/diff.rs diff --git a/identity_iota/src/chain/document.rs b/identity-iota/src/chain/document.rs similarity index 100% rename from identity_iota/src/chain/document.rs rename to identity-iota/src/chain/document.rs diff --git a/identity_iota/src/chain/mod.rs b/identity-iota/src/chain/mod.rs similarity index 100% rename from identity_iota/src/chain/mod.rs rename to identity-iota/src/chain/mod.rs diff --git a/identity_iota/src/client/client.rs b/identity-iota/src/client/client.rs similarity index 100% rename from identity_iota/src/client/client.rs rename to identity-iota/src/client/client.rs diff --git a/identity_iota/src/client/client_builder.rs b/identity-iota/src/client/client_builder.rs similarity index 100% rename from identity_iota/src/client/client_builder.rs rename to identity-iota/src/client/client_builder.rs diff --git a/identity_iota/src/client/mod.rs b/identity-iota/src/client/mod.rs similarity index 100% rename from identity_iota/src/client/mod.rs rename to identity-iota/src/client/mod.rs diff --git a/identity_iota/src/client/network.rs b/identity-iota/src/client/network.rs similarity index 100% rename from identity_iota/src/client/network.rs rename to identity-iota/src/client/network.rs diff --git a/identity_iota/src/client/resolver.rs b/identity-iota/src/client/resolver.rs similarity index 100% rename from identity_iota/src/client/resolver.rs rename to identity-iota/src/client/resolver.rs diff --git a/identity_iota/src/client/txn_printer.rs b/identity-iota/src/client/txn_printer.rs similarity index 100% rename from identity_iota/src/client/txn_printer.rs rename to identity-iota/src/client/txn_printer.rs diff --git a/identity_iota/src/vc/mod.rs b/identity-iota/src/credential/mod.rs similarity index 100% rename from identity_iota/src/vc/mod.rs rename to identity-iota/src/credential/mod.rs diff --git a/identity_iota/src/vc/validator.rs b/identity-iota/src/credential/validator.rs similarity index 98% rename from identity_iota/src/vc/validator.rs rename to identity-iota/src/credential/validator.rs index e03f172306..6478f6a075 100644 --- a/identity_iota/src/vc/validator.rs +++ b/identity-iota/src/credential/validator.rs @@ -1,8 +1,8 @@ use identity_core::{ common::Object, convert::FromJson as _, + credential::{VerifiableCredential, VerifiablePresentation}, error::Error, - vc::{VerifiableCredential, VerifiablePresentation}, }; use serde::{de::DeserializeOwned, Serialize}; use std::collections::BTreeMap; diff --git a/identity_iota/src/did/did.rs b/identity-iota/src/did/did.rs similarity index 100% rename from identity_iota/src/did/did.rs rename to identity-iota/src/did/did.rs diff --git a/identity_iota/src/did/did_segments.rs b/identity-iota/src/did/did_segments.rs similarity index 100% rename from identity_iota/src/did/did_segments.rs rename to identity-iota/src/did/did_segments.rs diff --git a/identity_iota/src/did/document.rs b/identity-iota/src/did/document.rs similarity index 100% rename from identity_iota/src/did/document.rs rename to identity-iota/src/did/document.rs diff --git a/identity_iota/src/did/document_builder.rs b/identity-iota/src/did/document_builder.rs similarity index 100% rename from identity_iota/src/did/document_builder.rs rename to identity-iota/src/did/document_builder.rs diff --git a/identity_iota/src/did/document_diff.rs b/identity-iota/src/did/document_diff.rs similarity index 100% rename from identity_iota/src/did/document_diff.rs rename to identity-iota/src/did/document_diff.rs diff --git a/identity_iota/src/did/document_properties.rs b/identity-iota/src/did/document_properties.rs similarity index 100% rename from identity_iota/src/did/document_properties.rs rename to identity-iota/src/did/document_properties.rs diff --git a/identity_iota/src/did/mod.rs b/identity-iota/src/did/mod.rs similarity index 100% rename from identity_iota/src/did/mod.rs rename to identity-iota/src/did/mod.rs diff --git a/identity_iota/src/error.rs b/identity-iota/src/error.rs similarity index 100% rename from identity_iota/src/error.rs rename to identity-iota/src/error.rs diff --git a/identity_iota/src/lib.rs b/identity-iota/src/lib.rs similarity index 58% rename from identity_iota/src/lib.rs rename to identity-iota/src/lib.rs index ef9a209a96..59f6af8e78 100644 --- a/identity_iota/src/lib.rs +++ b/identity-iota/src/lib.rs @@ -1,3 +1,13 @@ +// #![warn( +// missing_docs, +// missing_crate_level_docs, +// broken_intra_doc_links, +// private_intra_doc_links, +// private_doc_tests, +// clippy::missing_safety_doc, +// clippy::missing_errors_doc, +// )] + #[macro_use] extern crate lazy_static; @@ -9,11 +19,11 @@ extern crate serde; pub mod chain; pub mod client; +pub mod credential; pub mod did; pub mod error; pub mod tangle; pub mod utils; -pub mod vc; /// Re-export `identity_core::crypto`; in the future this will be `crypto.rs`. pub mod crypto { diff --git a/identity_iota/src/tangle/message.rs b/identity-iota/src/tangle/message.rs similarity index 100% rename from identity_iota/src/tangle/message.rs rename to identity-iota/src/tangle/message.rs diff --git a/identity_iota/src/tangle/message_id.rs b/identity-iota/src/tangle/message_id.rs similarity index 100% rename from identity_iota/src/tangle/message_id.rs rename to identity-iota/src/tangle/message_id.rs diff --git a/identity_iota/src/tangle/message_index.rs b/identity-iota/src/tangle/message_index.rs similarity index 100% rename from identity_iota/src/tangle/message_index.rs rename to identity-iota/src/tangle/message_index.rs diff --git a/identity_iota/src/tangle/mod.rs b/identity-iota/src/tangle/mod.rs similarity index 100% rename from identity_iota/src/tangle/mod.rs rename to identity-iota/src/tangle/mod.rs diff --git a/identity_iota/src/tangle/traits.rs b/identity-iota/src/tangle/traits.rs similarity index 100% rename from identity_iota/src/tangle/traits.rs rename to identity-iota/src/tangle/traits.rs diff --git a/identity_iota/src/utils.rs b/identity-iota/src/utils.rs similarity index 100% rename from identity_iota/src/utils.rs rename to identity-iota/src/utils.rs diff --git a/identity_core/src/convert/mod.rs b/identity_core/src/convert/mod.rs deleted file mode 100644 index f91ea8bcbc..0000000000 --- a/identity_core/src/convert/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod as_json; -mod serde_into; - -pub use self::{as_json::*, serde_into::*}; diff --git a/identity_core/src/convert/serde_into.rs b/identity_core/src/convert/serde_into.rs deleted file mode 100644 index d90c5f89b7..0000000000 --- a/identity_core/src/convert/serde_into.rs +++ /dev/null @@ -1,17 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_json::{from_value, to_value}; - -use crate::error::{Error, Result}; - -pub trait SerdeInto: Serialize + Sized { - fn serde_into(&self) -> Result - where - T: for<'de> Deserialize<'de>, - { - to_value(self) - .map_err(Error::EncodeJSON) - .and_then(|value| from_value(value).map_err(Error::DecodeJSON)) - } -} - -impl SerdeInto for T where T: Serialize + Sized {} diff --git a/identity_core/src/proof/mod.rs b/identity_core/src/proof/mod.rs deleted file mode 100644 index 87373ff1c3..0000000000 --- a/identity_core/src/proof/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod jcsed25519signature2020; - -pub use self::jcsed25519signature2020::*; diff --git a/identity_core/src/utils.rs b/identity_core/src/utils.rs deleted file mode 100644 index 4a9eddab76..0000000000 --- a/identity_core/src/utils.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::error::{Error, Result}; - -pub fn decode_b58(data: &(impl AsRef + ?Sized)) -> Result> { - bs58::decode(data.as_ref()).into_vec().map_err(Error::DecodeBase58) -} - -pub fn encode_b58(data: &(impl AsRef<[u8]> + ?Sized)) -> String { - bs58::encode(data.as_ref()).into_string() -} - -pub fn decode_hex(data: &(impl AsRef + ?Sized)) -> Result> { - hex::decode(data.as_ref()).map_err(Error::DecodeBase16) -} - -pub fn encode_hex(data: &(impl AsRef<[u8]> + ?Sized)) -> String { - hex::encode(data.as_ref()) -} - -pub fn decode_b64(data: &(impl AsRef + ?Sized)) -> Result> { - base64::decode_config(data.as_ref(), base64::URL_SAFE_NO_PAD).map_err(Error::DecodeBase64) -} - -pub fn encode_b64(data: &(impl AsRef<[u8]> + ?Sized)) -> String { - base64::encode_config(data.as_ref(), base64::URL_SAFE_NO_PAD) -}