Skip to content

Commit

Permalink
Merge branch 'master' into add-pin-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
coinsurenz committed Feb 10, 2024
2 parents 40fb787 + 892e329 commit 0995a72
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitcoin = { version = "0.30.0", features = ["serde", "base64"] }
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"] }

miniscript = { version = "10.0", features = ["serde"], optional = true }
miniscript = { version = "11.0", features = ["serde"], optional = true }

[dev-dependencies]
serial_test = "0.6.0"
Expand Down
12 changes: 9 additions & 3 deletions ci/Dockerfile.trezor
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ FROM rust
RUN rustup toolchain install nightly
RUN rustup default nightly
RUN apt-get update
RUN apt-get install scons libsdl2-dev python3 python3-pip libsdl2-image-dev llvm-dev libclang-dev clang protobuf-compiler libusb-1.0-0-dev -y
RUN git clone --recursive -b core/v2.5.3 https://github.com/trezor/trezor-firmware/ trezor-firmware
RUN apt-get install scons libsdl2-dev python3 python3-pip python3-poetry libsdl2-image-dev llvm-dev libclang-dev clang protobuf-compiler libusb-1.0-0-dev -y
RUN git clone --recursive -b core/v2.6.4 https://github.com/trezor/trezor-firmware/ trezor-firmware
WORKDIR /trezor-firmware/core
RUN pip install poetry

# pyblake2 broken on 3.11, trezor-firmware does not use it but depends on it => remove it as dependency
RUN sed -i "/pyblake.*/d" ../pyproject.toml

# build wrapt 1.13.3 fails => update to 1.14.1
RUN poetry add "wrapt==1.14.1"

RUN poetry install
RUN poetry run make build_unix
CMD ["poetry", "run", "./emu.py", "--headless", "--slip0014", "-q"]
7 changes: 2 additions & 5 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Deref;
use std::process::Command;

use bitcoin::bip32::DerivationPath;
use bitcoin::psbt::PartiallySignedTransaction;
use bitcoin::Psbt;

use serde::de::DeserializeOwned;
use serde_json::value::Value;
Expand Down Expand Up @@ -205,10 +205,7 @@ impl HWIClient {
}

/// Signs a PSBT.
pub fn sign_tx(
&self,
psbt: &PartiallySignedTransaction,
) -> Result<HWIPartiallySignedTransaction, Error> {
pub fn sign_tx(&self, psbt: &Psbt) -> Result<HWIPartiallySignedTransaction, Error> {
Python::with_gil(|py| {
let output = self
.hwilib
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod tests {
use bitcoin::locktime::absolute;
use bitcoin::psbt::{Input, Output};
use bitcoin::{secp256k1, Transaction};
use bitcoin::{Network, TxIn, TxOut};
use bitcoin::{transaction, Amount, Network, TxIn, TxOut};

#[cfg(feature = "miniscript")]
use miniscript::{Descriptor, DescriptorPublicKey};
Expand Down Expand Up @@ -217,11 +217,11 @@ mod tests {
let script_pubkey = address.address.assume_checked().script_pubkey();

let previous_tx = Transaction {
version: 1,
version: transaction::Version::ONE,
lock_time: absolute::LockTime::from_consensus(0),
input: vec![TxIn::default()],
output: vec![TxOut {
value: 100,
value: Amount::from_sat(100),
script_pubkey: script_pubkey.clone(),
}],
};
Expand All @@ -233,13 +233,13 @@ mod tests {
},
..Default::default()
};
let psbt = bitcoin::psbt::PartiallySignedTransaction {
let psbt = bitcoin::Psbt {
unsigned_tx: Transaction {
version: 1,
version: transaction::Version::ONE,
lock_time: absolute::LockTime::from_consensus(0),
input: vec![previous_txin],
output: vec![TxOut {
value: 50,
value: Amount::from_sat(50),
script_pubkey: script_pubkey,
}],
},
Expand Down
24 changes: 12 additions & 12 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::ops::Deref;
use std::str::FromStr;

use bitcoin::address::{Address, NetworkUnchecked};
use bitcoin::base64;
use bitcoin::bip32::{ExtendedPubKey, Fingerprint};
use bitcoin::psbt::PartiallySignedTransaction;
use bitcoin::bip32::{Fingerprint, Xpub};
use bitcoin::Network;
use bitcoin::Psbt;

use pyo3::types::PyModule;
use pyo3::{IntoPy, PyObject};
Expand All @@ -19,11 +18,11 @@ use crate::error::{Error, ErrorCode};

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
pub struct HWIExtendedPubKey {
pub xpub: ExtendedPubKey,
pub xpub: Xpub,
}

impl Deref for HWIExtendedPubKey {
type Target = ExtendedPubKey;
type Target = Xpub;

fn deref(&self) -> &Self::Target {
&self.xpub
Expand All @@ -37,8 +36,11 @@ pub struct HWISignature {
}

fn from_b64<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<u8>, D::Error> {
use bitcoin::base64::{engine::general_purpose, Engine as _};

let b64_string = String::deserialize(d)?;
base64::decode(b64_string)
general_purpose::STANDARD
.decode(b64_string)
.map_err(|_| serde::de::Error::custom("error while deserializing signature"))
}

Expand All @@ -58,18 +60,16 @@ pub struct HWIAddress {
#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
pub struct HWIPartiallySignedTransaction {
#[serde(deserialize_with = "deserialize_psbt")]
pub psbt: PartiallySignedTransaction,
pub psbt: Psbt,
}

fn deserialize_psbt<'de, D: Deserializer<'de>>(
d: D,
) -> Result<PartiallySignedTransaction, D::Error> {
fn deserialize_psbt<'de, D: Deserializer<'de>>(d: D) -> Result<Psbt, D::Error> {
let s = String::deserialize(d)?;
PartiallySignedTransaction::from_str(&s).map_err(serde::de::Error::custom)
Psbt::from_str(&s).map_err(serde::de::Error::custom)
}

impl Deref for HWIPartiallySignedTransaction {
type Target = PartiallySignedTransaction;
type Target = Psbt;

fn deref(&self) -> &Self::Target {
&self.psbt
Expand Down

0 comments on commit 0995a72

Please sign in to comment.