Skip to content

Commit

Permalink
Update bitcoin to v0.28.0 (#2160)
Browse files Browse the repository at this point in the history
  • Loading branch information
romac authored May 2, 2022
1 parent 3e3b665 commit 1640910
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ futures = "0.3.21"
crossbeam-channel = "0.5.4"
k256 = { version = "0.10.4", features = ["ecdsa-core", "ecdsa", "sha256"]}
hex = "0.4"
bitcoin = { version = "=0.27", features = ["use-serde"] }
bitcoin = { version = "=0.28", features = ["use-serde"] }
tiny-bip39 = "0.8.0"
hdpath = { version = "0.6.0" }
sha2 = "0.10.2"
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/chain/cosmos/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn sign_tx(
fn encode_key_bytes(key: &KeyEntry) -> Result<Vec<u8>, Error> {
let mut pk_buf = Vec::new();

prost::Message::encode(&key.public_key.public_key.to_bytes(), &mut pk_buf)
prost::Message::encode(&key.public_key.to_pub().to_bytes(), &mut pk_buf)
.map_err(|e| Error::protobuf_encode("PublicKey".into(), e))?;

Ok(pk_buf)
Expand Down
16 changes: 9 additions & 7 deletions relayer/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl KeyEntry {

// Decode the private key from the mnemonic
let private_key = private_key_from_mnemonic(&key_file.mnemonic, hd_path)?;
let derived_pubkey = ExtendedPubKey::from_private(&Secp256k1::new(), &private_key);
let derived_pubkey_bytes = derived_pubkey.public_key.to_bytes();
let derived_pubkey = ExtendedPubKey::from_priv(&Secp256k1::new(), &private_key);
let derived_pubkey_bytes = derived_pubkey.to_pub().to_bytes();
assert!(derived_pubkey_bytes.len() <= keyfile_pubkey_bytes.len());

// FIXME: For some reason that is currently unclear, the public key decoded from
Expand Down Expand Up @@ -334,7 +334,7 @@ impl KeyRing {
let private_key = private_key_from_mnemonic(mnemonic_words, hd_path)?;

// Get the public Key from the private key
let public_key = ExtendedPubKey::from_private(&Secp256k1::new(), &private_key);
let public_key = ExtendedPubKey::from_priv(&Secp256k1::new(), &private_key);

// Get address from the public Key
let address = get_address(public_key, at);
Expand Down Expand Up @@ -377,7 +377,7 @@ pub fn sign_message(
msg: Vec<u8>,
address_type: &AddressType,
) -> Result<Vec<u8>, Error> {
let private_key_bytes = key.private_key.private_key.to_bytes();
let private_key_bytes = key.private_key.to_priv().to_bytes();
match address_type {
AddressType::Ethermint { ref pk_type } if pk_type.ends_with(".ethsecp256k1.PubKey") => {
let hash = keccak256_hash(msg.as_slice());
Expand All @@ -386,7 +386,9 @@ pub fn sign_message(
let sign_msg = Message::from_slice(hash.as_slice()).unwrap();
let key = SecretKey::from_slice(private_key_bytes.as_slice())
.map_err(Error::invalid_key_raw)?;
let (_, sig_bytes) = s.sign_recoverable(&sign_msg, &key).serialize_compact();
let (_, sig_bytes) = s
.sign_ecdsa_recoverable(&sign_msg, &key)
.serialize_compact();
Ok(sig_bytes.to_vec())
}
AddressType::Cosmos | AddressType::Ethermint { .. } => {
Expand Down Expand Up @@ -425,7 +427,7 @@ fn private_key_from_mnemonic(
fn get_address(pk: ExtendedPubKey, at: &AddressType) -> Vec<u8> {
match at {
AddressType::Ethermint { ref pk_type } if pk_type.ends_with(".ethsecp256k1.PubKey") => {
let public_key = pk.public_key.key.serialize_uncompressed();
let public_key = pk.public_key.serialize_uncompressed();
// 0x04 is [SECP256K1_TAG_PUBKEY_UNCOMPRESSED](https://github.com/bitcoin-core/secp256k1/blob/d7ec49a6893751f068275cc8ddf4993ef7f31756/include/secp256k1.h#L196)
debug_assert_eq!(public_key[0], 0x04);

Expand All @@ -436,7 +438,7 @@ fn get_address(pk: ExtendedPubKey, at: &AddressType) -> Vec<u8> {
}
AddressType::Cosmos | AddressType::Ethermint { .. } => {
let mut hasher = Sha256::new();
hasher.update(pk.public_key.to_bytes().as_slice());
hasher.update(pk.to_pub().to_bytes().as_slice());

// Read hash digest over the public key bytes & consume hasher
let pk_hash = hasher.finalize();
Expand Down

0 comments on commit 1640910

Please sign in to comment.