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

Addition of DID version selection #4

Merged
merged 1 commit into from
Apr 24, 2024
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Tool for registering a new NYM and it's role on the Indy Ledger
Make sure you are using the latest version of stable rust by running `rustup update`.
Run `cargo run` to start the app.

You might require cmake to be present depending on your system.

### Native Locally

`cargo run --release`
Expand All @@ -37,4 +39,8 @@ On Fedora Rawhide you need to run:

### Web Locally

Sadly, for the moment, the zmq library is preventing a webassembly build.
Sadly, for the moment, the zmq library is preventing a webassembly build.

### Roadmap

Using a wallet instead of asking for the seed
18 changes: 18 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ pub enum MyRoles {
NetworkMonitor = 201,
Steward = 2,
}

#[derive(PartialEq, Eq, Deserialize, Serialize, Debug)]
pub enum DIDVersion {
Sov,
Indy,
}
impl DIDVersion {
pub fn to_usize(&self) -> usize {
match self {
DIDVersion::Sov => 1,
DIDVersion::Indy => 2,
}
}
}
impl Default for MyRoles {
fn default() -> Self {
Self::Endorser
Expand All @@ -33,6 +47,7 @@ pub struct TemplateApp {
my_role: MyRoles,
nym_did: DidInfo,
trustee_did: DidInfo,
did_version: DIDVersion,
}

impl Default for TemplateApp {
Expand All @@ -50,6 +65,7 @@ impl Default for TemplateApp {
my_role: Default::default(),
nym_did: Default::default(),
trustee_did: Default::default(),
did_version: DIDVersion::Indy,
}
}
}
Expand Down Expand Up @@ -127,6 +143,7 @@ impl eframe::App for TemplateApp {
&mut self.endorser_seed,
&mut self.txn,
&mut self.signed_txn_result,
&mut self.did_version,
);
});
}
Expand All @@ -147,6 +164,7 @@ impl eframe::App for TemplateApp {
&mut self.my_role,
&mut self.nym_did,
&mut self.trustee_did,
&mut self.did_version,
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use indy_vdr::pool::helpers::perform_ledger_request;
use indy_vdr::pool::{PreparedRequest, ProtocolVersion, RequestResult, SharedPool};
use serde_json::Value;

pub fn create_did(seed: String) -> anyhow::Result<DidInfo> {
let (did, prv, vk) = generate_did(Some(seed.as_bytes()), Some(1))?;
pub fn create_did(seed: String, version: usize) -> anyhow::Result<DidInfo> {
let (did, prv, vk) = generate_did(Some(seed.as_bytes()), Some(version))?;
let endorser_did = DidInfo {
did: DidValue::from(did.to_string()),
privatekey: prv,
Expand Down
14 changes: 12 additions & 2 deletions src/indorser.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
use crate::app::DIDVersion;
use crate::helpers::{create_did, sign_transaction};
use egui::Ui;

pub fn endorser_tool(
ui: &mut Ui,
endorser_seed: &mut String,
txn: &mut String,
signed_txn_result: &mut Option<String>,
did_version: &mut DIDVersion,
) {
ui.label("Sign Txn with Endorser DID");
// Add more UI elements inside the nested window
ui.heading("Endorser");

ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.label("Endorser seed: ");
ui.add(
egui::TextEdit::singleline(endorser_seed)
.char_limit(32)
.hint_text("Enter 32 bytes seed"),
);
ui.label(format!("Length: {}", endorser_seed.len()));
ui.label("Select the version for the DID. did:Sov is 1, did:Indy is 2");
egui::ComboBox::from_id_source("version_dropdown")
.selected_text(format!("{:?}", did_version))
.show_ui(ui, |ui| {
ui.selectable_value(&mut *did_version, DIDVersion::Sov, "SOV");
ui.selectable_value(&mut *did_version, DIDVersion::Indy, "Indy");
});
});
ui.separator();
if endorser_seed.len() == 32 {
let endorser_did = create_did(endorser_seed.clone()).unwrap();
let endorser_did = create_did(endorser_seed.clone(), did_version.to_usize()).unwrap();
ui.colored_label(
egui::Color32::KHAKI,
format!("DID: {:?}", endorser_did.did.0),
Expand Down
16 changes: 12 additions & 4 deletions src/nym_registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use indy_vdr::ledger::constants::{LedgerRole, UpdateRole};
use indy_vdr::pool::{PoolBuilder, PoolTransactions};
use rfd::FileDialog;

use crate::app::MyRoles;
use crate::app::{DIDVersion, MyRoles};
use crate::helpers::{create_did, register_nym, DidInfo};

#[allow(clippy::too_many_arguments)]
pub fn nym_registration_tool(
ui: &mut Ui,
trustee_seed: &mut String,
Expand All @@ -16,6 +17,7 @@ pub fn nym_registration_tool(
my_role: &mut MyRoles,
nym_did: &mut DidInfo,
trustee_did: &mut DidInfo,
did_version: &mut DIDVersion,
) {
ui.heading("Nym Creation Tool");
ui.separator();
Expand All @@ -33,8 +35,14 @@ pub fn nym_registration_tool(
.hint_text("Enter 32 bytes seed"),
);
ui.label(format!("Length: {}", trustee_seed.len()));
ui.label("Select the version used for the trustee DID. did:Sov is 1, did:Indy is 2");
egui::ComboBox::from_id_source("did_version_dropdown")
.selected_text(format!("{:?}", did_version))
.show_ui(ui, |ui| {
ui.selectable_value(&mut *did_version, DIDVersion::Sov, "SOV");
ui.selectable_value(&mut *did_version, DIDVersion::Indy, "Indy");
});
});

ui.separator();
ui.vertical(|ui| {
ui.heading("NYM Registration");
Expand Down Expand Up @@ -62,7 +70,7 @@ pub fn nym_registration_tool(
});
ui.separator();
ui.label("Select the role for the NYM");
egui::ComboBox::from_id_source("my_dropdown")
egui::ComboBox::from_id_source("my_role_dropdown")
.selected_text(format!("{:?}", my_role))
.show_ui(ui, |ui| {
ui.selectable_value(&mut *my_role, MyRoles::Endorser, "Endorser");
Expand All @@ -87,7 +95,7 @@ pub fn nym_registration_tool(
MyRoles::Steward => UpdateRole::Set(LedgerRole::Steward),
};

match create_did(trustee_seed.clone()) {
match create_did(trustee_seed.clone(), did_version.to_usize()) {
Ok(did) => *trustee_did = did,
Err(e) => {
eprintln!("Error occurred: {:?}", e);
Expand Down
Loading