Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into IS-1203C
Browse files Browse the repository at this point in the history
  • Loading branch information
jovfer committed Mar 15, 2019
2 parents 41e1d36 + 1ff1206 commit d355fae
Show file tree
Hide file tree
Showing 31 changed files with 5,045 additions and 7,108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,85 +17,86 @@ credential definition for the Schema added by Steward.
// ------------------------------------------
// hyperledger crates
// ------------------------------------------
extern crate indy; // rust wrapper project
extern crate indyrs as indy; // rust wrapper project

use std::env;
use std::fs;
use std::io::Write;
use std::path::PathBuf;

use indy::did::Did;
use indy::ledger::Ledger;
use indy::pool::Pool;
use indy::wallet::Wallet;
use indy::anoncreds::Issuer;
use indy::did;
use indy::future::Future;
use indy::ledger;
use indy::pool;
use indy::wallet;
use indy::anoncreds;

const PROTOCOL_VERSION: usize = 2;
static USEFUL_CREDENTIALS: &'static str = r#"{"key": "12345678901234567890123456789012"}"#;

fn main() {
let wallet_name = "wallet";
let pool_name = "pool";
let wallet_name = "walletXX";
let pool_name = "poolXX";

indy::pool::Pool::set_protocol_version(PROTOCOL_VERSION).unwrap();
indy::pool::set_protocol_version(PROTOCOL_VERSION).wait().unwrap();

println!("1. Creating a new local pool ledger configuration that can be used later to connect pool nodes");
let pool_config_file = create_genesis_txn_file_for_pool(pool_name);
let pool_config = json!({
"genesis_txn" : &pool_config_file
});
Pool::create_ledger_config(&pool_name, Some(&pool_config.to_string())).unwrap();
pool::create_pool_ledger_config(&pool_name, Some(&pool_config.to_string())).wait().unwrap();

println!("2. Open pool ledger and get the pool handle from libindy");
let pool_handle: i32 = Pool::open_ledger(&pool_name, None).unwrap();
let pool_handle: i32 = pool::open_pool_ledger(&pool_name, None).wait().unwrap();

println!("3. Creates a new wallet");
let config = json!({ "id" : wallet_name.to_string() }).to_string();
Wallet::create(&config, USEFUL_CREDENTIALS).unwrap();
wallet::create_wallet(&config, USEFUL_CREDENTIALS).wait().unwrap();

println!("4. Open wallet and get the wallet handle from libindy");
let wallet_handle: i32 = Wallet::open(&config, USEFUL_CREDENTIALS).unwrap();
let wallet_handle: i32 = wallet::open_wallet(&config, USEFUL_CREDENTIALS).wait().unwrap();

println!("5. Generating and storing steward DID and Verkey");
let first_json_seed = json!({
"seed":"000000000000000000000000Steward1"
}).to_string();
let (steward_did, _steward_verkey) = Did::new(wallet_handle, &first_json_seed).unwrap();
let (steward_did, _steward_verkey) = did::create_and_store_my_did(wallet_handle, &first_json_seed).wait().unwrap();

println!("6. Generating and storing Trust Anchor DID and Verkey");
let (trustee_did, trustee_verkey) = Did::new(wallet_handle, &"{}".to_string()).unwrap();
let (trustee_did, trustee_verkey) = did::create_and_store_my_did(wallet_handle, &"{}".to_string()).wait().unwrap();

println!("7. Build NYM request to add Trust Anchor to the ledger");
let build_nym_request: String = Ledger::build_nym_request(&steward_did, &trustee_did, Some(&trustee_verkey), None, Some("TRUST_ANCHOR")).unwrap();
let build_nym_request: String = ledger::build_nym_request(&steward_did, &trustee_did, Some(&trustee_verkey), None, Some("TRUST_ANCHOR")).wait().unwrap();

println!("8. Sending the nym request to ledger");
let _build_nym_sign_submit_result: String = Ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_nym_request).unwrap();
let _build_nym_sign_submit_result: String = ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_nym_request).wait().unwrap();

println!("9. Create Schema and Build the SCHEMA request to add new schema to the ledger as a Steward");
let name = "gvt";
let version = "1.0";
let attributes = r#"["age", "sex", "height", "name"]"#;
let (_schema_id, schema_json) = Issuer::create_schema(&steward_did, name, version, attributes).unwrap();
let (_schema_id, schema_json) = anoncreds::issuer_create_schema(&steward_did, name, version, attributes).wait().unwrap();

let build_schema_request: String = Ledger::build_schema_request(&steward_did, &schema_json).unwrap();
let build_schema_request: String = ledger::build_schema_request(&steward_did, &schema_json).wait().unwrap();

println!("10. Sending the SCHEMA request to the ledger");
let _signed_schema_request_response = Ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_schema_request).unwrap();
let _signed_schema_request_response = ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_schema_request).wait().unwrap();

println!("11. Creating and storing CREDENTAIL DEFINITION using anoncreds as Trust Anchor, for the given Schema");
let config_json = r#"{ "support_revocation": false }"#;
let tag = r#"TAG1"#;

let (_cred_def_id, _cred_def_json) = Issuer::create_and_store_credential_def(wallet_handle, &trustee_did, &schema_json, tag, None, config_json).unwrap();
let (_cred_def_id, _cred_def_json) = anoncreds::issuer_create_and_store_credential_def(wallet_handle, &trustee_did, &schema_json, tag, None, config_json).wait().unwrap();

// CLEAN UP
println!("12. Close and delete wallet");
indy::wallet::Wallet::close(wallet_handle).unwrap();
indy::wallet::Wallet::delete(&config, USEFUL_CREDENTIALS).unwrap();
indy::wallet::close_wallet(wallet_handle).wait().unwrap();
indy::wallet::delete_wallet(&config, USEFUL_CREDENTIALS).wait().unwrap();

println!("13. Close pool and delete pool ledger config");
Pool::close(pool_handle).unwrap();
Pool::delete(&pool_name).unwrap();
pool::close_pool_ledger(pool_handle).wait().unwrap();
pool::delete_pool_ledger(&pool_name).wait().unwrap();
}

fn create_genesis_txn_file_for_pool(pool_name: &str) -> String {
Expand Down Expand Up @@ -129,4 +130,4 @@ fn write_genesis_txn_to_file(pool_name: &str,
f.sync_all().unwrap();

txn_file_path
}
}
24 changes: 12 additions & 12 deletions docs/how-tos/save-schema-and-cred-def/rust/src/step2.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
indy::pool::Pool::set_protocol_version(PROTOCOL_VERSION).unwrap();
indy::pool::set_protocol_version(PROTOCOL_VERSION).wait().unwrap();

println!("1. Creating a new local pool ledger configuration that can be used later to connect pool nodes");
let pool_config_file = create_genesis_txn_file_for_pool(pool_name);
let pool_config = json!({
"genesis_txn" : &pool_config_file
});
Pool::create_ledger_config(&pool_name, Some(&pool_config.to_string())).unwrap();
"genesis_txn" : &pool_config_file
});
pool::create_pool_ledger_config(&pool_name, Some(&pool_config.to_string())).wait().unwrap();

println!("2. Open pool ledger and get the pool handle from libindy");
let pool_handle: i32 = Pool::open_ledger(&pool_name, None).unwrap();
let pool_handle: i32 = pool::open_pool_ledger(&pool_name, None).wait().unwrap();

println!("3. Creates a new wallet");
let config = json!({ "id" : wallet_name.to_string() }).to_string();
Wallet::create(&config, USEFUL_CREDENTIALS).unwrap();
wallet::create_wallet(&config, USEFUL_CREDENTIALS).wait().unwrap();

println!("4. Open wallet and get the wallet handle from libindy");
let wallet_handle: i32 = Wallet::open(&config, USEFUL_CREDENTIALS).unwrap();
let wallet_handle: i32 = wallet::open_wallet(&config, USEFUL_CREDENTIALS).wait().unwrap();

println!("5. Generating and storing steward DID and Verkey");
let first_json_seed = json!({
"seed":"000000000000000000000000Steward1"
"seed":"000000000000000000000000Steward1"
}).to_string();
let (steward_did, _steward_verkey) = Did::new(wallet_handle, &first_json_seed).unwrap();
let (steward_did, _steward_verkey) = did::create_and_store_my_did(wallet_handle, &first_json_seed).wait().unwrap();

println!("6. Generating and storing Trust Anchor DID and Verkey");
let (trustee_did, trustee_verkey) = Did::new(wallet_handle, &"{}".to_string()).unwrap();
let (trustee_did, trustee_verkey) = did::create_and_store_my_did(wallet_handle, &"{}".to_string()).wait().unwrap();

println!("7. Build NYM request to add Trust Anchor to the ledger");
let build_nym_request: String = Ledger::build_nym_request(&steward_did, &trustee_did, Some(&trustee_verkey), None, Some("TRUST_ANCHOR")).unwrap();
let build_nym_request: String = ledger::build_nym_request(&steward_did, &trustee_did, Some(&trustee_verkey), None, Some("TRUST_ANCHOR")).wait().unwrap();

println!("8. Sending the nym request to ledger");
let _build_nym_sign_submit_result: String = Ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_nym_request).unwrap();
let _build_nym_sign_submit_result: String = ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_nym_request).wait().unwrap();
6 changes: 3 additions & 3 deletions docs/how-tos/save-schema-and-cred-def/rust/src/step3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ println!("9. Create Schema and Build the SCHEMA request to add new schema to the
let name = "gvt";
let version = "1.0";
let attributes = r#"["age", "sex", "height", "name"]"#;
let (_schema_id, schema_json) = Issuer::create_schema(&steward_did, name, version, attributes).unwrap();
let (_schema_id, schema_json) = anoncreds::issuer_create_schema(&steward_did, name, version, attributes).wait().unwrap();

let build_schema_request: String = Ledger::build_schema_request(&steward_did, &schema_json).unwrap();
let build_schema_request: String = ledger::build_schema_request(&steward_did, &schema_json).wait().unwrap();

println!("10. Sending the SCHEMA request to the ledger");
let _signed_schema_request_response = Ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_schema_request).unwrap();
let _signed_schema_request_response = ledger::sign_and_submit_request(pool_handle, wallet_handle, &steward_did, &build_schema_request).wait().unwrap();
12 changes: 6 additions & 6 deletions docs/how-tos/save-schema-and-cred-def/rust/src/step4.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
println!("11. Creating and storing CREDENTIAL DEFINITION using anoncreds as Trust Anchor, for the given Schema");
println!("11. Creating and storing CREDENTAIL DEFINITION using anoncreds as Trust Anchor, for the given Schema");
let config_json = r#"{ "support_revocation": false }"#;
let tag = r#"TAG1"#;

let (_cred_def_id, _cred_def_json) = Issuer::create_and_store_credential_def(wallet_handle, &trustee_did, &schema_json, tag, None, config_json).unwrap();
let (_cred_def_id, _cred_def_json) = anoncreds::issuer_create_and_store_credential_def(wallet_handle, &trustee_did, &schema_json, tag, None, config_json).wait().unwrap();

// CLEAN UP
println!("12. Close and delete wallet");
indy::wallet::Wallet::close(wallet_handle).unwrap();
indy::wallet::Wallet::delete(&config, USEFUL_CREDENTIALS).unwrap();
indy::wallet::close_wallet(wallet_handle).wait().unwrap();
indy::wallet::delete_wallet(&config, USEFUL_CREDENTIALS).wait().unwrap();

println!("13. Close pool and delete pool ledger config");
Pool::close(pool_handle).unwrap();
Pool::delete(&pool_name).unwrap();
pool::close_pool_ledger(pool_handle).wait().unwrap();
pool::delete_pool_ledger(&pool_name).wait().unwrap();
22 changes: 11 additions & 11 deletions docs/how-tos/save-schema-and-cred-def/rust/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ credential definition for the Schema added by Steward.
// ------------------------------------------
// crates.io
// ------------------------------------------
#[macro_use]
extern crate serde_json;
#[macro_use] extern crate serde_json;


// ------------------------------------------
// hyperledger crates
// ------------------------------------------
extern crate indy; // rust wrapper project
extern crate indyrs as indy; // rust wrapper project

use std::env;
use std::fs;
use std::io::Write;
use std::path::PathBuf;

use indy::did::Did;
use indy::ledger::Ledger;
use indy::pool::Pool;
use indy::wallet::Wallet;
use indy::anoncreds::Issuer;
use indy::did;
use indy::future::Future;
use indy::ledger;
use indy::pool;
use indy::wallet;
use indy::anoncreds;

const PROTOCOL_VERSION: usize = 2;
static USEFUL_CREDENTIALS: &'static str = r#"{"key": "12345678901234567890123456789012"}"#;

fn main() {
let wallet_name = "wallet";
let pool_name = "pool";
let wallet_name = "walletXX";
let pool_name = "poolXX";

// Step 2 code goes here.

Expand Down Expand Up @@ -76,4 +76,4 @@ fn write_genesis_txn_to_file(pool_name: &str,
f.sync_all().unwrap();

txn_file_path
}
}
Loading

0 comments on commit d355fae

Please sign in to comment.