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