Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cli = ["base64-compat", "clap", "fern", "log", "jobserver", "shell-escape"]
[dependencies]
bitcoin = { version = "0.32.5", features = [ "std", "serde", "rand", "rand-std" ] }
secp256k1 = { version = "0.29", features = [ "recovery" ] }
secp256k1_zkp_musig = { package = "secp256k1-zkp", git = "https://github.com/sanket1729/rust-secp256k1-zkp.git", rev = "0de61c2cc536a58f08822851528a5dfa5968d155" }
bip39 = { version = "2.1.0", features = [ "all-languages" ] }
lightning-invoice = { version = "0.32.0", features = [ "std" ] }
miniscript = { version = "12.3.0", features = ["compiler"] }
Expand Down
2 changes: 2 additions & 0 deletions src/bin/hal/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod ln;
pub mod merkle;
pub mod message;
pub mod miniscript;
pub mod musig;
pub mod psbt;
pub mod random;
pub mod script;
Expand All @@ -28,6 +29,7 @@ pub fn subcommands() -> Vec<clap::App<'static, 'static>> {
merkle::subcommand(),
message::subcommand(),
miniscript::subcommand(),
musig::subcommand(),
psbt::subcommand(),
random::subcommand(),
script::subcommand(),
Expand Down
43 changes: 43 additions & 0 deletions src/bin/hal/cmd/musig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

use std::str::FromStr;
use crate::prelude::*;
use secp256k1_zkp_musig as zkpmusig;

pub fn subcommand<'a>() -> clap::App<'a, 'a> {
cmd::subcommand_group("musig", "use the MuSig2 multisignature protocol")
.subcommand(cmd_aggregate())
}

pub fn execute<'a>(args: &clap::ArgMatches<'a>) {
match args.subcommand() {
("aggregate", Some(ref m)) => exec_aggregate(&m),
(_, _) => unreachable!("clap prints help"),
};
}

fn cmd_aggregate<'a>() -> clap::App<'a, 'a> {
cmd::subcommand("aggregate", "aggregate public keys in a MuSig2 compatible way")
.arg(args::flag(
"ordered", "aggregate in the specified order instead of ordering lexicographically",
))
.arg(args::arg("pubkeys", "list of public keys in hex").required(true).multiple(true))
}

fn exec_aggregate<'a>(args: &clap::ArgMatches<'a>) {
let mut pks = Vec::with_capacity(2);
for arg in args.values_of("pubkeys").need("no pubkeys provided") {
let pk = bitcoin::PublicKey::from_str(&arg).unwrap_or_else(|_| {
exit!("invalid public key provided: {}", arg);
});
pks.push(zkpmusig::PublicKey::from_slice(&pk.inner.serialize()).unwrap());
}

if !args.is_present("ordered") {
//TODO(stevenroose) is this lexicographically
pks.sort_by_key(|k| k.serialize());
}

let secp = zkpmusig::Secp256k1::new();
let agg = zkpmusig::MusigKeyAggCache::new(&secp, &pks[..]);
print!("{}", agg.agg_pk());
}
1 change: 1 addition & 0 deletions src/bin/hal/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ fn main() {
("merkle", Some(ref m)) => cmd::merkle::execute(&m),
("message", Some(ref m)) => cmd::message::execute(&m),
("miniscript", Some(ref m)) => cmd::miniscript::execute(&m),
("musig", Some(ref m)) => cmd::musig::execute(&m),
("psbt", Some(ref m)) => cmd::psbt::execute(&m),
("random", Some(ref m)) => cmd::random::execute(&m),
("script", Some(ref m)) => cmd::script::execute(&m),
Expand Down