npub1xu…g43rm on Nostr: #[cfg(feature = "nostr")] use frost_secp256k1_tr as frost; #[cfg(feature = "nostr")] ...
#[cfg(feature = "nostr")]
use frost_secp256k1_tr as frost;
#[cfg(feature = "nostr")]
use rand::thread_rng;
#[cfg(feature = "nostr")]
use std::collections::BTreeMap;
#[cfg(feature = "nostr")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rng = thread_rng();
let max_signers = 3;
let min_signers = 2;
////////////////////////////////////////////////////////////////////////////
// Round 0: Key Generation (Trusted Dealer)
////////////////////////////////////////////////////////////////////////////
// In a real P2P setup, you'd use Distributed Key Generation (DKG).
// For local testing/simulations, the trusted dealer is faster.
let (shares, pubkey_package) = frost::keys::generate_with_dealer(
max_signers,
min_signers,
frost::keys::IdentifierList::Default,
&mut rng,
)?;
// Verifying the public key exists
let group_public_key = pubkey_package.verifying_key();
println!("Group Public Key: {:?}", group_public_key);
////////////////////////////////////////////////////////////////////////////
// Round 1: Commitment
////////////////////////////////////////////////////////////////////////////
let message = b"BIP-64MOD Consensus Proposal";
let mut signing_commitments = BTreeMap::new();
let mut participant_nonces = BTreeMap::new();
// Participants 1 and 2 decide to sign
for i in 1..=min_signers {
let identifier = frost::Identifier::try_from(i as u16)?;
// Generate nonces and commitments
let (nonces, commitments) = frost::round1::commit(
shares[&identifier].signing_share(),
&mut rng,
);
signing_commitments.insert(identifier, commitments);
participant_nonces.insert(identifier, nonces);
}
////////////////////////////////////////////////////////////////////////////
// Round 2: Signing
////////////////////////////////////////////////////////////////////////////
let mut signature_shares = BTreeMap::new();
let signing_package = frost::SigningPackage::new(signing_commitments, message);
for i in 1..=min_signers {
let identifier = frost::Identifier::try_from(i as u16)?;
let nonces = &participant_nonces[&identifier];
// Each participant produces a signature share
let key_package: frost::keys::KeyPackage = shares[&identifier].clone().try_into()?;
let share = frost::round2::sign(&signing_package, nonces, &key_package)?;
signature_shares.insert(identifier, share);
}
////////////////////////////////////////////////////////////////////////////
// Finalization: Aggregation
////////////////////////////////////////////////////////////////////////////
let group_signature = frost::aggregate(
&signing_package,
&signature_shares,
&pubkey_package,
)?;
// Verification
group_public_key.verify(message, &group_signature)?;
println!("Threshold signature verified successfully!");
Ok(())
}
#[cfg(not(feature = "nostr"))]
fn main() {
println!("This example requires the 'nostr' feature. Please run with: cargo run --example trusted-dealer --features nostr");
}
Published at
2026-04-04 01:42:42 UTCEvent JSON
{
"id": "49e8f4c26c16b8d52a8fbdc55027a37c627d285151fab7db98568e218538b3e2",
"pubkey": "37306250e62aafbe17f1fd1ee25a539f268e044d7516734c6e389c6de7273ac9",
"created_at": 1775266962,
"kind": 1,
"tags": [
[
"file",
"examples/trusted-dealer.rs"
],
[
"version",
"0.3.3"
]
],
"content": "#[cfg(feature = \"nostr\")]\r\nuse frost_secp256k1_tr as frost;\r\n#[cfg(feature = \"nostr\")]\r\nuse rand::thread_rng;\r\n#[cfg(feature = \"nostr\")]\r\nuse std::collections::BTreeMap;\r\n\r\n#[cfg(feature = \"nostr\")]\r\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\r\n let mut rng = thread_rng();\r\n let max_signers = 3;\r\n let min_signers = 2;\r\n\r\n ////////////////////////////////////////////////////////////////////////////\r\n // Round 0: Key Generation (Trusted Dealer)\r\n ////////////////////////////////////////////////////////////////////////////\r\n \r\n // In a real P2P setup, you'd use Distributed Key Generation (DKG).\r\n // For local testing/simulations, the trusted dealer is faster.\r\n let (shares, pubkey_package) = frost::keys::generate_with_dealer(\r\n max_signers,\r\n min_signers,\r\n frost::keys::IdentifierList::Default,\r\n \u0026mut rng,\r\n )?;\r\n\r\n // Verifying the public key exists\r\n let group_public_key = pubkey_package.verifying_key();\r\n println!(\"Group Public Key: {:?}\", group_public_key);\r\n\r\n ////////////////////////////////////////////////////////////////////////////\r\n // Round 1: Commitment\r\n ////////////////////////////////////////////////////////////////////////////\r\n \r\n let message = b\"BIP-64MOD Consensus Proposal\";\r\n let mut signing_commitments = BTreeMap::new();\r\n let mut participant_nonces = BTreeMap::new();\r\n\r\n // Participants 1 and 2 decide to sign\r\n for i in 1..=min_signers {\r\n let identifier = frost::Identifier::try_from(i as u16)?;\r\n \r\n // Generate nonces and commitments\r\n let (nonces, commitments) = frost::round1::commit(\r\n shares[\u0026identifier].signing_share(),\r\n \u0026mut rng,\r\n );\r\n \r\n signing_commitments.insert(identifier, commitments);\r\n participant_nonces.insert(identifier, nonces);\r\n }\r\n\r\n ////////////////////////////////////////////////////////////////////////////\r\n // Round 2: Signing\r\n ////////////////////////////////////////////////////////////////////////////\r\n \r\n let mut signature_shares = BTreeMap::new();\r\n let signing_package = frost::SigningPackage::new(signing_commitments, message);\r\n\r\n for i in 1..=min_signers {\r\n let identifier = frost::Identifier::try_from(i as u16)?;\r\n let nonces = \u0026participant_nonces[\u0026identifier];\r\n \r\n // Each participant produces a signature share\r\n let key_package: frost::keys::KeyPackage = shares[\u0026identifier].clone().try_into()?;\r\n let share = frost::round2::sign(\u0026signing_package, nonces, \u0026key_package)?;\r\n signature_shares.insert(identifier, share);\r\n }\r\n\r\n ////////////////////////////////////////////////////////////////////////////\r\n // Finalization: Aggregation\r\n ////////////////////////////////////////////////////////////////////////////\r\n \r\n let group_signature = frost::aggregate(\r\n \u0026signing_package,\r\n \u0026signature_shares,\r\n \u0026pubkey_package,\r\n )?;\r\n\r\n // Verification\r\n group_public_key.verify(message, \u0026group_signature)?;\r\n \r\n println!(\"Threshold signature verified successfully!\");\r\n Ok(())\r\n}\r\n\r\n#[cfg(not(feature = \"nostr\"))]\r\nfn main() {\r\n println!(\"This example requires the 'nostr' feature. Please run with: cargo run --example trusted-dealer --features nostr\");\r\n}\r\n",
"sig": "a7177eae95bccd477a439c2ab94d6bfcab4d180c20bfde0ee00b1c3a109c94b305eb24ae91b7ffa86948d583f9bcd156575eda74856d81c89c2783e672b9bdb1"
}