-
Notifications
You must be signed in to change notification settings - Fork 8
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
Feature/feat eth2 #36
Open
xiaoguang1010
wants to merge
5
commits into
develop
Choose a base branch
from
feature/feat-eth2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a37326
feat: add bls get_pub_key interface
xiaoguang1010 7eeef9b
add bls msg_sign interface
xiaoguang1010 12f4a0b
Optimized bls related code and added test cases
xiaoguang1010 585e36c
Added BLS signature source data length check
xiaoguang1010 cb583ed
modify eth2 instance aid
xiaoguang1010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ members = [ | |
"wallet/coin-bch", | ||
"wallet/coin-filecoin", | ||
"wallet/coin-btc-fork", | ||
"wallet/coin-ethereum2", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::api::PubKeyResult; | ||
use crate::error_handling::Result; | ||
use crate::message_handler::encode_message; | ||
use crate::PubKeyParam; | ||
use coin_ethereum2::address::Eth2Address; | ||
use prost::Message; | ||
|
||
pub fn get_pub_key(param: &PubKeyParam) -> Result<Vec<u8>> { | ||
let pub_key = Eth2Address::get_pub_key(¶m.path)?; | ||
let return_message = PubKeyResult { | ||
path: param.path.to_owned(), | ||
chain_type: param.chain_type.to_string(), | ||
pub_key: pub_key, | ||
derived_mode: "".to_string(), | ||
}; | ||
encode_message(return_message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use crate::error_handling::Result; | ||
use crate::message_handler::encode_message; | ||
use coin_ethereum2::eth2api::Eth2MsgSignInput; | ||
use coin_ethereum2::transaction::Eth2Sign; | ||
use coin_substrate::substrateapi::SubstrateRawTxIn; | ||
use common::SignParam; | ||
use prost::Message; | ||
|
||
pub fn sign_eth2_message(data: &[u8], sign_param: &SignParam) -> Result<Vec<u8>> { | ||
let sign_data: Eth2MsgSignInput = Eth2MsgSignInput::decode(data).expect("imkey_illegal_param"); | ||
let signed = Eth2Sign::msg_sign(sign_data, sign_param)?; | ||
encode_message(signed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
syntax = "proto3"; | ||
package eth2api; | ||
|
||
message Eth2MsgSignInput { | ||
string message = 1; | ||
} | ||
|
||
message Eth2MsgSignOutput { | ||
string signature = 1; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "coin-ethereum2" | ||
version = "0.1.0" | ||
authors = ["xiaoguang <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
common = {path = "../../common"} | ||
device = {path = "../../device"} | ||
transport = {path = "../../transport"} | ||
failure = "0.1.6" | ||
hex = "0.3.2" | ||
prost = "0.6.1" | ||
prost-types = "0.6.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use crate::Result; | ||
|
||
use common::apdu::{Apdu, ApduCheck, BlsApdu}; | ||
use common::constants::ETH2_AID; | ||
use common::error::CoinError; | ||
use common::path::check_path_validity; | ||
use common::utility; | ||
use common::utility::secp256k1_sign_verify; | ||
use device::device_binding::KEY_MANAGER; | ||
use hex; | ||
use transport::message; | ||
use transport::message::send_apdu; | ||
|
||
#[derive(Debug)] | ||
pub struct Eth2Address {} | ||
|
||
impl Eth2Address { | ||
pub fn get_pub_key(path: &str) -> Result<String> { | ||
check_path_validity(path)?; | ||
|
||
let select_apdu = Apdu::select_applet(ETH2_AID); | ||
let select_response = message::send_apdu(select_apdu)?; | ||
ApduCheck::check_response(&select_response)?; | ||
|
||
let key_manager_obj = KEY_MANAGER.lock(); | ||
let bind_signature = utility::secp256k1_sign(&key_manager_obj.pri_key, &path.as_bytes())?; | ||
|
||
let mut apdu_pack: Vec<u8> = vec![]; | ||
apdu_pack.push(0x00); | ||
apdu_pack.push(bind_signature.len() as u8); | ||
apdu_pack.extend(bind_signature.as_slice()); | ||
apdu_pack.push(0x01); | ||
apdu_pack.push(path.as_bytes().len() as u8); | ||
apdu_pack.extend(path.as_bytes()); | ||
|
||
//get public | ||
let msg_pubkey = BlsApdu::get_xpub(&apdu_pack); | ||
let res_msg_pubkey = send_apdu(msg_pubkey)?; | ||
ApduCheck::check_response(&res_msg_pubkey)?; | ||
|
||
let pubkey = &res_msg_pubkey[..96]; | ||
let sign_result = &res_msg_pubkey[96..res_msg_pubkey.len() - 4]; | ||
|
||
//se signature verify | ||
let sign_verify_result = secp256k1_sign_verify( | ||
&key_manager_obj.se_pub_key, | ||
hex::decode(sign_result).unwrap().as_slice(), | ||
hex::decode(pubkey).unwrap().as_slice(), | ||
)?; | ||
if !sign_verify_result { | ||
return Err(CoinError::ImkeySignatureVerifyFail.into()); | ||
} | ||
|
||
Ok(pubkey.to_string()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::address::Eth2Address; | ||
use common::constants; | ||
use device::device_binding::bind_test; | ||
|
||
#[test] | ||
fn test_get_pub_key() { | ||
bind_test(); | ||
|
||
let uncomprs_pubkey = Eth2Address::get_pub_key(constants::ETH2_PATH).unwrap(); | ||
assert_eq!( | ||
&uncomprs_pubkey, | ||
"80CCA779CE5C8C183232518B3F7BF9D1A4AB8767589D320FE39A9379A674765A766FFC99FACC7D60F157F7E5F01E9D01" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Eth2MsgSignInput { | ||
#[prost(string, tag = "1")] | ||
pub message: std::string::String, | ||
} | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Eth2MsgSignOutput { | ||
#[prost(string, tag = "1")] | ||
pub signature: std::string::String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pub mod address; | ||
pub mod eth2api; | ||
pub mod transaction; | ||
|
||
#[macro_use] | ||
extern crate failure; | ||
use core::result; | ||
pub type Result<T> = result::Result<T, failure::Error>; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确定前面的path不是harden 的是吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的。https://eips.ethereum.org/EIPS/eip-2334
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以看看https://eips.ethereum.org/EIPS/eip-2333 目前来看这个派生方案和bip32是不兼容的