Skip to content

Commit

Permalink
Merge branch 'update-btc-deps'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Nov 29, 2023
2 parents fe0475b + 57e9f70 commit 7c9170a
Show file tree
Hide file tree
Showing 529 changed files with 44,503 additions and 49,415 deletions.
89 changes: 29 additions & 60 deletions src/rust/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 src/rust/bitbox02-rust-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ util = { path = "../util" }
hex = { version = "0.4", default-features = false }
sha2 = { version = "0.10.8", default-features = false, optional = true }
sha3 = { version = "0.10.8", default-features = false, optional = true }
bitcoin = { version = "0.30.0", default-features = false, features = ["no-std"], optional = true }
bitcoin = { version = "0.31.0", default-features = false, features = ["no-std"], optional = true }

[features]
# Only one of the "target-" should be activated, which in turn defines/activates the dependent features.
Expand Down
10 changes: 7 additions & 3 deletions src/rust/bitbox02-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ zeroize = "1.6.0"
num-bigint = { version = "0.4.3", default-features = false, optional = true }
num-traits = { version = "0.2", default-features = false, optional = true }
bip32-ed25519 = { git = "https://github.com/digitalbitbox/rust-bip32-ed25519", tag = "v0.1.2", optional = true }
bech32 = { version = "0.9", default-features = false, optional = true }
bech32 = { version = "0.10.0-beta", default-features = false, optional = true }
blake2 = { version = "0.10.6", default-features = false, optional = true }
minicbor = { version = "0.20.0", default-features = false, features = ["alloc"], optional = true }
crc = { version = "3.0.1", optional = true }
Expand All @@ -47,8 +47,12 @@ lazy_static = { version = "1.4.0", optional = true }
async-recursion = "1.0.5"
hmac = { version = "0.12.1", default-features = false, features = ["reset"] }

miniscript = { version = "10.0.0", default-features = false, features = ["no-std"], optional = true }
bitcoin = { version = "0.30.0", default-features = false, features = ["no-std"], optional = true }
miniscript = { version = "11.0.0", default-features = false, features = ["no-std"], optional = true }
bitcoin = { version = "0.31.0", default-features = false, features = ["no-std"], optional = true }
# We don't rely on this dep directly, the miniscript/bitcoin deps do. We list it here to enable the
# small-hash feature to reduce the binary size, saving around 2784 bytes (as measured at time of
# writing, this might fluctuate over time).
bitcoin_hashes = { version = "0.13.0", default-features = false, features = ["small-hash"] }

[dependencies.prost]
# keep version in sync with tools/prost-build/Cargo.toml.
Expand Down
12 changes: 4 additions & 8 deletions src/rust/bitbox02-rust/src/hww/api/bitcoin/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryFrom;

use bech32::{ToBase32, Variant};

use pb::btc_script_config::SimpleType;
pub use pb::btc_sign_init_request::FormatUnit;
pub use pb::{BtcCoin, BtcOutputType};
Expand Down Expand Up @@ -305,14 +303,12 @@ fn encode_segwit_addr(
witness_version: u8,
witness_program: &[u8],
) -> Result<String, ()> {
let variant = match witness_version {
0 => Variant::Bech32,
1 => Variant::Bech32m,
let version = match witness_version {
0 => bech32::segwit::VERSION_0,
1 => bech32::segwit::VERSION_1,
_ => return Err(()),
};
let mut b32 = witness_program.to_base32();
b32.insert(0, bech32::u5::try_from_u8(witness_version).or(Err(()))?);
bech32::encode(hrp, &b32, variant).or(Err(()))
bech32::segwit::encode(&bech32::Hrp::parse_unchecked(hrp), version, witness_program).or(Err(()))
}

#[cfg(test)]
Expand Down
18 changes: 9 additions & 9 deletions src/rust/bitbox02-rust/src/hww/api/cardano/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ use pb::cardano_response::Response;
use pb::cardano_script_config::Config;
use pb::CardanoNetwork;

use bech32::{FromBase32, ToBase32, Variant};

use blake2::{
digest::{Update, VariableOutput},
Blake2bVar,
Expand All @@ -44,11 +42,14 @@ pub const ADDRESS_HASH_SIZE: usize = 28;
/// https://github.com/cardano-foundation/CIPs/blob/0081c890995ff94618145ae5beb7f288c029a86a/CIP-0019/CIP-0019.md#shelley-addresses
/// See also: https://github.com/input-output-hk/cardano-ledger-specs/blob/d0aa86ded0b973b09b629e5aa62aa1e71364d088/eras/alonzo/test-suite/cddl-files/alonzo.cddl#L119-L127
fn decode_shelley_payment_address(params: &params::Params, address: &str) -> Result<Vec<u8>, ()> {
let (hrp, data, variant) = bech32::decode(address).or(Err(()))?;
if variant != Variant::Bech32 || hrp != params.bech32_hrp_payment {
let result =
bech32::primitives::decode::CheckedHrpstring::new::<bech32::Bech32>(address).or(Err(()))?;
// TODO: use `result.hrp().as_str()` once bech32 has a new release.
let hrp: String = result.hrp().char_iter().collect();
if hrp != params.bech32_hrp_payment {
return Err(());
}
let data = Vec::from_base32(&data).or(Err(()))?;
let data: Vec<u8> = result.byte_iter().collect();
if data.is_empty() {
return Err(());
}
Expand Down Expand Up @@ -189,10 +190,9 @@ pub fn validate_and_encode_payment_address(
bytes.extend_from_slice(&payment_key_hash);
bytes.extend_from_slice(&stake_key_hash);

Ok(bech32::encode(
params.bech32_hrp_payment,
bytes.to_base32(),
Variant::Bech32,
Ok(bech32::encode::<bech32::Bech32>(
bech32::Hrp::parse_unchecked(params.bech32_hrp_payment),
&bytes,
)
.unwrap())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryFrom;

use bech32::{ToBase32, Variant};
use blake2::{
digest::{Update, VariableOutput},
Blake2bVar,
Expand Down Expand Up @@ -92,7 +91,7 @@ fn format_asset(policy_id: &[u8], asset_name: &[u8]) -> String {
hasher.update(asset_name);
let mut hash = [0u8; 20];
hasher.finalize_variable(&mut hash).unwrap();
bech32::encode("asset", hash.to_base32(), Variant::Bech32).unwrap()
bech32::encode::<bech32::Bech32>(bech32::Hrp::parse_unchecked("asset"), &hash).unwrap()
}

/// Validate size limits in the asset groups and that there are no duplicate assets.
Expand Down
1 change: 0 additions & 1 deletion src/rust/vendor/ahash/.cargo-checksum.json

This file was deleted.

Loading

0 comments on commit 7c9170a

Please sign in to comment.