From 0cbd5328e9cc6b6ec7da9ccd28fd9af0692582c1 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 3 Jun 2024 17:21:37 -0500 Subject: [PATCH 1/3] ci: update ubuntu to 22.04, fix openssl ripemd160 config --- .github/workflows/main.yml | 5 +++-- ci/openssl.cnf | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 ci/openssl.cnf diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dab5ea7..61bbf4a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,6 +9,7 @@ on: env: CARGO_TERM_COLOR: always + OPENSSL_CONF: ci/openssl.cnf jobs: fmt: @@ -36,7 +37,7 @@ jobs: - name: Clippy run: cargo clippy --all-features -- -D warnings test-emulators: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: matrix: rust: @@ -89,7 +90,7 @@ jobs: - name: Wipe run: cargo test test_wipe_device -- --ignored test-readme-examples: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: checkout uses: actions/checkout@v2 diff --git a/ci/openssl.cnf b/ci/openssl.cnf new file mode 100644 index 0000000..9b4b0de --- /dev/null +++ b/ci/openssl.cnf @@ -0,0 +1,14 @@ +openssl_conf = openssl_init + +[openssl_init] +providers = provider_sect + +[provider_sect] +default = default_sect +legacy = legacy_sect + +[default_sect] +activate = 1 + +[legacy_sect] +activate = 1 \ No newline at end of file From dd3e6d93dd9f655ac2fa36d49f48e53c9cc1eed5 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Tue, 28 May 2024 20:48:26 -0500 Subject: [PATCH 2/3] ci(speculos): set version to 0.8.3, fix clippy --- .github/workflows/main.yml | 13 ++----------- ci/Dockerfile.ledger | 2 +- clippy.toml | 2 +- src/lib.rs | 17 +++++++++-------- src/types.rs | 11 +++++++---- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 61bbf4a..9a0f4d7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,17 +59,8 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: ci/ - file: ci/Dockerfile.${{ matrix.emulator.name }} - tags: hwi/${{ matrix.emulator.name }}_emulator:latest - load: true - cache-from: type=gha - cache-to: type=gha + - name: Build simulator image + run: docker build -t hwi/${{ matrix.emulator.name }}_emulator:latest ./ci -f ci/Dockerfile.${{ matrix.emulator.name }} - name: Run simulator image run: docker run --name simulator --network=host hwi/${{ matrix.emulator.name }}_emulator & - name: Install Python diff --git a/ci/Dockerfile.ledger b/ci/Dockerfile.ledger index b593664..c73008f 100644 --- a/ci/Dockerfile.ledger +++ b/ci/Dockerfile.ledger @@ -1,4 +1,4 @@ -FROM ghcr.io/ledgerhq/speculos +FROM ghcr.io/ledgerhq/speculos:0.8.3 RUN apt-get update RUN apt-get install wget -y diff --git a/clippy.toml b/clippy.toml index 516ad1f..69478ce 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv="1.48.0" +msrv="1.63.0" diff --git a/src/lib.rs b/src/lib.rs index d986b1c..69c00cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ #[cfg(test)] #[macro_use] extern crate serial_test; +extern crate core; pub use interface::HWIClient; @@ -58,7 +59,7 @@ mod tests { #[serial] fn test_enumerate() { let devices = HWIClient::enumerate().unwrap(); - assert!(devices.len() > 0); + assert!(!devices.is_empty()); } #[test] @@ -82,7 +83,7 @@ mod tests { .expect("No devices found. Either plug in a hardware wallet, or start a simulator.") .as_ref() .expect("Error when opening the first device"); - HWIClient::get_client(&device, true, TESTNET).unwrap() + HWIClient::get_client(device, true, TESTNET).unwrap() } #[test] @@ -118,8 +119,8 @@ mod tests { let client = get_first_device(); let account = Some(10); let descriptor = client.get_descriptors::(account).unwrap(); - assert!(descriptor.internal.len() > 0); - assert!(descriptor.receive.len() > 0); + assert!(!descriptor.internal.is_empty()); + assert!(!descriptor.receive.is_empty()); } #[test] @@ -140,8 +141,8 @@ mod tests { let descriptor = client .get_descriptors::>(account) .unwrap(); - assert!(descriptor.internal.len() > 0); - assert!(descriptor.receive.len() > 0); + assert!(!descriptor.internal.is_empty()); + assert!(!descriptor.receive.is_empty()); } #[test] @@ -198,7 +199,7 @@ mod tests { fn test_sign_tx() { let devices = HWIClient::enumerate().unwrap(); let device = devices.first().unwrap().as_ref().unwrap(); - let client = HWIClient::get_client(&device, true, TESTNET).unwrap(); + let client = HWIClient::get_client(device, true, TESTNET).unwrap(); let derivation_path = DerivationPath::from_str("m/44'/1'/0'/0/0").unwrap(); let address = client @@ -236,7 +237,7 @@ mod tests { input: vec![previous_txin], output: vec![TxOut { value: Amount::from_sat(50), - script_pubkey: script_pubkey, + script_pubkey, }], }, xpub: Default::default(), diff --git a/src/types.rs b/src/types.rs index 4f368ef..db8ef8e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,6 @@ +use core::fmt; use std::convert::TryFrom; +use std::fmt::{Display, Formatter}; use std::ops::Deref; use std::str::FromStr; @@ -260,9 +262,9 @@ where } } -impl ToString for HWIDeviceType { - fn to_string(&self) -> String { - match self { +impl Display for HWIDeviceType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let name = match self { Self::Ledger => String::from("ledger"), Self::Trezor => String::from("trezor"), Self::BitBox01 => String::from("digitalbitbox"), @@ -271,7 +273,8 @@ impl ToString for HWIDeviceType { Self::Coldcard => String::from("coldcard"), Self::Jade => String::from("jade"), Self::Other(name) => name.to_string(), - } + }; + fmt::Display::fmt(&name, f) } } From d70bd9add7ae4900c065c1978094db97f72bab73 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 3 Jun 2024 16:34:41 -0500 Subject: [PATCH 3/3] deps(pyo3): update to 0.21.2 --- Cargo.toml | 2 +- src/interface.rs | 7 ++++--- src/types.rs | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 53ec9d6..942b65c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" bitcoin = { version = "0.31.0", features = ["serde", "base64"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0" } -pyo3 = { version = "0.15.1", features = ["auto-initialize"] } +pyo3 = { version = "0.21.2", features = ["auto-initialize"] } miniscript = { version = "11.0", features = ["serde"], optional = true } diff --git a/src/interface.rs b/src/interface.rs index f5745cb..c816bfb 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -36,8 +36,9 @@ struct HWILib { impl HWILib { pub fn initialize() -> Result { Python::with_gil(|py| { - let commands: Py = PyModule::import(py, "hwilib.commands")?.into(); - let json_dumps: Py = PyModule::import(py, "json")?.getattr("dumps")?.into(); + let commands: Py = PyModule::import_bound(py, "hwilib.commands")?.into(); + let json_dumps: Py = + PyModule::import_bound(py, "json")?.getattr("dumps")?.into(); Ok(HWILib { commands, json_dumps, @@ -497,7 +498,7 @@ impl HWIClient { pub fn get_version() -> Option { Python::with_gil(|py| { Some( - PyModule::import(py, "hwilib") + PyModule::import_bound(py, "hwilib") .ok()? .getattr("__version__") .expect("Should have a __version__") diff --git a/src/types.rs b/src/types.rs index db8ef8e..db25a24 100644 --- a/src/types.rs +++ b/src/types.rs @@ -15,6 +15,7 @@ use serde::{Deserialize, Deserializer}; #[cfg(feature = "miniscript")] use miniscript::{Descriptor, DescriptorPublicKey}; +use pyo3::prelude::PyAnyMethods; use crate::error::{Error, ErrorCode}; @@ -113,7 +114,7 @@ pub enum HWIAddressType { impl IntoPy for HWIAddressType { fn into_py(self, py: pyo3::Python) -> PyObject { - let addrtype = PyModule::import(py, "hwilib.common") + let addrtype = PyModule::import_bound(py, "hwilib.common") .unwrap() .getattr("AddressType") .unwrap(); @@ -133,7 +134,7 @@ impl IntoPy for HWIChain { fn into_py(self, py: pyo3::Python) -> PyObject { use bitcoin::Network::*; - let chain = PyModule::import(py, "hwilib.common") + let chain = PyModule::import_bound(py, "hwilib.common") .unwrap() .getattr("Chain") .unwrap();