mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-19 09:13:39 +00:00
switch musig pubkeys to uncompressed format
This commit is contained in:
@ -124,13 +124,13 @@ impl CoordinatorDB {
|
||||
bond_tx_hex_maker TEXT NOT NULL,
|
||||
bond_tx_hex_taker TEXT NOT NULL,
|
||||
payout_address_maker TEXT NOT NULL,
|
||||
taproot_pubkey_hex_maker TEXT NOT NULL,
|
||||
taproot_xonly_pubkey_hex_maker TEXT NOT NULL,
|
||||
payout_address_taker TEXT NOT NULL,
|
||||
taproot_pubkey_hex_taker TEXT NOT NULL,
|
||||
taproot_xonly_pubkey_hex_taker TEXT NOT NULL,
|
||||
musig_pub_nonce_hex_maker TEXT NOT NULL,
|
||||
musig_pubkey_hex_maker TEXT NOT NULL,
|
||||
musig_pubkey_compressed_hex_maker TEXT NOT NULL,
|
||||
musig_pub_nonce_hex_taker TEXT NOT NULL,
|
||||
musig_pubkey_hex_taker TEXT NOT NULL,
|
||||
musig_pubkey_compressed_hex_taker TEXT NOT NULL,
|
||||
escrow_psbt_hex_maker TEXT,
|
||||
escrow_psbt_hex_taker TEXT,
|
||||
escrow_psbt_txid TEXT,
|
||||
@ -680,21 +680,23 @@ impl CoordinatorDB {
|
||||
&self,
|
||||
offer_id: &str,
|
||||
) -> Result<EscrowPsbtConstructionData> {
|
||||
let row = sqlx::query("SELECT taproot_pubkey_hex_maker, taproot_pubkey_hex_taker, musig_pubkey_hex_maker, musig_pubkey_hex_taker FROM taken_offers WHERE offer_id = ?")
|
||||
let row = sqlx::query("SELECT taproot_xonly_pubkey_hex_maker, taproot_xonly_pubkey_hex_taker, musig_pubkey_compressed_hex_maker, musig_pubkey_compressed_hex_taker FROM taken_offers WHERE offer_id = ?")
|
||||
.bind(offer_id)
|
||||
.fetch_one(&*self.db_pool)
|
||||
.await?;
|
||||
|
||||
let taproot_pubkey_hex_maker: String = row.get("taproot_pubkey_hex_maker");
|
||||
let taproot_pubkey_hex_taker: String = row.get("taproot_pubkey_hex_taker");
|
||||
let musig_pubkey_hex_maker: String = row.get("musig_pubkey_hex_maker");
|
||||
let musig_pubkey_hex_taker: String = row.get("musig_pubkey_hex_taker");
|
||||
let taproot_xonly_pubkey_hex_maker: String = row.get("taproot_xonly_pubkey_hex_maker");
|
||||
let taproot_xonly_pubkey_hex_taker: String = row.get("taproot_xonly_pubkey_hex_taker");
|
||||
let musig_pubkey_compressed_hex_maker: String =
|
||||
row.get("musig_pubkey_compressed_hex_maker");
|
||||
let musig_pubkey_compressed_hex_taker: String =
|
||||
row.get("musig_pubkey_compressed_hex_taker");
|
||||
|
||||
Ok(EscrowPsbtConstructionData {
|
||||
taproot_pubkey_hex_maker,
|
||||
taproot_pubkey_hex_taker,
|
||||
musig_pubkey_hex_maker,
|
||||
musig_pubkey_hex_taker,
|
||||
taproot_xonly_pubkey_hex_maker,
|
||||
taproot_xonly_pubkey_hex_taker,
|
||||
musig_pubkey_compressed_hex_maker,
|
||||
musig_pubkey_compressed_hex_taker,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ use musig2::{secp256k1::PublicKey as MuSig2PubKey, KeyAggContext};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EscrowPsbtConstructionData {
|
||||
pub taproot_pubkey_hex_maker: String,
|
||||
pub taproot_pubkey_hex_taker: String,
|
||||
pub taproot_xonly_pubkey_hex_maker: String,
|
||||
pub taproot_xonly_pubkey_hex_taker: String,
|
||||
// pub taproot_pubkey_hex_coordinator: String,
|
||||
pub musig_pubkey_hex_maker: String,
|
||||
pub musig_pubkey_hex_taker: String,
|
||||
pub musig_pubkey_compressed_hex_maker: String,
|
||||
pub musig_pubkey_compressed_hex_taker: String,
|
||||
}
|
||||
|
||||
fn aggregate_musig_pubkeys(maker_musig_pubkey: &str, taker_musig_pubkey: &str) -> Result<String> {
|
||||
@ -34,9 +34,9 @@ pub fn build_escrow_transaction_output_descriptor(
|
||||
escrow_data: &EscrowPsbtConstructionData,
|
||||
coordinator_pk: &XOnlyPublicKey,
|
||||
) -> Result<String> {
|
||||
let taproot_pubkey_hex_maker = escrow_data.taproot_pubkey_hex_maker.clone();
|
||||
let taproot_pubkey_hex_maker = escrow_data.taproot_xonly_pubkey_hex_maker.clone();
|
||||
let maker_pk = taproot_pubkey_hex_maker;
|
||||
let taker_pk = escrow_data.taproot_pubkey_hex_taker.clone();
|
||||
let taker_pk = escrow_data.taproot_xonly_pubkey_hex_taker.clone();
|
||||
let coordinator_pk = hex::encode(coordinator_pk.serialize());
|
||||
|
||||
// let script_a = format!("and(and(after({}),{}),{})", "144", maker_pk, coordinator_pk);
|
||||
@ -84,8 +84,8 @@ pub fn build_escrow_transaction_output_descriptor(
|
||||
|
||||
// An internal key, that defines the way to spend the transaction directly, using Key Path Spending
|
||||
let internal_agg_musig_key = aggregate_musig_pubkeys(
|
||||
&escrow_data.musig_pubkey_hex_maker,
|
||||
&escrow_data.musig_pubkey_hex_taker,
|
||||
&escrow_data.musig_pubkey_compressed_hex_maker,
|
||||
&escrow_data.musig_pubkey_compressed_hex_taker,
|
||||
)?;
|
||||
|
||||
// Create the descriptor
|
||||
|
@ -168,6 +168,7 @@ async fn test_invalid_bond_tx_low_fee_rate() {
|
||||
|
||||
#[test]
|
||||
fn test_build_escrow_transaction_output_descriptor() {
|
||||
// generating pubkeys
|
||||
// let seed: [u8; 32] = [
|
||||
// 0x1b, 0x2d, 0x3d, 0x4d, 0x5d, 0x6d, 0x7d, 0x8d, 0x9d, 0xad, 0xbd, 0xcd, 0xdd, 0xed, 0xfd,
|
||||
// 0x0d, 0x1d, 0x2d, 0x3d, 0x4d, 0x5d, 0x6d, 0x8d, 0x8d, 0x9d, 0xbd, 0xbd, 0xcd, 0xdd, 0xed,
|
||||
@ -176,19 +177,18 @@ fn test_build_escrow_transaction_output_descriptor() {
|
||||
// let xprv = ExtendedPrivKey::new_master(Network::Testnet, &seed).unwrap();
|
||||
// let pubkey = xprv
|
||||
// .to_keypair(&secp256k1::Secp256k1::new())
|
||||
// .x_only_public_key()
|
||||
// .0
|
||||
// .public_key()
|
||||
// .to_string();
|
||||
// dbg!(&pubkey);
|
||||
let escrow_data = EscrowPsbtConstructionData {
|
||||
taproot_pubkey_hex_maker:
|
||||
taproot_xonly_pubkey_hex_maker:
|
||||
"b709f64da734e04e35b129a65a7fae361cad8a9458d1abc4f0b45b7661a42fca".to_string(),
|
||||
taproot_pubkey_hex_taker:
|
||||
taproot_xonly_pubkey_hex_taker:
|
||||
"4987f3de20a9b1fa6f76c6758934953a8d615e415f1a656f0f6563694b53107d".to_string(),
|
||||
musig_pubkey_hex_maker:
|
||||
"02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9".to_string(),
|
||||
musig_pubkey_hex_taker:
|
||||
"03DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659".to_string(),
|
||||
musig_pubkey_compressed_hex_maker:
|
||||
"02d8e204cdaebec4c5a637311072c865858dc4f142b3848b8e6dde4143476535b5".to_string(),
|
||||
musig_pubkey_compressed_hex_taker:
|
||||
"02d8e204cdaebec4c5a637311072c865858dc4f142b3848b8e6dde4143476535b5".to_string(),
|
||||
};
|
||||
let coordinator_pk = XOnlyPublicKey::from_str(
|
||||
"d8e204cdaebec4c5a637311072c865858dc4f142b3848b8e6dde4143476535b5",
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::wallet::bitcoin::key::{Parity, Secp256k1, XOnlyPublicKey};
|
||||
use crate::wallet::{wallet_utils::get_seed, KeychainKind};
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use bdk::bitcoin::secp256k1::PublicKey;
|
||||
use bdk::{
|
||||
bitcoin::{
|
||||
bip32::ExtendedPrivKey,
|
||||
@ -17,7 +18,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
#[derive(Debug)]
|
||||
pub struct MuSigData {
|
||||
pub nonce: MusigNonce,
|
||||
pub public_key: (XOnlyPublicKey, Parity),
|
||||
pub public_key: PublicKey,
|
||||
pub secret_key: SecretKey,
|
||||
}
|
||||
|
||||
@ -71,7 +72,7 @@ impl MuSigData {
|
||||
|
||||
Ok(MuSigData {
|
||||
nonce,
|
||||
public_key: keypair.x_only_public_key(),
|
||||
public_key: keypair.public_key(),
|
||||
secret_key: keypair.secret_key(),
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user