krust/commands/
multisig.rs1use anyhow::{Context, Result};
2
3use super::hab;
4use super::incept::parse_tholder;
5
6pub async fn handle_join(
16 name: &str,
17 alias: &str,
18 group: &str,
19 smids: &[String],
20 rmids: &[String],
21 file: &str,
22 out: &str,
23) -> Result<()> {
24 let mut hby = hab::open(name, None)?;
25 let proposal = std::fs::read(file)
26 .with_context(|| format!("Failed to read proposed inception {}", file))?;
27 let rmids = (!rmids.is_empty()).then_some(rmids);
28
29 let signed = hby
30 .join_group_inception(group, alias, smids, rmids, &proposal)
31 .context("Failed to join group")?;
32 std::fs::write(out, &signed)
33 .with_context(|| format!("Failed to write signed inception to {}", out))?;
34
35 let hab = hby.hab_by_name(group)?;
36 let pre = hab.pre.clone().unwrap_or_default();
37 println!("✓ Joined group '{}' as member '{}'", group, alias);
38 println!(" Prefix: {}", pre);
39 println!(" Signed inception written to {}", out);
40 Ok(())
41}
42
43#[allow(clippy::too_many_arguments)]
51pub async fn handle_incept(
52 name: &str,
53 alias: &str,
54 group: &str,
55 smids: &[String],
56 rmids: &[String],
57 isith: Option<&str>,
58 nsith: Option<&str>,
59 out: &str,
60) -> Result<()> {
61 let mut hby = hab::open(name, None)?;
62 let rmids = (!rmids.is_empty()).then_some(rmids);
63 let isith = parse_tholder(isith)?.map(|t| t.sith());
64 let nsith = parse_tholder(nsith)?.map(|t| t.sith());
65
66 let proposal = hby
67 .make_group_hab(group, alias, smids, rmids, isith, nsith)
68 .context("Failed to propose group")?;
69 std::fs::write(out, &proposal)
70 .with_context(|| format!("Failed to write proposed inception to {}", out))?;
71
72 let pre = hby.hab_by_name(group)?.pre.clone().unwrap_or_default();
73 println!("✓ Proposed group '{}' with member '{}'", group, alias);
74 println!(" Prefix: {}", pre);
75 println!(" Accepted: {}", hby.kevers().contains_key(&pre));
76 println!(" Proposed inception written to {}", out);
77 Ok(())
78}
79
80pub async fn handle_ingest(name: &str, group: &str, file: &str) -> Result<()> {
84 let mut hby = hab::open(name, None)?;
85 let pre = hby
86 .hab_by_name(group)
87 .with_context(|| format!("No local group '{}'", group))?
88 .pre
89 .clone()
90 .unwrap_or_default();
91 let msgs = std::fs::read(file).with_context(|| format!("Failed to read {}", file))?;
92 let n = hby.ingest(&msgs, true).context("Failed to ingest signatures")?;
94
95 let accepted = hby.kevers().contains_key(&pre);
96 println!("✓ Ingested {} message(s) for group '{}'", n, group);
97 println!(" Prefix: {}", pre);
98 println!(" Accepted: {}", accepted);
99 if !accepted {
100 println!(" Still waiting for signatures from other members");
101 }
102 Ok(())
103}