Skip to content

Commit 9826c76

Browse files
committed
fix: rename BIP322 commands, validate address ownership before signing and add Bip322Error variant
1 parent 7c9542c commit 9826c76

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

.github/workflows/audit.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@ name: Audit
33
on:
44
push:
55
paths:
6-
# Run if workflow changes
7-
- '.github/workflows/audit.yml'
8-
# Run on changed dependencies
96
- '**/Cargo.toml'
107
- '**/Cargo.lock'
11-
# Run if the configuration file changes
12-
- '**/audit.toml'
138
schedule:
149
- cron: '0 0 * * 0' # Once per week
15-
# Run manually
16-
workflow_dispatch:
1710

1811
jobs:
1912

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub enum OfflineWalletSubCommand {
407407
},
408408
/// Sign a message using BIP322
409409
#[cfg(feature = "bip322")]
410-
SignBip322 {
410+
SignMessage {
411411
/// The message to sign
412412
#[arg(long)]
413413
message: String,
@@ -417,21 +417,19 @@ pub enum OfflineWalletSubCommand {
417417
/// Address to sign
418418
#[arg(long)]
419419
address: String,
420-
// Optional list of specific UTXOs for proof-of-funds (only for `FullWithProofOfFunds`) #[arg(long)]
420+
/// Optional list of specific UTXOs for proof-of-funds (only for `FullWithProofOfFunds`)
421+
#[arg(long)]
421422
utxos: Option<Vec<OutPoint>>,
422423
},
423424
/// Verify a BIP322 signature
424425
#[cfg(feature = "bip322")]
425-
VerifyBip322 {
426+
VerifyMessage {
426427
/// The signature proof to verify
427428
#[arg(long)]
428429
proof: String,
429430
/// The message that was signed
430431
#[arg(long)]
431432
message: String,
432-
/// The signature format (e.g., Legacy, Simple, Full)
433-
#[arg(long, default_value = "simple")]
434-
signature_type: String,
435433
/// The address associated with the signature
436434
#[arg(long)]
437435
address: String,

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ pub enum BDKCliError {
140140
#[cfg(feature = "payjoin")]
141141
#[error("Payjoin create request error: {0}")]
142142
PayjoinCreateRequest(#[from] payjoin::send::v2::CreateRequestError),
143+
144+
#[cfg(feature = "bip322")]
145+
#[error("BIP-322 error: {0}")]
146+
Bip322Error(#[from] bdk_bip322::error::Error),
143147
}
144148

145149
impl From<ExtractTxError> for BDKCliError {

src/handlers.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use std::sync::Arc;
7272
#[cfg(feature = "bip322")]
7373
use crate::error::BDKCliError;
7474
#[cfg(feature = "bip322")]
75-
use bdk_bip322::{BIP322, Bip322Proof, Bip322VerificationResult};
75+
use bdk_bip322::{BIP322, MessageProof, MessageVerificationResult};
7676

7777
#[cfg(any(
7878
feature = "electrum",
@@ -597,7 +597,7 @@ pub fn handle_offline_wallet_subcommand(
597597
)?)
598598
}
599599
#[cfg(feature = "bip322")]
600-
SignBip322 {
600+
SignMessage {
601601
message,
602602
signature_type,
603603
address,
@@ -606,29 +606,30 @@ pub fn handle_offline_wallet_subcommand(
606606
let address: Address = parse_address(&address)?;
607607
let signature_format = parse_signature_format(&signature_type)?;
608608

609-
let proof: Bip322Proof = wallet
610-
.sign_bip322(message.as_str(), signature_format, &address, utxos)
611-
.map_err(|e| {
612-
BDKCliError::Generic(format!("Failed to sign BIP-322 message: {e}"))
613-
})?;
609+
if !wallet.is_mine(address.script_pubkey()) {
610+
return Err(Error::Generic(format!(
611+
"Address {} does not belong to this wallet.",
612+
address
613+
)));
614+
}
615+
616+
let proof: MessageProof =
617+
wallet.sign_message(message.as_str(), signature_format, &address, utxos)?;
614618

615619
Ok(json!({"proof": proof.to_base64()}).to_string())
616620
}
617621
#[cfg(feature = "bip322")]
618-
VerifyBip322 {
622+
VerifyMessage {
619623
proof,
620624
message,
621-
signature_type,
622625
address,
623626
} => {
624627
let address: Address = parse_address(&address)?;
625-
let signature_format = parse_signature_format(&signature_type)?;
626-
627-
let parsed_proof: Bip322Proof = Bip322Proof::from_base64(&proof)
628+
let parsed_proof: MessageProof = MessageProof::from_base64(&proof)
628629
.map_err(|e| BDKCliError::Generic(format!("Invalid proof: {e}")))?;
629630

630-
let is_valid: Bip322VerificationResult =
631-
wallet.verify_bip322(&parsed_proof, &message, signature_format, &address)?;
631+
let is_valid: MessageVerificationResult =
632+
wallet.verify_message(&parsed_proof, &message, &address)?;
632633

633634
Ok(json!({
634635
"valid": is_valid.valid,

0 commit comments

Comments
 (0)