Skip to main content

bls_sig_cli/
cli.rs

1use clap::{Parser, Subcommand, command};
2
3#[derive(Parser, Debug)]
4#[command(name = "bls", version = "0.1.0", about = "BLS Signatures CLI")]
5pub struct Cli {
6    #[command(subcommand)]
7    pub command: Commands,
8}
9
10/// Available commands for the BLS signature CLI.
11#[derive(Subcommand, Debug)]
12pub enum Commands {
13    /// Generate a new BLS secret key.
14    ///
15    /// This command allows you to derive a new secret key from Input Key Material (IKM)
16    /// or generate a random one if no IKM is provided.
17    /// The generated key can be printed to standard output or saved to a specified file.
18    Keygen {
19        /// Optional: Input Key Material (IKM) used to derive the BLS private key.
20        /// This should be a high-entropy, secret string.
21        /// If not provided, a cryptographically secure random private key will be generated.
22        #[arg(short = 'i', long, help = "Input Key Material")]
23        ikm: Option<String>,
24
25        /// Optional: Specifies the file path where the generated secret key should be stored.
26        /// If this argument is omitted, the secret key will be printed to standard output.
27        #[arg(short = 'o', long, help = "Custom output file path")]
28        out: Option<String>,
29        // /// Store key at /etc/bls/secret.key (requires root)
30        // #[arg(long, help = "Use system-wide key path (/etc/bls/secret.key)")]
31        // system: bool, // This argument is commented out in your provided code.
32    },
33
34    /// Derive and print the public key associated with a given BLS secret key file.
35    ///
36    /// This command reads a secret key from a specified file and computes its
37    /// corresponding public key, which is then printed to standard output.
38    Pubkey {
39        /// Optional: Path to the BLS secret key file.
40        /// If omitted, the application might look for a default key file
41        /// (e.g., in a standard configuration directory), or it may result in an error
42        /// if no key can be found.
43        #[arg(short = 'p', long, help = "Path to secret key file")]
44        path: Option<String>,
45    },
46
47    /// Sign a message using a BLS secret key.
48    ///
49    /// This command takes a message and a secret key (from a file) to produce
50    /// a BLS signature. The signature will be printed to standard output.
51    Sign {
52        /// Optional: Path to the BLS secret key file to be used for signing.
53        /// If omitted, the application might look for a default key file
54        /// (e.g., in a standard configuration directory), or it may result in an error
55        /// if no key can be found.
56        #[arg(short, long, help = "Path to secret key file")]
57        path: Option<String>,
58
59        /// Mandatory: The message data to be signed.
60        /// This can be a raw string provided directly on the command line,
61        /// or the content of a file (if your application's logic supports reading from file).
62        #[arg(
63            short,
64            long,
65            required = true,
66            help = "Message to be signed. Accepts a generic file or a raw string"
67        )]
68        msg: String,
69    },
70
71    /// Verify a BLS signature against a public key and a message.
72    ///
73    /// This command takes a public key, a message, and a signature (all in hexadecimal format)
74    /// and verifies if the signature is valid for the given message and public key.
75    /// The verification result (success or failure) will be printed.
76    Verify {
77        /// Mandatory: The BLS public key, provided in hexadecimal string format.
78        #[arg(short, long, required = true, help = "Public key in hex")]
79        pk: String,
80
81        /// Mandatory: The original message that was signed.
82        /// This can be a raw string provided directly on the command line,
83        /// or the content of a file (if your application's logic supports reading from file).
84        /// It must exactly match the message used during signing.
85        #[arg(
86            short,
87            long,
88            required = true,
89            help = "Message to be signed. Accepts a generic file or a raw string"
90        )]
91        msg: String,
92
93        /// Mandatory: The BLS signature, provided in hexadecimal string format.
94        #[arg(short, long, required = true, help = "Signature in hex")]
95        sig: String,
96    },
97}