Skip to content

Commit 90270f7

Browse files
committed
fix(bip322): Re-enable bip322 feature
- update bdk_bip322 crate with replacement crate bdk_message_signer - re-enable bip322 feature - update documentation for add_global_xpubs fn
1 parent aba6c66 commit 90270f7

9 files changed

Lines changed: 272 additions & 263 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ shlex = { version = "1.3.0", optional = true }
3939
payjoin = { version = "0.25.0", features = ["v1", "v2", "io", "_test-utils"], optional = true}
4040
reqwest = { version = "0.13.2", default-features = false, features = ["rustls"], optional = true }
4141
url = { version = "2.5.8", optional = true }
42-
# bdk_bip322 = { version = "0.1.0", optional = true }
42+
bdk_message_signer = { version = "0.2.0", optional = true }
4343
bitcoin-payment-instructions = { version = "0.7.0", optional = true}
4444

4545
[features]
@@ -61,7 +61,7 @@ dns_payment = ["bitcoin-payment-instructions"]
6161

6262
# Internal features
6363
_payjoin-dependencies = ["payjoin", "reqwest", "url", "sqlite"]
64-
# bip322 = ["bdk_bip322"]
64+
bip322 = ["bdk_message_signer"]
6565

6666
# Use this to consensus verify transactions at sync time
6767
verify = []

src/commands.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
//! All subcommands are defined in the below enums.
1414
1515
#![allow(clippy::large_enum_variant)]
16-
// #[cfg(feature = "bip322")]
17-
// use crate::handlers::offline::{SignMessageCommand, VerifyMessageCommand};
16+
#[cfg(feature = "bip322")]
17+
use crate::handlers::offline::{SignMessageCommand, VerifyMessageCommand};
1818
use crate::handlers::{
1919
config::{ListWalletsCommand, SaveConfigCommand},
2020
descriptor::DescriptorCommand,
@@ -362,11 +362,11 @@ pub enum OfflineWalletSubCommand {
362362
/// Combines multiple PSBTs into one.
363363
CombinePsbt(CombinePsbtCommand),
364364
/// Sign a message using BIP322
365-
// #[cfg(feature = "bip322")]
366-
// SignMessage(SignMessageCommand),
365+
#[cfg(feature = "bip322")]
366+
SignMessage(SignMessageCommand),
367367
/// Verify a BIP322 signature
368-
// #[cfg(feature = "bip322")]
369-
// VerifyMessage(VerifyMessageCommand),
368+
#[cfg(feature = "bip322")]
369+
VerifyMessage(VerifyMessageCommand),
370370
/// Lock UTXO(s) so they're excluded from coin selection.
371371
LockUtxo(LockUtxoCommand),
372372
/// Unlock previously locked UTXO(s).

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ pub enum BDKCliError {
155155
#[cfg(feature = "payjoin")]
156156
#[error("Payjoin database error: {0}")]
157157
PayjoinDb(#[from] crate::handlers::payjoin::db::Error),
158-
// #[cfg(feature = "bip322")]
159-
// #[error("BIP-322 error: {0}")]
160-
// Bip322Error(#[from] bdk_bip322::error::Error),
158+
#[cfg(feature = "bip322")]
159+
#[error("BIP-322 error: {0}")]
160+
Bip322Error(#[from] bdk_message_signer::error::Error),
161161
}
162162

163163
impl From<ExtractTxError> for BDKCliError {

src/handlers/offline.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ use {
2828
bdk_wallet::keys::{DescriptorPublicKey, DescriptorSecretKey, SinglePubKey},
2929
std::collections::HashMap,
3030
};
31-
// #[cfg(feature = "bip322")]
32-
// use {
33-
// crate::utils::parse_signature_format,
34-
// crate::utils::types::MessageResult,
35-
// bdk_bip322::{BIP322, MessageProof},
36-
// };
31+
#[cfg(feature = "bip322")]
32+
use {
33+
crate::utils::parse_signature_format,
34+
crate::utils::types::MessageResult,
35+
bdk_message_signer::{MessageProof, MessageSigner},
36+
};
3737

3838
impl OfflineWalletSubCommand {
3939
pub fn execute(&self, ctx: &mut AppContext<OfflineOperations<'_>>) -> Result<(), Error> {
@@ -73,14 +73,14 @@ impl OfflineWalletSubCommand {
7373
Self::CombinePsbt(combine_psbt_command) => combine_psbt_command
7474
.execute(ctx)?
7575
.write_out(std::io::stdout()),
76-
// #[cfg(feature = "bip322")]
77-
// Self::SignMessage(sign_message_command) => sign_message_command
78-
// .execute(ctx)?
79-
// .write_out(std::io::stdout()),
80-
// #[cfg(feature = "bip322")]
81-
// Self::VerifyMessage(verify_message_command) => verify_message_command
82-
// .execute(ctx)?
83-
// .write_out(std::io::stdout()),
76+
#[cfg(feature = "bip322")]
77+
Self::SignMessage(sign_message_command) => sign_message_command
78+
.execute(ctx)?
79+
.write_out(std::io::stdout()),
80+
#[cfg(feature = "bip322")]
81+
Self::VerifyMessage(verify_message_command) => verify_message_command
82+
.execute(ctx)?
83+
.write_out(std::io::stdout()),
8484
Self::LockUtxo(lock_utxo) => lock_utxo.execute(ctx)?.write_out(std::io::stdout()),
8585
Self::UnlockUtxo(unlock_utxo) => unlock_utxo.execute(ctx)?.write_out(std::io::stdout()),
8686
Self::LockedUtxos(locked_utxos) => {
@@ -204,7 +204,7 @@ pub struct CreateTxCommand {
204204
#[arg(long = "enable_rbf", short = 'r', default_value_t = true)]
205205
pub enable_rbf: bool,
206206

207-
/// Make a PSBT that can be signed by offline signers and hardware wallets. Forces the addition of `non_witness_utxo` and more details to let the signer identify the change output.
207+
/// Make a PSBT that can be signed by offline signers and hardware wallets. Forces the addition of `PSBT_GLOBAL_XPUB` and more details to let the signer identify the change output.
208208
#[arg(long = "offline_signer")]
209209
pub offline_signer: bool,
210210

@@ -773,7 +773,6 @@ impl AppCommand<AppContext<OfflineOperations<'_>>> for CombinePsbtCommand {
773773
}
774774
}
775775

776-
/**
777776
#[cfg(feature = "bip322")]
778777
#[derive(Debug, Parser, Clone, PartialEq)]
779778
pub struct SignMessageCommand {
@@ -861,12 +860,11 @@ impl AppCommand<AppContext<OfflineOperations<'_>>> for VerifyMessageCommand {
861860
})
862861
}
863862
}
864-
**/
865863

866864
#[derive(Parser, Debug, Clone, PartialEq)]
867865
pub struct LockUtxoCommand {
868866
/// Outpoint(s) to lock, format TXID:VOUT.
869-
#[arg(env = "TXID:VOUT", long = "utxo", required = true, value_parser = parse_outpoint)]
867+
#[arg(env = "TXID", long = "utxo", required = true, value_parser = parse_outpoint)]
870868
pub utxos: Vec<OutPoint>,
871869
}
872870

@@ -891,7 +889,7 @@ impl AppCommand<AppContext<OfflineOperations<'_>>> for LockUtxoCommand {
891889
#[derive(Parser, Debug, Clone, PartialEq)]
892890
pub struct UnlockUtxoCommand {
893891
/// Outpoint(s) to unlock, format TXID:VOUT.
894-
#[arg(env = "TXID:VOUT", long = "utxo", required = true, value_parser = parse_outpoint)]
892+
#[arg(env = "TXID", long = "utxo", required = true, value_parser = parse_outpoint)]
895893
pub utxos: Vec<OutPoint>,
896894
}
897895

src/utils/common.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{commands::WalletOpts, config::WalletConfig, error::BDKCliError as Error};
2-
// #[cfg(feature = "bip322")]
3-
// use bdk_bip322::SignatureFormat;
42
#[cfg(feature = "cbf")]
53
use bdk_kyoto::{Info, Receiver, UnboundedReceiver, Warning};
4+
#[cfg(feature = "bip322")]
5+
use bdk_message_signer::SignatureFormat;
66
#[cfg(feature = "silent-payments")]
77
use bdk_sp::encoding::SilentPaymentCode;
88
use bdk_wallet::bitcoin::{Address, Network, OutPoint, ScriptBuf};
@@ -197,20 +197,20 @@ pub(crate) fn parse_sp_code_value_pairs(s: &str) -> Result<(SilentPaymentCode, u
197197
Ok((key, value))
198198
}
199199

200-
// /// Function to parse the signature format from a string
201-
// #[cfg(feature = "bip322")]
202-
// pub(crate) fn parse_signature_format(format_str: &str) -> Result<SignatureFormat, Error> {
203-
// match format_str.to_lowercase().as_str() {
204-
// "legacy" => Ok(SignatureFormat::Legacy),
205-
// "simple" => Ok(SignatureFormat::Simple),
206-
// "full" => Ok(SignatureFormat::Full),
207-
// "fullproofoffunds" => Ok(SignatureFormat::FullProofOfFunds),
208-
// _ => Err(Error::Generic(
209-
// "Invalid signature format. Use 'legacy', 'simple', 'full', or 'fullproofoffunds'"
210-
// .to_string(),
211-
// )),
212-
// }
213-
// }
200+
/// Function to parse the signature format from a string
201+
#[cfg(feature = "bip322")]
202+
pub(crate) fn parse_signature_format(format_str: &str) -> Result<SignatureFormat, Error> {
203+
match format_str.to_lowercase().as_str() {
204+
"legacy" => Ok(SignatureFormat::Legacy),
205+
"simple" => Ok(SignatureFormat::Simple),
206+
"full" => Ok(SignatureFormat::Full),
207+
"fullproofoffunds" => Ok(SignatureFormat::FullProofOfFunds),
208+
_ => Err(Error::Generic(
209+
"Invalid signature format. Use 'legacy', 'simple', 'full', or 'fullproofoffunds'"
210+
.to_string(),
211+
)),
212+
}
213+
}
214214

215215
pub fn command_requires_db(command: &OfflineWalletSubCommand) -> bool {
216216
match command {
@@ -232,11 +232,11 @@ pub fn command_requires_db(command: &OfflineWalletSubCommand) -> bool {
232232
| OfflineWalletSubCommand::FinalizePsbt(_)
233233
| OfflineWalletSubCommand::CombinePsbt(_) => false,
234234

235-
// #[cfg(feature = "bip322")]
236-
// OfflineWalletSubCommand::SignMessage(_) => true,
235+
#[cfg(feature = "bip322")]
236+
OfflineWalletSubCommand::SignMessage(_) => true,
237237

238-
// #[cfg(feature = "bip322")]
239-
// OfflineWalletSubCommand::VerifyMessage(_) => true,
238+
#[cfg(feature = "bip322")]
239+
OfflineWalletSubCommand::VerifyMessage(_) => true,
240240
#[cfg(feature = "silent-payments")]
241241
OfflineWalletSubCommand::CreateSpTx(_) => true,
242242
#[cfg(feature = "dns_payment")]

src/utils/types.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ pub struct KeychainPair<T> {
110110
pub internal: T,
111111
}
112112

113-
// #[cfg(feature = "bip322")]
114-
// #[derive(Serialize, Debug, Default)]
115-
// pub struct MessageResult {
116-
// #[serde(skip_serializing_if = "Option::is_none")]
117-
// pub proof: Option<String>,
118-
119-
// #[serde(skip_serializing_if = "Option::is_none")]
120-
// pub valid: Option<bool>,
121-
122-
// #[serde(skip_serializing_if = "Option::is_none")]
123-
// pub proven_amount: Option<u64>,
124-
// }
113+
#[cfg(feature = "bip322")]
114+
#[derive(Serialize, Debug, Default)]
115+
pub struct MessageResult {
116+
#[serde(skip_serializing_if = "Option::is_none")]
117+
pub proof: Option<String>,
118+
119+
#[serde(skip_serializing_if = "Option::is_none")]
120+
pub valid: Option<bool>,
121+
122+
#[serde(skip_serializing_if = "Option::is_none")]
123+
pub proven_amount: Option<u64>,
124+
}
125125

126126
#[derive(Serialize, Debug)]
127127
pub struct StatusResult {

0 commit comments

Comments
 (0)