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

feat: eth batch personal sign[R2D2-8760] #45

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.5
2.6.6
1 change: 1 addition & 0 deletions imkey-core/ikc-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ aes-soft = "0.6.4"
block-modes = "0.7.0"
parking_lot = "0.12.1"
bitcoin = "0.29.2"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
10 changes: 10 additions & 0 deletions imkey-core/ikc-common/src/apdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ impl EthApdu {
pub fn personal_sign(path: &str) -> String {
Apdu::sign_digest(0x55, 0x00, 0x00, path)
}

pub fn batch_personal_sign(p1: u8, p2: u8, data: Vec<u8>) -> String {
if data.len() as u32 > LC_MAX {
panic!("data to long");
}
let mut apdu = ApduHeader::new(0x80, 0x57, p1, p2, data.len() as u8).to_array();
apdu.extend(data.iter());
apdu.push(0x00);
apdu.to_hex().to_uppercase()
}
}

pub struct EosApdu();
Expand Down
6 changes: 4 additions & 2 deletions imkey-core/ikc-common/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub const VERSION: &str = "2.10.3";
pub const URL: &str = "https://imkey.online:1000/imkey";
// pub const URL: &str = "https://imkeyserver.com:10444/imkey";
// pub const URL: &str = "https://imkey.online:1000/imkey";
pub const URL: &str = "https://imkeyserver.com:10443/imkey";

pub const TSM_ACTION_SE_SECURE_CHECK: &str = "/seSecureCheck";
pub const TSM_ACTION_APP_DOWNLOAD: &str = "/appDownload";
Expand Down Expand Up @@ -117,3 +117,5 @@ pub const ETH_TRANSACTION_TYPE_EIP2718: &str = "01";
pub const ETH_TRANSACTION_TYPE_EIP1559: &str = "02";

pub const ETH_MAX_SUPPORT_PAYMENT_LEN: usize = 255;

pub const ETH_BATCH_SIGN_MAX_MESSAGE_NUMBER: usize = 1000;
2 changes: 2 additions & 0 deletions imkey-core/ikc-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ pub enum CoinError {
InvalidVersion,
#[fail(display = "invalid addr length")]
InvalidAddrLength,
#[fail(display = "imkey_exceeded_message_number")]
ImkeyExceededMessageNumber,
}
9 changes: 9 additions & 0 deletions imkey-core/ikc-common/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ring::digest;
use secp256k1::ecdsa::{RecoverableSignature, RecoveryId};
use secp256k1::{Message, PublicKey as PublicKey2, Secp256k1, SecretKey, Signature};
use std::str::FromStr;
use tiny_keccak::Hasher;

pub fn hex_to_bytes(value: &str) -> Result<Vec<u8>> {
let ret_data;
Expand Down Expand Up @@ -129,6 +130,14 @@ pub fn get_account_path(path: &str) -> Result<String> {
Ok(children.join("/"))
}

pub fn keccak_256_hash(value: &[u8]) -> Vec<u8> {
let mut keccak256 = tiny_keccak::Keccak::v256();
keccak256.update(&value);
let mut hash = [0u8; 256 / 8];
keccak256.finalize(&mut hash);
hash.to_vec()
}

#[cfg(test)]
mod tests {
use crate::utility;
Expand Down
2 changes: 1 addition & 1 deletion imkey-core/ikc-device/src/device_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub fn bind_test() {
// pub const TEST_KEY_PATH: &str = "/tmp/";
// pub const TEST_BIND_CODE: &str = "MCYNK5AH";
pub const TEST_KEY_PATH: &str = "/tmp/";
pub const TEST_BIND_CODE: &str = "DJKP4NUR";
pub const TEST_BIND_CODE: &str = "B97Q5QB6";

#[cfg(test)]
mod test {
Expand Down
9 changes: 9 additions & 0 deletions imkey-core/ikc-proto/src/eth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ message EthMessageInput {

message EthMessageOutput {
string signature = 1;
}

message EthBatchMessageInput {
repeated string messages = 1;
bool isPersonalSign = 2;
}

message EthBatchMessageOutput {
repeated string signatures = 1;
}
8 changes: 4 additions & 4 deletions imkey-core/ikc-transport/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ pub fn send_apdu_timeout(apdu: String, timeout: i32) -> Result<String> {

#[test]
fn test_rwlock() {
let r1 = TEST.read().unwrap();
let r1 = TEST.read();
println!("test:{}", *r1);

let r2 = TEST.read().unwrap();
let r2 = TEST.read();
println!("test:{}", *r2);
drop(r1);
drop(r2);

let mut w = TEST.write().unwrap();
let mut w = TEST.write();
*w = "haha".to_string();
println!("test:{}", *w);
drop(w);
}

#[test]
fn test_callback() {
let callback = CALLBACK.lock().unwrap();
let callback = CALLBACK.lock();
let ptr = callback(
CString::new("00A4040000".to_owned()).unwrap().into_raw(),
20,
Expand Down
12 changes: 12 additions & 0 deletions imkey-core/ikc-wallet/coin-ethereum/src/ethapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ pub struct EthMessageOutput {
#[prost(string, tag = "1")]
pub signature: std::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EthBatchMessageInput {
#[prost(string, repeated, tag = "1")]
pub messages: ::std::vec::Vec<std::string::String>,
#[prost(bool, tag = "2")]
pub is_personal_sign: bool,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EthBatchMessageOutput {
#[prost(string, repeated, tag = "1")]
pub signatures: ::std::vec::Vec<std::string::String>,
}
Loading