Skip to content

Commit

Permalink
feat: eth batch message signing interface code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoguang1010 committed Sep 14, 2023
1 parent 46fe33d commit 0f4cb33
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
1 change: 1 addition & 0 deletions imkey-core/ikc-common/src/apdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ impl ApduCheck {
"F080" => Err(ApduError::ImkeyInMenuPage.into()),
"F081" => Err(ApduError::ImkeyPinNotVerified.into()),
"6F01" => Err(ApduError::ImkeyBluetoothChannelError.into()),
"6944" => Err(ApduError::ImkeySignatureCancelled.into()),
_ => Err(format_err!("imkey_command_execute_fail_{}", response_data)), //Err(ApduError::ImkeyCommandExecuteFail.into())
}
}
Expand Down
4 changes: 2 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:10443/imkey";
pub const URL: &str = "https://imkey.online:1000/imkey";
// pub const URL: &str = "https://imkeyserver.com:10444/imkey";

pub const TSM_ACTION_SE_SECURE_CHECK: &str = "/seSecureCheck";
pub const TSM_ACTION_APP_DOWNLOAD: &str = "/appDownload";
Expand Down
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 @@ -34,6 +34,8 @@ pub enum ApduError {
ImkeyInMenuPage,
#[fail(display = "imkey_pin_not_verified")]
ImkeyPinNotVerified,
#[fail(display = "imkey_signature_cancelled")]
ImkeySignatureCancelled,
}

#[derive(Fail, Debug, PartialOrd, PartialEq)]
Expand Down
31 changes: 11 additions & 20 deletions imkey-core/ikc-wallet/coin-ethereum/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,7 @@ impl Transaction {
sign_data.extend(message);
let hash = keccak_256_hash(&sign_data.as_ref());

let key_manager_obj = KEY_MANAGER.lock();
let sdk_prikey_signature = secp256k1_sign(&key_manager_obj.pri_key, &hash)?;

let mut data: Vec<u8> = Vec::new();
//signature
let tlv_signature = gen_tlv_data(0x00, sdk_prikey_signature.as_slice())?;
data.extend(tlv_signature);
//hash
data.extend(gen_tlv_data(0x01, &hash)?);
//path
Expand All @@ -425,9 +419,18 @@ impl Transaction {
//total number
data.extend(tlv_total_number.clone());

let key_manager_obj = KEY_MANAGER.lock();
let sdk_prikey_signature = secp256k1_sign(&key_manager_obj.pri_key, &data)?;

let mut req_data = vec![];
//signature
let tlv_signature = gen_tlv_data(0x00, sdk_prikey_signature.as_slice())?;
req_data.extend(tlv_signature);
req_data.extend(data);

let p1 = if index == 0 { 0x00 } else { 0x80 };
let p2 = if index == sign_number - 1 { 0x80 } else { 0x00 };
let sign_apdu = EthApdu::batch_personal_sign(p1, p2, data);
let sign_apdu = EthApdu::batch_personal_sign(p1, p2, req_data);

let sign_response = send_apdu(sign_apdu)?;
ApduCheck::check_response(&sign_response)?;
Expand Down Expand Up @@ -1433,26 +1436,14 @@ mod tests {
is_personal_sign: true,
messages,
};
let start_time = std::time::SystemTime::now();
let output = Transaction::batch_message_sign(input, &sign_param);
let end_time = std::time::SystemTime::now();
let elapsed_time = end_time.duration_since(start_time).unwrap();
let total_seconds = elapsed_time.as_secs();
let hours = total_seconds / 3600;
let minutes = (total_seconds % 3600) / 60;
let seconds = total_seconds % 60;

println!(
"Elapsed time: {} hours, {} minutes, {} seconds",
hours, minutes, seconds
);
assert!(output.is_ok());
let output = output.unwrap();
assert_eq!(
output.signatures[0],
"d928f76ad80d63003c189b095078d94ae068dc2f18a5cafd97b3a630d7bc47465bd6f1e74de2e88c05b271e1c5a8b93564d9d8842c207482b20634d68f2d54e51b".to_string()
);
assert_eq!(output.signatures.len(), 100);
assert_eq!(output.signatures.len(), 500);
}

#[test]
Expand Down

0 comments on commit 0f4cb33

Please sign in to comment.