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

Add claim into subkey #164

Merged
merged 4 commits into from
May 25, 2020
Merged
Changes from 2 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
36 changes: 36 additions & 0 deletions bin/subkey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ trait Crypto: Sized {
format_account_id::<Self>(public_key.clone()),
public_key.to_ss58check_with_version(v)
);
} else if let Ok(message) = hex::decode(uri) {
let account_id = plasm_account_from_public(&message[..]);
println!(
"Public Key (hex): `{}` is account:\n \
Plasm AccountId: {}\n \
Ethereum Address: {:?}\n \
Plasm Address: {}",
uri,
account_id,
eth_account_from_public(&message),
account_id.to_ss58check_with_version(Ss58AddressFormat::PlasmAccount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it generalized by default and use account_id.to_ss58check_with_version(v) form.

);
} else {
println!("Invalid phrase/URI given");
}
Expand Down Expand Up @@ -583,6 +595,17 @@ fn print_usage(matches: &ArgMatches) {
println!("{}", matches.usage());
}

fn plasm_account_from_public(full_public: &[u8]) -> plasm_primitives::AccountId {
use sp_runtime::MultiSigner;
let public =
sp_core::ecdsa::Public::from_full(full_public).expect("Not convert from_full publickey.");
MultiSigner::from(public).into_account()
}

fn eth_account_from_public(full_public: &[u8]) -> sp_core::H160 {
sp_core::H160::from_slice(&sp_core::hashing::keccak_256(&full_public)[12..32])
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -652,4 +675,17 @@ mod tests {

assert_eq!(d1, d2);
}

#[test]
fn should_from_public_work() {
let full_public = hex!["3e909fb1f265942dbbf5e0659ee5c74820c8ecb5a55eecba5752f3cd55293ef98fa8efc553f174ddf3f7e2b5d99ab731da7cff2c1ed7d20579c59e85ab6772dc"];
assert_eq!(
plasm_account_from_public(&full_public[..]).to_string(),
"5HYaXhCVqDgjkbpUTXJKzc2bFNSwpt7Xm7znS7WaqGNSUEfG"
);
assert_eq!(
eth_account_from_public(&full_public[..]).as_bytes(),
&hex!["e0e0b97949687e5cdc9ca843c0428bd0437e176d"][..]
);
}
}