From 598b9d9b6d30782ca2a87ab2d19ad27923d7d1c9 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 29 May 2023 15:22:09 +0200 Subject: [PATCH] chore: bump dependencies --- .github/workflows/tests.yaml | 101 +++++++++++++++----------------- .gitignore | 4 +- bip32/Cargo.toml | 18 +++--- bip32/src/lib.rs | 4 -- bip39/Cargo.toml | 24 ++++---- bip39/src/lib.rs | 4 -- bip39/src/mnemonic.rs | 14 ++--- bip39/src/wordlist/mod.rs | 23 +++++--- core/Cargo.toml | 18 +++--- core/src/enc.rs | 4 +- ledger/Cargo.toml | 54 ++++++++--------- ledger/src/transports/hid.rs | 9 ++- ledger/src/transports/mod.rs | 43 +++++++------- ledger/src/transports/native.rs | 4 +- ledger/src/transports/wasm.rs | 10 +++- 15 files changed, 161 insertions(+), 173 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 508c78ba..3cd10780 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -15,75 +15,66 @@ env: CARGO_TERM_COLOR: always jobs: - build: + test: + name: test ${{ matrix.features }} runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + features: ["", "--no-default-features"] steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: Swatinem/rust-cache@v1 - with: - cache-on-failure: true - - - name: Build - run: cargo build --verbose - - name: Build (no default features) - run: cargo build --verbose --no-default-features --locked + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - run: cargo test ${{ matrix.features }} wasm: - name: Build WASM + name: check WASM runs-on: ubuntu-latest steps: - - name: Checkout sources - uses: actions/checkout@v2 - - name: Install rust - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable with: - toolchain: stable target: wasm32-unknown-unknown - profile: minimal - override: true + - uses: Swatinem/rust-cache@v2 + - name: check + run: | + cargo check \ + --target wasm32-unknown-unknown \ + --no-default-features \ + --features browser - - uses: Swatinem/rust-cache@v1 - with: - cache-on-failure: true - - - name: Check - uses: actions-rs/cargo@v1 - with: - command: build - args: --verbose --target wasm32-unknown-unknown --no-default-features --features "browser" + clippy: + name: clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@clippy + - name: clippy + run: cargo clippy --workspace --all-targets + env: + RUSTFLAGS: "-D warnings" - test: + docs: + name: docs runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: Swatinem/rust-cache@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly with: - cache-on-failure: true + components: rust-docs + - name: doc + run: cargo doc --workspace --no-deps --document-private-items + env: + RUSTDOCFLAGS: "--cfg docsrs -D warnings" - - name: Run tests - run: cargo test --verbose - - lint: + fmt: + name: fmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - profile: minimal - components: rustfmt, clippy - override: true - - uses: Swatinem/rust-cache@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly with: - cache-on-failure: true - - - name: cargo fmt - run: cargo +nightly fmt -- --check - - name: cargo clippy - run: cargo +nightly clippy -- -D warnings + components: rustfmt + - name: fmt --check + run: cargo fmt --all --check diff --git a/.gitignore b/.gitignore index b181f762..a91c45d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ target/ +Cargo.lock + pkg/ pkg-node/ **/*.rs.bk -Cargo.lock tarpaulin-report.html node_modules +.vscode diff --git a/bip32/Cargo.toml b/bip32/Cargo.toml index 3efc4de4..ab631ea0 100644 --- a/bip32/Cargo.toml +++ b/bip32/Cargo.toml @@ -8,24 +8,20 @@ repository = "https://github.com/summa-tx/bitcoins-rs" license = "MIT OR Apache-2.0" [dependencies] -thiserror = "1.0" -hmac = "0.12" -sha2 = "0.10" -bs58 = "0.4.0" coins-core = { version = "0.8.3", path = "../core" } -serde = "1.0.105" -k256 = { version = "0.13", features = ["std", "arithmetic"] } +bs58 = "0.5" digest = "0.10" - -[target.'cfg(target_arch = "wasm32")'.dependencies] -getrandom = { version = "0.2", features = ["js"] } +hmac = "0.12" +k256 = { version = "0.13", features = ["std", "arithmetic"] } +serde = "1.0" +sha2 = "0.10" +thiserror = "1.0" [dev-dependencies] -hex = "0.4.2" +hex = "0.4" [features] default = ["mainnet"] mainnet = [] testnet = [] - diff --git a/bip32/src/lib.rs b/bip32/src/lib.rs index 39c3d079..5762913d 100644 --- a/bip32/src/lib.rs +++ b/bip32/src/lib.rs @@ -173,7 +173,3 @@ impl From for Bip32Error { unimplemented!("unreachable, but required by type system") } } - -// We need to specify the getrandom JS feature, but don't need the crate. -#[cfg(target_arch = "wasm32")] -use getrandom as _; diff --git a/bip39/Cargo.toml b/bip39/Cargo.toml index 133216eb..4b018b7f 100644 --- a/bip39/Cargo.toml +++ b/bip39/Cargo.toml @@ -1,31 +1,31 @@ [package] name = "coins-bip39" version = "0.8.6" -authors = ["Rohit Narurkar ", "James Prestwich ", "0xYYY <0xYYY@pm.me>"] +authors = [ + "Rohit Narurkar ", + "James Prestwich ", + "0xYYY <0xYYY@pm.me>", +] edition = "2018" description = "Bip39 in Rust" -repository = "https://github.com/summa-tx/bitcoins-rs" +repository = "https://github.com/summa-tx/coins" license = "MIT OR Apache-2.0" [dependencies] -bitvec = "0.17.4" coins-bip32 = { version = "0.8.3", path = "../bip32" } + +bitvec = "1.0" hmac = "0.12" pbkdf2 = "0.12" -rand = "0.8.4" +rand = "0.8" sha2 = "0.10" thiserror = "1.0" # used by all wordlists -once_cell = { version = "1.17.1", optional = true} +once_cell = { version = "1.17", optional = true } [dev-dependencies] -hex = "0.4.2" - -[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] -version = "0.2.3" -default-features = false -features=["js"] +hex = "0.4" [features] default = ["all-langs"] @@ -50,4 +50,4 @@ italian = ["dep:once_cell"] japanese = ["dep:once_cell"] korean = ["dep:once_cell"] portuguese = ["dep:once_cell"] -spanish = ["dep:once_cell"] \ No newline at end of file +spanish = ["dep:once_cell"] diff --git a/bip39/src/lib.rs b/bip39/src/lib.rs index d1683fa5..a10caad5 100644 --- a/bip39/src/lib.rs +++ b/bip39/src/lib.rs @@ -21,7 +21,3 @@ pub use self::mnemonic::*; /// Wordlists pub mod wordlist; pub use self::wordlist::*; - -// We need to specify the getrandom JS feature, but don't need the crate. -#[cfg(target_arch = "wasm32")] -use getrandom as _; diff --git a/bip39/src/mnemonic.rs b/bip39/src/mnemonic.rs index a33573fc..ee2b4de4 100644 --- a/bip39/src/mnemonic.rs +++ b/bip39/src/mnemonic.rs @@ -224,7 +224,7 @@ where pub fn new_from_phrase(phrase: &str) -> Result { let words = phrase.split(' ').collect::>(); - let mut entropy: BitVec = BitVec::new(); + let mut entropy: BitVec = BitVec::new(); for word in words { let index = W::get_index(word)?; let index_u8: [u8; 2] = (index as u16).to_be_bytes(); @@ -232,11 +232,11 @@ where // 11-bits per word as per BIP-39, and max index (2047) can be represented in 11-bits. let index_slice = &BitVec::from_slice(&index_u8)[5..]; - entropy.append(&mut BitVec::::from_bitslice(index_slice)); + entropy.append(&mut BitVec::::from_bitslice(index_slice)); } let mnemonic = Self { - entropy: Entropy::from_slice(entropy)?, + entropy: Entropy::from_slice(entropy.as_raw_slice())?, _wordlist: PhantomData, }; @@ -256,12 +256,12 @@ where let mut hasher = Sha256::new(); hasher.update(self.entropy.as_ref()); let hash = hasher.finalize(); - let hash_0 = BitVec::::from_element(hash[0]); + let hash_0 = BitVec::::from_element(hash[0]); let (checksum, _) = hash_0.split_at(length / 3); // Convert the entropy bytes into bits and append the checksum. - let mut encoding = BitVec::::from_slice(self.entropy.as_ref()); - encoding.append(&mut checksum.to_vec()); + let mut encoding = BitVec::::from_slice(self.entropy.as_ref()); + encoding.append(&mut checksum.to_bitvec()); // Compute the phrase in 11 bit chunks which encode an index into the word list let wordlist = W::get_all(); @@ -313,7 +313,7 @@ where } } -#[cfg(test)] +#[cfg(all(test, feature = "english"))] mod tests { use crate::English; use coins_bip32::enc::{MainnetEncoder, XKeyEncoder}; diff --git a/bip39/src/wordlist/mod.rs b/bip39/src/wordlist/mod.rs index 9778a7ad..1133e425 100644 --- a/bip39/src/wordlist/mod.rs +++ b/bip39/src/wordlist/mod.rs @@ -10,43 +10,50 @@ pub mod chinese_simplified; #[cfg(feature = "chinese-simplified")] pub use self::chinese_simplified::ChineseSimplified; -#[cfg(feature = "chinese-traditional")] /// The Chinese (Traditional) wordlist +#[cfg(feature = "chinese-traditional")] pub mod chinese_traditional; #[cfg(feature = "chinese-traditional")] pub use super::chinese_traditional::ChineseTraditional; -#[cfg(feature = "czech")] + /// The Czech wordlist +#[cfg(feature = "czech")] pub mod czech; #[cfg(feature = "czech")] pub use super::czech::Czech; -#[cfg(feature = "french")] + /// The French wordlist +#[cfg(feature = "french")] pub mod french; #[cfg(feature = "french")] pub use super::french::French; -#[cfg(feature = "italian")] + /// The Italian wordlist +#[cfg(feature = "italian")] pub mod italian; #[cfg(feature = "italian")] pub use super::italian::Italian; -#[cfg(feature = "japanese")] + /// The Japanese wordlist +#[cfg(feature = "japanese")] pub mod japanese; #[cfg(feature = "japanese")] pub use super::japanese::Japanese; -#[cfg(feature = "korean")] + /// The Korean wordlist +#[cfg(feature = "korean")] pub mod korean; #[cfg(feature = "korean")] pub use super::korean::Korean; -#[cfg(feature = "portuguese")] + /// The Portuguese wordlist +#[cfg(feature = "portuguese")] pub mod portuguese; #[cfg(feature = "portuguese")] pub use super::portuguese::Portuguese; -#[cfg(feature = "spanish")] + /// The Spanish wordlist +#[cfg(feature = "spanish")] pub mod spanish; #[cfg(feature = "spanish")] pub use super::spanish::Spanish; diff --git a/core/Cargo.toml b/core/Cargo.toml index 673a0652..81f1827f 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -4,21 +4,21 @@ version = "0.8.3" authors = ["James Prestwich "] edition = "2018" description = "Core library for coins-bip32 and coins-bip39" -repository = "https://github.com/summa-tx/bitcoins-rs" +repository = "https://github.com/summa-tx/coins" license = "MIT OR Apache-2.0" [dependencies] -bech32 = "0.7.2" -hex = "0.4.2" +base64 = "0.21" +bech32 = "0.9" +bs58 = { version = "0.5", features = ["check"] } +hex = "0.4" +serde = { version = "1.0", features = ["derive"] } +serde_derive = "1.0" thiserror = "1.0" -base64 = "0.21.0" -serde_derive = "1.0.106" -serde = { version = "1.0.106", features = ["derive"] } -bs58 = { version = "0.4.0", features = ["check"] } # update in parallel -generic-array = "0.14.4" digest = "0.10" +generic-array = "0.14" +ripemd = "0.1" sha2 = "0.10" sha3 = "0.10" -ripemd = "0.1" diff --git a/core/src/enc.rs b/core/src/enc.rs index 5af2f08e..8e4ec7f8 100644 --- a/core/src/enc.rs +++ b/core/src/enc.rs @@ -70,13 +70,13 @@ pub type EncodingResult = Result; pub fn encode_bech32(hrp: &str, v: u8, h: &[u8]) -> EncodingResult { let mut v = vec![u5::try_from_u8(v)?]; v.extend(&h.to_base32()); - b32_encode(hrp, &v).map_err(|v| v.into()) + b32_encode(hrp, &v, bech32::Variant::Bech32).map_err(|v| v.into()) } /// Decode a witness program from a bech32 string. Caller specifies an expected HRP. If a /// different HRP is found, returns `WrongHrp`. pub fn decode_bech32(expected_hrp: &str, s: &str) -> EncodingResult<(u8, Vec)> { - let (hrp, data) = b32_decode(s)?; + let (hrp, data, _variant) = b32_decode(s)?; if hrp != expected_hrp { return Err(EncodingError::WrongHrp { got: hrp, diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index 225bdad4..4b6d9aae 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "coins-ledger" version = "0.8.3" -authors = ["Summa ", "James Prestwich ", "Zondax GmbH "] +authors = [ + "Summa ", + "James Prestwich ", + "Zondax GmbH ", +] edition = "2018" -categories = ["authentication", "cryptography"] +categories = ["authentication", "cryptography"] keywords = ["ledger", "apdu", "cryptocurrency"] -repository = "https://github.com/summa-tx/bitcoins-rs" +repository = "https://github.com/summa-tx/coins" license = "MIT OR Apache-2.0" description = "Ledger Nano X/S connection and communication management library" @@ -13,25 +17,22 @@ description = "Ledger Nano X/S connection and communication management library" crate-type = ["cdylib", "rlib"] [dependencies] -thiserror = "1.0.10" +async-trait = "0.1" +cfg-if = "1.0" +futures = "0.3" +hex = "0.4" serde = { version = "1.0", features = ["derive"] } -futures = "0.3.5" -async-trait = "0.1.3" -tap = "1.0.1" -hex = "0.4.3" +tap = "1.0" +thiserror = "1.0" # native [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -cfg-if = "1.0.0" -lazy_static = "1.3.0" -byteorder = "1.3.1" -libc = "0.2.50" -matches = "0.1.8" -tracing = "0.1.37" - -# native -[target.'cfg(not(target_arch = "wasm32"))'.dependencies.hidapi-rusb] -version = "1.3.2" +lazy_static = "1.4" +byteorder = "1.4" +libc = "0.2" +matches = "0.1" +tracing = "0.1" +hidapi-rusb = "1.3" # linux native only [target.'cfg(target_os = "linux")'.dependencies] @@ -39,19 +40,16 @@ nix = "0.26" # WASM [target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen = "0.2.60" -wasm-bindgen-futures = "0.4.10" -js-sys = "0.3.37" -log = "0.4.11" +wasm-bindgen = "0.2.86" +wasm-bindgen-futures = "0.4.36" +js-sys = "0.3.63" +log = "0.4" +getrandom = { version = "0.2", features = ["js"] } [dev-dependencies] -serial_test = "0.3.2" -tokio = {version = "0.2.22", features = ["rt-threaded", "macros"]} +serial_test = "2" +tokio = { version = "1.28", features = ["rt-multi-thread", "macros"] } [features] browser = [] node = [] - -# https://github.com/rustwasm/wasm-pack/issues/886#issuecomment-667669802 -[package.metadata.wasm-pack.profile.release] -wasm-opt = ["-Oz", "--enable-mutable-globals"] diff --git a/ledger/src/transports/hid.rs b/ledger/src/transports/hid.rs index 09bf6199..7d61cdd5 100644 --- a/ledger/src/transports/hid.rs +++ b/ledger/src/transports/hid.rs @@ -14,8 +14,8 @@ use hidapi_rusb::HidDevice; use std::cell::RefCell; use std::sync::{Arc, Mutex, Weak}; -#[cfg(not(target_os = "linux"))] // Mock the type in other target_os +#[cfg(not(target_os = "linux"))] mod nix { #[derive(thiserror::Error, Debug)] pub enum Error { @@ -34,7 +34,6 @@ const LEDGER_PACKET_SIZE: u8 = 64; const LEDGER_TIMEOUT: i32 = 10_000_000; /// Ledger transport errors -#[cfg(not(target_arch = "wasm32"))] #[derive(Error, Debug)] pub enum NativeTransportError { /// Device not found error @@ -74,9 +73,9 @@ struct HidApiWrapper { _api: RefCell>>, } -#[allow(dead_code)] -/// The transport struct. Holds a `Mutex` on the underlying `HidAPI` instance. Instantiate with -/// `new`. +/// The transport struct. Holds a `Mutex` on the underlying `HidAPI` instance. +/// +/// Instantiate with [`new`][TransportNativeHID::new]. pub struct TransportNativeHID { api_mutex: Arc>, device: HidDevice, diff --git a/ledger/src/transports/mod.rs b/ledger/src/transports/mod.rs index 5f5b1ed5..a695a363 100644 --- a/ledger/src/transports/mod.rs +++ b/ledger/src/transports/mod.rs @@ -1,33 +1,31 @@ //! Abstract ledger tranport trait with WASM and native HID instantiations. -#[doc(hidden)] -#[cfg(not(target_arch = "wasm32"))] -pub mod hid; - -/// APDU Transport wrapper for JS/WASM transports -#[cfg(all(target_arch = "wasm32"))] -pub mod wasm; -#[cfg(all(target_arch = "wasm32"))] -pub use wasm::LedgerTransport as DefaultTransport; - -/// APDU Transport for native HID -#[cfg(not(target_arch = "wasm32"))] -pub mod native; -#[cfg(not(target_arch = "wasm32"))] -pub use native::NativeTransport as DefaultTransport; - -#[cfg(target_arch = "wasm32")] -use log::{debug, error}; -#[cfg(not(target_arch = "wasm32"))] -use tracing::{debug, error}; - use crate::{ common::{APDUAnswer, APDUCommand}, errors::LedgerError, }; - use async_trait::async_trait; +cfg_if::cfg_if! { + if #[cfg(target_arch = "wasm32")] { + /// APDU Transport wrapper for JS/WASM transports. + pub mod wasm; + pub use wasm::LedgerTransport as DefaultTransport; + + use log::{debug, error}; + } else { + /// APDU Transport for native HID. + pub mod hid; + + /// APDU Transport for native HID. Wraps [`hid`]'s + /// [`TransportNativeHID`][hid::TransportNativeHID]. + pub mod native; + pub use native::NativeTransport as DefaultTransport; + + use tracing::{debug, error}; + } +} + /// A Ledger device connection. This wraps the default transport type. In native code, this is /// the `hidapi` library. When the `node` or `browser` feature is selected, it is a Ledger JS /// transport library. @@ -93,6 +91,7 @@ impl LedgerAsync for Ledger { resp } } + /******************************************************************************* * (c) 2020 ZondaX GmbH * diff --git a/ledger/src/transports/native.rs b/ledger/src/transports/native.rs index fe5e328f..9b38c890 100644 --- a/ledger/src/transports/native.rs +++ b/ledger/src/transports/native.rs @@ -8,9 +8,9 @@ use crate::{ pub struct NativeTransport(hid::TransportNativeHID); impl NativeTransport { - /// Instantiate + /// Instantiate a new transport pub fn new() -> Result { - Ok(Self(hid::TransportNativeHID::new()?)) + hid::TransportNativeHID::new().map(Self) } /// Send an APDU command to the device, and receive a response diff --git a/ledger/src/transports/wasm.rs b/ledger/src/transports/wasm.rs index de486900..233f84a0 100644 --- a/ledger/src/transports/wasm.rs +++ b/ledger/src/transports/wasm.rs @@ -1,4 +1,3 @@ -use js_sys; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::JsFuture; @@ -7,8 +6,13 @@ use crate::{ errors::LedgerError, }; -// These conditional compilation blokcs ensure that we try to import the correct transport for our -// environment. +// Compilation would fail either way, since the following `extern "C"` block +// would not be linked to anything +#[cfg(not(any(feature = "node", feature = "browser")))] +compile_error!("Either `node` or `browser` feature must be enabled for WASM transport"); + +// These conditional compilation blocks ensure that we try to import the correct +// transport for our environment. #[cfg_attr( feature = "node", wasm_bindgen(module = "@ledgerhq/hw-transport-node-hid")