Skip to content

Commit

Permalink
Merge #326: Replace Signature with Message Signature
Browse files Browse the repository at this point in the history
2e4dac9 Replace Signature with Message Signature (Masud)

Pull request description:

  When attempting to use verify_message() function, using Singature kept leading to InvalidSignature.

  As such, we replaced Signature with MessageSignature from bitcoin::sign_message::MessageSignature.

  We also noticed that there was a // TODO comment to test verify_message, so we also added a test function and it works with the new MessageSignature.

ACKs for top commit:
  tcharding:
    ACK 2e4dac9

Tree-SHA512: d6279086c66f420009c5600e3d5028090c8df3a7088d2fbe928d94fc796dedf227b8536295bd231bf5ddc6ad306120685020c4cf6f4f0c631c3075d9ff9f0009
  • Loading branch information
tcharding committed Apr 30, 2024
2 parents c0fc7cb + 2e4dac9 commit 05f5b82
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use serde_json;

use crate::bitcoin::address::{NetworkUnchecked, NetworkChecked};
use crate::bitcoin::hashes::hex::FromHex;
use crate::bitcoin::secp256k1::ecdsa::Signature;
use bitcoin::sign_message::MessageSignature;
use crate::bitcoin::{
Address, Amount, Block, OutPoint, PrivateKey, PublicKey, Script, Transaction,
};
Expand Down Expand Up @@ -874,7 +874,7 @@ pub trait RpcApi: Sized {
fn verify_message(
&self,
address: &Address,
signature: &Signature,
signature: &MessageSignature,
message: &str,
) -> Result<bool> {
let args = [address.to_string().into(), signature.to_string().into(), into_json(message)?];
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2018"

[dependencies]
bitcoincore-rpc = { path = "../client" }
bitcoin = { version = "0.31.0", features = ["serde", "rand"]}
bitcoin = { version = "0.31.0", features = ["serde", "rand", "base64"]}
lazy_static = "1.4.0"
log = "0.4"
14 changes: 13 additions & 1 deletion integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::json::BlockStatsFields as BsFields;
use bitcoin::consensus::encode::{deserialize, serialize_hex};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::Hash;
use bitcoin::sign_message::MessageSignature;
use bitcoin::{secp256k1, ScriptBuf, sighash};
use bitcoin::{
transaction, Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount,
Expand Down Expand Up @@ -146,6 +147,7 @@ fn main() {
test_get_blockchain_info(&cl);
test_get_new_address(&cl);
test_get_raw_change_address(&cl);
test_verify_message_with_messagesignature(&cl);
test_dump_private_key(&cl);
test_generate(&cl);
test_get_balance_generate_to_address(&cl);
Expand Down Expand Up @@ -216,7 +218,7 @@ fn main() {
test_get_mempool_info(&cl);
test_add_multisig_address(&cl);
//TODO import_multi(
//TODO verify_message(

//TODO encrypt_wallet(&self, passphrase: &str) -> Result<()> {
//TODO get_by_id<T: queryable::Queryable<Self>>(
test_add_node(&cl);
Expand Down Expand Up @@ -1368,6 +1370,16 @@ fn test_add_multisig_address(cl: &Client) {
assert!(cl.add_multisig_address(addresses.len(), &addresses, None, Some(json::AddressType::Bech32)).is_ok());
}

fn test_verify_message_with_messagesignature(cl: &Client) {
let addr: Address = Address::from_str("mm68FdwbpxkVcqjU3fu7iiBGEwrsC6Hk66").unwrap().assume_checked();
let signature = MessageSignature::from_base64(
"H3X+ic7axKtHGIsKiqDq0TmP9HIAkONwunln17ROlvB4SOVVUoG5e79EwAz94x2eERPwqcGJ5rLuWRhIu85pEwE=",)
.expect("a valid signature");
let message = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";

assert!(cl.verify_message(&addr, &signature, message).expect("a valid signature"));
}

#[rustfmt::skip]
fn test_derive_addresses(cl: &Client) {
let descriptor = r"pkh(02e96fe52ef0e22d2f131dd425ce1893073a3c6ad20e8cac36726393dfb4856a4c)#62k9sn4x";
Expand Down

0 comments on commit 05f5b82

Please sign in to comment.