Skip to content

Commit

Permalink
Merge branch 'main' into 115-selective-disclosure-ssi-update
Browse files Browse the repository at this point in the history
  • Loading branch information
edchapman88 committed Nov 22, 2023
2 parents d4c3da8 + 2343764 commit 975e85c
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 277 deletions.
30 changes: 15 additions & 15 deletions trustchain-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use trustchain_core::{
vp::PresentationError,
};
use trustchain_ion::{
attest::attest_operation, attestor::IONAttestor, create::create_operation, get_ion_resolver,
attest::attest_operation, attestor::IONAttestor, create::create_operation, trustchain_resolver,
};

/// API for Trustchain CLI DID functionality.
Expand Down Expand Up @@ -146,7 +146,7 @@ pub trait TrustchainVPAPI {
linked_data_proof_options: Option<LinkedDataProofOptions>,
context_loader: &mut ContextLoader,
) -> Result<Presentation, PresentationError> {
let resolver = get_ion_resolver(endpoint);
let resolver = trustchain_resolver(endpoint);
let attestor = IONAttestor::new(did);
Ok(attestor
.sign_presentation(
Expand Down Expand Up @@ -258,8 +258,8 @@ mod tests {
use trustchain_core::vp::PresentationError;
use trustchain_core::{holder::Holder, issuer::Issuer};
use trustchain_ion::attestor::IONAttestor;
use trustchain_ion::get_ion_resolver;
use trustchain_ion::verifier::IONVerifier;
use trustchain_ion::trustchain_resolver;
use trustchain_ion::verifier::TrustchainVerifier;

// The root event time of DID documents in `trustchain-ion/src/data.rs` used for unit tests and the test below.
const ROOT_EVENT_TIME_1: u64 = 1666265405;
Expand Down Expand Up @@ -318,13 +318,13 @@ mod tests {
let issuer_did = "did:ion:test:EiBVpjUxXeSRJpvj2TewlX9zNF3GKMCKWwGmKBZqF6pk_A"; // root+1
let issuer = IONAttestor::new(issuer_did);
let mut vc_with_proof = signed_credential(issuer).await;
let resolver = get_ion_resolver("http://localhost:3000/");
let resolver = trustchain_resolver("http://localhost:3000/");
let mut context_loader = ContextLoader::default();
let res = TrustchainAPI::verify_credential(
&vc_with_proof,
None,
ROOT_EVENT_TIME_1,
&IONVerifier::new(resolver),
&TrustchainVerifier::new(resolver),
&mut context_loader,
)
.await;
Expand All @@ -334,12 +334,12 @@ mod tests {
vc_with_proof.expiration_date = Some(VCDateTime::try_from(now_ns()).unwrap());

// Verify: expect no warnings and a signature error as VC has changed
let resolver = get_ion_resolver("http://localhost:3000/");
let resolver = trustchain_resolver("http://localhost:3000/");
let res = TrustchainAPI::verify_credential(
&vc_with_proof,
None,
ROOT_EVENT_TIME_1,
&IONVerifier::new(resolver),
&TrustchainVerifier::new(resolver),
&mut context_loader,
)
.await;
Expand All @@ -359,7 +359,7 @@ mod tests {

// DID with RSS verification method
let issuer_did_suffix = "EiDSE2lEM65nYrEqVvQO5C3scYhkv1KmZzq0S0iZmNKf1Q";
let resolver = get_ion_resolver("http://localhost:3000/");
let resolver = trustchain_resolver("http://localhost:3000/");
let vc: Credential = serde_json::from_str(UNSIGNED_DRIVERS_LICENCE_VC).unwrap();
let attestor = IONAttestor::new(issuer_did_suffix);

Expand Down Expand Up @@ -407,7 +407,7 @@ mod tests {
&signed_vc,
None,
1697213008,
&IONVerifier::new(resolver),
&TrustchainVerifier::new(resolver),
&mut context_loader,
)
.await;
Expand All @@ -425,7 +425,7 @@ mod tests {
let holder = IONAttestor::new(holder_did);

let vc_with_proof = signed_credential(issuer).await;
let resolver = get_ion_resolver("http://localhost:3000/");
let resolver = trustchain_resolver("http://localhost:3000/");
let mut context_loader = ContextLoader::default();

// let vc: Credential = serde_json::from_str(TEST_UNSIGNED_VC).unwrap();
Expand Down Expand Up @@ -482,7 +482,7 @@ mod tests {
&presentation,
None,
ROOT_EVENT_TIME_1,
&IONVerifier::new(resolver),
&TrustchainVerifier::new(resolver),
&mut context_loader,
)
.await;
Expand All @@ -499,7 +499,7 @@ mod tests {
let issuer = IONAttestor::new(issuer_did);

let vc_with_proof = signed_credential(issuer).await;
let resolver = get_ion_resolver("http://localhost:3000/");
let resolver = trustchain_resolver("http://localhost:3000/");
let presentation = Presentation {
verifiable_credential: Some(OneOrMany::Many(vec![CredentialOrJWT::Credential(
vc_with_proof,
Expand All @@ -513,7 +513,7 @@ mod tests {
&presentation,
None,
ROOT_EVENT_TIME_1,
&IONVerifier::new(resolver),
&TrustchainVerifier::new(resolver),
&mut ContextLoader::default()
)
.await,
Expand All @@ -523,7 +523,7 @@ mod tests {

// Helper function to create a signed credential given an attesor.
async fn signed_credential(attestor: IONAttestor) -> Credential {
let resolver = get_ion_resolver("http://localhost:3000/");
let resolver = trustchain_resolver("http://localhost:3000/");
let vc: Credential = serde_json::from_str(TEST_UNSIGNED_VC).unwrap();
attestor
.sign(&vc, None, None, &resolver, &mut ContextLoader::default())
Expand Down
8 changes: 4 additions & 4 deletions trustchain-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use trustchain_core::{vc::CredentialError, verifier::Verifier};
use trustchain_ion::{
attest::attest_operation,
create::{create_operation, create_operation_mnemonic},
get_ion_resolver,
verifier::IONVerifier,
trustchain_resolver,
verifier::TrustchainVerifier,
};

fn cli() -> Command {
Expand Down Expand Up @@ -89,7 +89,7 @@ fn cli() -> Command {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let matches = cli().get_matches();
let endpoint = cli_config().ion_endpoint.to_address();
let verifier = IONVerifier::new(get_ion_resolver(&endpoint));
let verifier = TrustchainVerifier::new(trustchain_resolver(&endpoint));
let resolver = verifier.resolver();
let mut context_loader = ContextLoader::default();
match matches.subcommand() {
Expand Down Expand Up @@ -170,7 +170,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
Some(("vc", sub_matches)) => {
let verifier = IONVerifier::new(get_ion_resolver(&endpoint));
let verifier = TrustchainVerifier::new(trustchain_resolver(&endpoint));
let resolver = verifier.resolver();
match sub_matches.subcommand() {
Some(("sign", sub_matches)) => {
Expand Down
1 change: 0 additions & 1 deletion trustchain-core/src/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::path::{Path, PathBuf};
use thiserror::Error;

/// An error relating to Trustchain key management.
// #[derive(Error, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Error, Debug)]
pub enum KeyManagerError {
/// Key does not exist.
Expand Down
13 changes: 2 additions & 11 deletions trustchain-core/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ fn get_from_proof_service<'a>(proof_service: &'a Service, key: &str) -> Option<&

/// Adds a proof from a DID Document to DocumentMetadata.
fn add_proof(doc: &Document, mut doc_meta: DocumentMetadata) -> DocumentMetadata {
// Check if the Trustchain proof service exists in document

// Get proof service
let proof_service = get_proof_service(doc);

Expand Down Expand Up @@ -165,10 +163,6 @@ fn transform_doc(doc: &Document, controller_did: &str) -> Document {
// Clone the passed DID document.
let doc_clone = doc.clone();

// Duplication?
// // Check if the Trustchain proof service alreday exists in the document.
// let doc_clone = self.remove_proof_service(doc_clone);

// Add controller
let doc_clone =
add_controller(doc_clone, controller_did).expect("Controller already present in document.");
Expand Down Expand Up @@ -212,7 +206,7 @@ fn transform_as_result(
// Return tuple
Ok((res_meta, doc, doc_meta))
} else {
// TODO: If proof service is not present or multiple, just return Ok for now.
// If proof service is not present, return Ok.
Ok((sidetree_res_meta, sidetree_doc, sidetree_doc_meta))
}
}
Expand Down Expand Up @@ -299,7 +293,7 @@ pub trait TrustchainResolver: DIDResolver + AsDIDResolver {
Err(ResolverError::FailedToConvertToTrustchain(
did_res_meta_error
.to_owned()
.rsplit(":")
.rsplit(':')
.next()
.unwrap_or("")
.to_owned(),
Expand Down Expand Up @@ -338,8 +332,6 @@ pub trait TrustchainResolver: DIDResolver + AsDIDResolver {
.resolve(did, &ResolutionInputMetadata::default())
.await;
}
// let ion_resolver = self.wrapped_resolver;
// let resolved = ion_resolver.resolve(did, input_metadata).await;

let resolved = self.wrapped_resolver().resolve(did, input_metadata).await;

Expand Down Expand Up @@ -436,7 +428,6 @@ mod tests {
assert!(did_doc.controller.is_some());

// Construct a Resolver instance.
// let resolver = Resolver::new(get_http_resolver());

// Attempt to add the controller.
let result = add_controller(did_doc, controller_did);
Expand Down
22 changes: 12 additions & 10 deletions trustchain-ffi/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use trustchain_core::{
};
use trustchain_ion::{
create::{mnemonic_to_create_and_keys, OperationDID},
get_ion_resolver,
verifier::IONVerifier,
trustchain_resolver_light_client,
verifier::TrustchainVerifier,
};

/// A speicfic error for FFI mobile making handling easier.
Expand Down Expand Up @@ -81,7 +81,8 @@ pub fn greet() -> String {
pub fn did_resolve(did: String, opts: String) -> Result<String> {
let mobile_opts: FFIConfig = opts.parse()?;
let endpoint_opts = mobile_opts.endpoint()?;
let resolver = get_ion_resolver(&endpoint_opts.trustchain_endpoint().to_address());
let resolver =
trustchain_resolver_light_client(&endpoint_opts.trustchain_endpoint().to_address());
let rt = Runtime::new().unwrap();
rt.block_on(async {
Ok(TrustchainAPI::resolve(&did, &resolver)
Expand All @@ -101,8 +102,8 @@ pub fn did_verify(did: String, opts: String) -> Result<String> {
let root_event_time = trustchain_opts.root_event_time;
let rt = Runtime::new().unwrap();
rt.block_on(async {
let verifier = IONVerifier::with_endpoint(
get_ion_resolver(&endpoint_opts.trustchain_endpoint().to_address()),
let verifier = TrustchainVerifier::with_endpoint(
trustchain_resolver_light_client(&endpoint_opts.trustchain_endpoint().to_address()),
endpoint_opts.trustchain_endpoint().to_address(),
);
Ok(TrustchainAPI::verify(&did, root_event_time, &verifier)
Expand All @@ -123,8 +124,8 @@ pub fn vc_verify_credential(credential: String, opts: String) -> Result<String>
let credential: Credential = serde_json::from_str(&credential)?;
let rt = Runtime::new().unwrap();
rt.block_on(async {
let verifier = IONVerifier::with_endpoint(
get_ion_resolver(&endpoint_opts.trustchain_endpoint().to_address()),
let verifier = TrustchainVerifier::with_endpoint(
trustchain_resolver_light_client(&endpoint_opts.trustchain_endpoint().to_address()),
endpoint_opts.trustchain_endpoint().to_address(),
);
let root_event_time = trustchain_opts.root_event_time;
Expand Down Expand Up @@ -172,7 +173,8 @@ pub fn vp_issue_presentation(
let mut presentation: Presentation =
serde_json::from_str(&presentation).map_err(FFIMobileError::FailedToDeserialize)?;
let jwk: JWK = serde_json::from_str(&jwk_json)?;
let resolver = get_ion_resolver(&endpoint_opts.trustchain_endpoint().to_address());
let resolver =
trustchain_resolver_light_client(&endpoint_opts.trustchain_endpoint().to_address());
let rt = Runtime::new().unwrap();
let proof = rt
.block_on(async {
Expand Down Expand Up @@ -205,8 +207,8 @@ pub fn vp_verify_presentation(presentation: String, opts: String) -> Result<()>
// Verify presentation
let rt = Runtime::new().unwrap();
rt.block_on(async {
let verifier = IONVerifier::with_endpoint(
get_ion_resolver(&endpoint_opts.trustchain_endpoint().to_address()),
let verifier = TrustchainVerifier::with_endpoint(
trustchain_resolver_light_client(&endpoint_opts.trustchain_endpoint().to_address()),
endpoint_opts.trustchain_endpoint().to_address(),
);
let root_event_time = trustchain_opts.root_event_time;
Expand Down
4 changes: 2 additions & 2 deletions trustchain-http/src/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
};
use std::{collections::HashMap, sync::Arc};
use trustchain_core::{utils::canonicalize, verifier::Verifier};
use trustchain_ion::{get_ion_resolver, verifier::IONVerifier};
use trustchain_ion::{trustchain_resolver, verifier::TrustchainVerifier};

lazy_static! {
/// Lazy static reference to core configuration loaded from `trustchain_config.toml`.
Expand Down Expand Up @@ -361,7 +361,7 @@ mod tests {
}

// Test signature
let verifier = IONVerifier::new(get_ion_resolver("http://localhost:3000/"));
let verifier = TrustchainVerifier::new(trustchain_resolver("http://localhost:3000/"));
let verify_credential_result = credential
.verify(
None,
Expand Down
Loading

0 comments on commit 975e85c

Please sign in to comment.