Skip to content

Commit e03f123

Browse files
committed
fix: rename BIP322 commands, validate address ownership before signing and add Bip322Error variant
1 parent 2eab75c commit e03f123

6 files changed

Lines changed: 59 additions & 34 deletions

File tree

.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: 33 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ bdk_esplora = { version = "0.22.1", features = ["async-https", "tokio"], optiona
3434
bdk_kyoto = { version = "0.15.4", optional = true }
3535
bdk_redb = { version = "0.1.1", optional = true }
3636
shlex = { version = "1.3.0", optional = true }
37-
payjoin = { version = "1.0.0-rc.1", features = ["v1", "v2", "io", "_test-utils"], optional = true}
38-
reqwest = { version = "0.12.23", default-features = false, optional = true }
39-
url = { version = "2.5.4", optional = true }
37+
payjoin = { version = "=1.0.0-rc.1", features = ["v1", "v2", "io", "_test-utils"], optional = true}
38+
reqwest = { version = "0.13.2", default-features = false, optional = true }
39+
url = { version = "2.5.8", optional = true }
4040
bdk-bip322 = { git = "https://github.com/aagbotemi/bdk-bip322.git", branch = "master", optional = true }
4141

4242
[features]

src/commands.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ pub enum OfflineWalletSubCommand {
463463
},
464464
/// Sign a message using BIP322
465465
#[cfg(feature = "bip322")]
466-
SignBip322 {
466+
SignMessage {
467467
/// The message to sign
468468
#[arg(long)]
469469
message: String,
@@ -473,21 +473,19 @@ pub enum OfflineWalletSubCommand {
473473
/// Address to sign
474474
#[arg(long)]
475475
address: String,
476-
// Optional list of specific UTXOs for proof-of-funds (only for `FullWithProofOfFunds`) #[arg(long)]
476+
/// Optional list of specific UTXOs for proof-of-funds (only for `FullWithProofOfFunds`)
477+
#[arg(long)]
477478
utxos: Option<Vec<OutPoint>>,
478479
},
479480
/// Verify a BIP322 signature
480481
#[cfg(feature = "bip322")]
481-
VerifyBip322 {
482+
VerifyMessage {
482483
/// The signature proof to verify
483484
#[arg(long)]
484485
proof: String,
485486
/// The message that was signed
486487
#[arg(long)]
487488
message: String,
488-
/// The signature format (e.g., Legacy, Simple, Full)
489-
#[arg(long, default_value = "simple")]
490-
signature_type: String,
491489
/// The address associated with the signature
492490
#[arg(long)]
493491
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
@@ -73,7 +73,7 @@ use std::sync::Arc;
7373
#[cfg(feature = "bip322")]
7474
use crate::error::BDKCliError;
7575
#[cfg(feature = "bip322")]
76-
use bdk_bip322::{BIP322, Bip322Proof, Bip322VerificationResult};
76+
use bdk_bip322::{BIP322, MessageProof, MessageVerificationResult};
7777

7878
#[cfg(any(
7979
feature = "electrum",
@@ -598,7 +598,7 @@ pub fn handle_offline_wallet_subcommand(
598598
)?)
599599
}
600600
#[cfg(feature = "bip322")]
601-
SignBip322 {
601+
SignMessage {
602602
message,
603603
signature_type,
604604
address,
@@ -607,29 +607,30 @@ pub fn handle_offline_wallet_subcommand(
607607
let address: Address = parse_address(&address)?;
608608
let signature_format = parse_signature_format(&signature_type)?;
609609

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

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

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

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

0 commit comments

Comments
 (0)