Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

did:ion (Sidetree) resolver and client #379

Merged
merged 9 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ exclude = ["json-ld-api/*", "json-ld-normalization/*"]

[features]
default = ["ring"]
http-did = ["hyper", "hyper-tls", "http", "percent-encoding", "tokio"]
libsecp256k1 = ["secp256k1"] # backward compatibility
http-did = ["http", "percent-encoding"]
libsecp256k1 = ["secp256k1"] # backward compatibility
secp256k1 = ["k256", "rand", "k256/keccak256"]
secp256r1 = ["p256", "rand"]
aleosig = ["rand", "blake2", "snarkvm-dpc", "snarkvm-algorithms", "snarkvm-curves", "snarkvm-utilities", "snarkvm-parameters"]
Expand Down Expand Up @@ -57,13 +57,6 @@ lazy_static = "1.4"
combination = "0.1"
sha2 = { version = "0.9", optional = true }
sha2_old = { package = "sha2", version = "0.8" }
hyper = { version = "0.14", optional = true, features = [
"server",
"client",
"http1",
"stream",
] }
hyper-tls = { version = "0.5", optional = true }
http = { version = "0.2", optional = true }
hex = "0.4"
serde_urlencoded = "0.7"
Expand All @@ -87,6 +80,7 @@ flate2 = "1.0"
bitvec = "0.20"
clear_on_drop = "0.2.4"
url = { version = "2.2", features = ["serde"] }
anyhow = "1.0"
rand_xorshift = "0.3"
bech32 = "0.8"
snarkvm-dpc = { version = "0.7.9", optional = true }
Expand All @@ -112,6 +106,7 @@ members = [
"did-sol",
"did-pkh",
"did-onion",
"did-ion",
"did-webkey",
"vc-test",
"did-test",
Expand All @@ -123,6 +118,7 @@ uuid = { version = "0.8", features = ["v4", "serde"] }
difference = "2.0"
did-method-key = { path = "./did-key" }
tokio = { version = "1.0", features = ["macros"] }
hyper = { version = "0.14", features = ["server", "http1", "stream"] }

[package.metadata.docs.rs]
features = ["secp256r1", "secp256k1", "ripemd-160", "http-did"]
Expand Down
34 changes: 34 additions & 0 deletions did-ion/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "did-ion"
version = "0.1.0"
authors = ["Spruce Systems, Inc."]
edition = "2021"
license = "Apache-2.0"
keywords = ["ssi", "did"]
categories = ["web-programming::http-client"]
description = "did:ion DID method implementation, using the ssi crate and ION/Sidetree REST API"
repository = "https://github.com/spruceid/ssi/"
homepage = "https://github.com/spruceid/ssi/tree/main/did-ion/"
documentation = "https://docs.rs/did-ion/"

[features]

[dependencies]
ssi = { version = "0.3", path = "../", default-features = false, features = ["http-did", "secp256k1"] }
async-trait = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_jcs = "0.1"
anyhow = "1.0"
thiserror = "1.0"
base64 = "0.12"
sha2 = "0.10"
json-patch = "0.2.6"
reqwest = { version = "0.11", features = ["json"] }

[target.'cfg(target_os = "android")'.dependencies.reqwest]
version = "0.11"
features = ["json", "native-tls-vendored"]

[dev-dependencies]
lazy_static = "1.4"
17 changes: 17 additions & 0 deletions did-ion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# did-ion

Rust implementation of the [did:ion][] [DID Method][], based on the [ssi][] library.

## Requirements

An ION node is needed, that is a [Sidetree REST API][] provider. The URL for
the ION/Sidetree node is to be stored in config TBD.

## License

[Apache License, Version 2.0](http://www.apache.org/licenses/)

[did:ion]: https://identity.foundation/ion/
[DID Method]: https://www.w3.org/TR/did-core/#methods
[ssi]: https://github.com/spruceid/ssi/
[Sidetree REST API]: https://identity.foundation/sidetree/api/
29 changes: 29 additions & 0 deletions did-ion/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use anyhow::{anyhow, Context, Result};
use ssi::jwk::{Algorithm, JWK};

pub mod sidetree;

use sidetree::{is_secp256k1, Sidetree, SidetreeClient, SidetreeError};

pub struct ION;

/// did:ion Method
pub type DIDION = SidetreeClient<ION>;

impl Sidetree for ION {
fn generate_key() -> Result<JWK, SidetreeError> {
let key = JWK::generate_secp256k1().context("Generate secp256k1 key")?;
Ok(key)
}

fn validate_key(key: &JWK) -> Result<(), SidetreeError> {
if !is_secp256k1(&key) {
return Err(anyhow!("Key must be Secp256k1").into());
}
Ok(())
}

const SIGNATURE_ALGORITHM: Algorithm = Algorithm::ES256K;
const METHOD: &'static str = "ion";
const NETWORK: Option<&'static str> = Some("test");
}
Loading