1use clap::{Parser, Subcommand};
2use anyhow::Result;
3
4mod commands;
5mod error;
6mod passcode;
7
8use commands::*;
9
10#[derive(Parser)]
11#[command(name = "krust")]
12#[command(about = "A CLI for libkeri - KERI protocol implementation", long_about = None)]
13#[command(version)]
14struct Cli {
15 #[command(subcommand)]
16 command: Commands,
17}
18
19#[derive(Subcommand)]
20enum Commands {
21 Init {
23 #[arg(short, long)]
25 name: String,
26
27 #[arg(short, long)]
29 passcode: Option<String>,
30
31 #[arg(long)]
33 nopasscode: bool,
34
35 #[arg(short, long)]
37 salt: Option<String>,
38
39 #[arg(long, default_value = ".")]
41 config_dir: String,
42
43 #[arg(long)]
45 config_file: Option<String>,
46 },
47
48 Passcode {
50 #[command(subcommand)]
51 command: PasscodeCommands,
52 },
53
54 Incept {
56 #[arg(short, long)]
58 name: String,
59
60 #[arg(short, long)]
62 alias: String,
63
64 #[arg(short, long)]
66 passcode: Option<String>,
67
68 #[arg(long)]
70 nopasscode: bool,
71
72 #[arg(short, long)]
74 file: Option<String>,
75
76 #[arg(short = 't', long)]
78 transferable: Option<bool>,
79
80 #[arg(short, long)]
82 wits: Vec<String>,
83
84 #[arg(long)]
86 toad: Option<u32>,
87
88 #[arg(long)]
90 icount: Option<String>,
91
92 #[arg(long)]
94 isith: Option<String>,
95
96 #[arg(long)]
98 ncount: Option<String>,
99
100 #[arg(long)]
102 nsith: Option<String>,
103
104 #[arg(short, long)]
106 est_only: bool,
107
108 #[arg(short, long)]
110 data: Option<String>,
111
112 #[arg(long)]
114 delpre: Option<String>,
115
116 #[arg(long)]
118 proxy: Option<String>,
119
120 #[arg(long, default_value_t = 120)]
122 timeout: u64,
123 },
124
125 Status {
127 #[arg(short, long)]
129 name: String,
130
131 #[arg(short, long)]
133 alias: String,
134 },
135
136 Rotate {
138 #[arg(short, long)]
140 name: String,
141
142 #[arg(short, long)]
144 alias: String,
145
146 #[arg(short, long)]
148 passcode: Option<String>,
149
150 #[arg(long)]
152 nopasscode: bool,
153
154 #[arg(long)]
156 isith: Option<String>,
157
158 #[arg(long)]
160 nsith: Option<String>,
161
162 #[arg(long)]
164 ncount: Option<String>,
165
166 #[arg(long)]
168 toad: Option<u32>,
169
170 #[arg(long)]
172 cuts: Vec<String>,
173
174 #[arg(long)]
176 adds: Vec<String>,
177
178 #[arg(short, long)]
180 data: Option<String>,
181
182 #[arg(long)]
184 proxy: Option<String>,
185
186 #[arg(long, default_value_t = 120)]
188 timeout: u64,
189 },
190
191 Oobi {
193 #[command(subcommand)]
194 command: OobiCommands,
195 },
196
197 Multisig {
199 #[command(subcommand)]
200 command: MultisigCommands,
201 },
202
203 Delegate {
205 #[command(subcommand)]
206 command: DelegateCommands,
207 },
208}
209
210#[derive(Subcommand)]
211enum DelegateCommands {
212 Confirm {
214 #[arg(short, long)]
216 name: String,
217
218 #[arg(short, long)]
220 alias: String,
221
222 #[arg(long)]
224 rotate: bool,
225
226 #[arg(long)]
228 oobi: Vec<String>,
229
230 #[arg(long, default_value_t = 120)]
232 timeout: u64,
233 },
234}
235
236#[derive(Subcommand)]
237enum MultisigCommands {
238 Incept {
240 #[arg(short, long)]
242 name: String,
243
244 #[arg(short, long)]
246 alias: String,
247
248 #[arg(short, long)]
250 group: String,
251
252 #[arg(long = "smids", required = true)]
254 smids: Vec<String>,
255
256 #[arg(long = "rmids")]
258 rmids: Vec<String>,
259
260 #[arg(long)]
262 isith: Option<String>,
263
264 #[arg(long)]
266 nsith: Option<String>,
267
268 #[arg(short, long)]
270 out: String,
271 },
272
273 Ingest {
275 #[arg(short, long)]
277 name: String,
278
279 #[arg(short, long)]
281 group: String,
282
283 #[arg(short, long)]
285 file: String,
286 },
287
288 Join {
290 #[arg(short, long)]
292 name: String,
293
294 #[arg(short, long)]
296 alias: String,
297
298 #[arg(short, long)]
300 group: String,
301
302 #[arg(long = "smids", required = true)]
304 smids: Vec<String>,
305
306 #[arg(long = "rmids")]
308 rmids: Vec<String>,
309
310 #[arg(short, long)]
312 file: String,
313
314 #[arg(short, long)]
316 out: String,
317 },
318}
319
320#[derive(Subcommand)]
321enum OobiCommands {
322 Resolve {
324 #[arg(short, long)]
326 name: String,
327
328 #[arg(long)]
330 oobi_alias: String,
331
332 #[arg(long)]
334 oobi: String,
335 },
336}
337
338#[derive(Subcommand)]
339enum PasscodeCommands {
340 Generate,
342}
343
344#[tokio::main]
345async fn main() -> Result<()> {
346 let cli = Cli::parse();
347
348 match cli.command {
349 Commands::Init { name, passcode, nopasscode, salt, config_dir, config_file } => {
350 init::handle_init(&name, passcode.as_deref(), nopasscode, salt.as_deref(), &config_dir, config_file.as_deref()).await?;
351 }
352 Commands::Passcode { command } => {
353 match command {
354 PasscodeCommands::Generate => {
355 commands::passcode::handle_generate().await?;
356 }
357 }
358 }
359 Commands::Incept { name, alias, passcode, nopasscode, file, transferable, wits, toad, icount, isith, ncount, nsith, est_only, data, delpre, proxy, timeout } => {
360 incept::handle_incept(&name, &alias, passcode.as_deref(), nopasscode, file.as_deref(), transferable, &wits, toad, icount.as_deref(), isith.as_deref(), ncount.as_deref(), nsith.as_deref(), est_only, data.as_deref(), delpre.as_deref(), proxy.as_deref(), timeout).await?;
361 }
362 Commands::Oobi { command } => match command {
363 OobiCommands::Resolve { name, oobi_alias, oobi } => {
364 commands::oobi::handle_resolve(&name, &oobi_alias, &oobi).await?;
365 }
366 },
367 Commands::Multisig { command } => match command {
368 MultisigCommands::Incept { name, alias, group, smids, rmids, isith, nsith, out } => {
369 commands::multisig::handle_incept(&name, &alias, &group, &smids, &rmids, isith.as_deref(), nsith.as_deref(), &out).await?;
370 }
371 MultisigCommands::Ingest { name, group, file } => {
372 commands::multisig::handle_ingest(&name, &group, &file).await?;
373 }
374 MultisigCommands::Join { name, alias, group, smids, rmids, file, out } => {
375 commands::multisig::handle_join(&name, &alias, &group, &smids, &rmids, &file, &out).await?;
376 }
377 },
378 Commands::Delegate { command } => match command {
379 DelegateCommands::Confirm { name, alias, rotate, oobi, timeout } => {
380 commands::delegate::handle_confirm(&name, &alias, rotate, &oobi, timeout).await?;
381 }
382 },
383 Commands::Status { name, alias } => {
384 status::handle_status(&name, &alias).await?;
385 }
386 Commands::Rotate { name, alias, passcode, nopasscode, isith, nsith, ncount, toad, cuts, adds, data, proxy, timeout } => {
387 rotate::handle_rotate(&name, &alias, passcode.as_deref(), nopasscode, isith.as_deref(), nsith.as_deref(), ncount.as_deref(), toad, &cuts, &adds, data.as_deref(), proxy.as_deref(), timeout).await?;
388 }
389 }
390
391 Ok(())
392}