Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
bip32 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Apr 17, 2023
1 parent 8dc826a commit 1bc8439
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license-file = "LICENSE"
anyhow = "1.0.70"
base64 = "0.21.0"
bech32 = "0.9.1"
bip32 = { version = "0.4.0", features = ["secp256k1", "bip39"] }
bip32 = { version = "0.5.0", features = ["secp256k1", "bip39"] }
chrono = "0.4.24"
clap = { version = "4.2.2", features = ["derive"] }
cosmos-sdk-proto = { git = "https://github.com/rnbguy/cosmos-rust", branch = "rano/json", features = ["cosmwasm"] }
Expand Down
6 changes: 3 additions & 3 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
},
Result,
};
use bip32::{secp256k1::ecdsa::VerifyingKey, DerivationPath};
use bip32::{secp256k1::ecdsa::VerifyingKey, DerivationPath, PublicKey};
use bip32::{
secp256k1::ecdsa::{signature::Signer, Signature},
PrivateKey,
Expand All @@ -44,12 +44,12 @@ impl KeyStoreBackend {
Self::Os(key) => {
let priv_key = get_priv_key_from_os(key)?;
let signature: Signature = priv_key.try_sign(data).unwrap();
Ok(signature.as_ref().try_into()?)
Ok(signature.to_bytes().try_into()?)
}
Self::Memory(key) => {
let priv_key = get_priv_key_from_memory(key)?;
let signature: Signature = priv_key.try_sign(data).unwrap();
Ok(signature.as_ref().try_into()?)
Ok(signature.to_bytes().try_into()?)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn save_key_to_os_from_mmseed(mmseed: &str, keyname: &str, coin: u64) -> Res
pub fn get_priv_key_from_os(key_name: &str) -> Result<SigningKey> {
let entry = keyring::Entry::new("rover", key_name)?;
let priv_bytes = BASE64_STANDARD.decode(entry.get_password()?)?;
Ok(SigningKey::from_bytes(&priv_bytes).expect("error"))
Ok(SigningKey::from_slice(&priv_bytes).expect("error"))
}

pub fn get_uncompressed_pub_key_from_os(key_name: &str) -> Result<Vec<u8>> {
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn get_priv_key_from_memory(key_name: &str) -> Result<SigningKey> {
let priv_bytes = keyring
.get(key_name)
.context("key is not present in memory")?;
Ok(SigningKey::from_bytes(priv_bytes).expect("error"))
Ok(SigningKey::from_slice(priv_bytes).expect("error"))
}

pub fn get_uncompressed_pub_key_from_memory(key_name: &str) -> Result<Vec<u8>> {
Expand Down
6 changes: 3 additions & 3 deletions src/txs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Context;
use bip32::secp256k1::ecdsa::signature::SignatureEncoding;
use bip32::secp256k1::ecdsa::{signature::Signer, signature::Verifier, Signature};

use cosmos_sdk_proto::cosmos::tx::v1beta1::{AuthInfo, TxBody};
Expand Down Expand Up @@ -88,7 +89,7 @@ where
K: Signer<Signature>,
{
let signature: Signature = priv_key.try_sign(&sign_doc.try_encoded()?).expect("error");
Ok(signature.as_ref().try_into()?)
Ok(signature.to_vec().try_into().expect("64 sized vector"))
}

pub fn update_signature(mut tx: Tx, signature: &[u8; 64]) -> Tx {
Expand Down Expand Up @@ -118,13 +119,12 @@ pub fn verify_transaction<K>(
where
K: Verifier<Signature>,
{
use bip32::secp256k1::ecdsa::signature::Signature;
let sign_doc = crate::txs::generate_sign_doc(signed_tx, chain_id, account_number)?;
let signature = signed_tx.signatures[0].clone();
pub_key
.verify(
&sign_doc.try_encoded()?,
&Signature::from_bytes(&signature).expect("error"),
&Signature::from_slice(&signature).expect("error"),
)
.expect("error");
Ok(())
Expand Down

0 comments on commit 1bc8439

Please sign in to comment.