cargo_openvm/commands/
keygen.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::path::PathBuf;

use clap::Parser;
use eyre::Result;
use openvm_sdk::{
    fs::{write_app_pk_to_file, write_app_vk_to_file},
    Sdk,
};

use crate::{
    default::{DEFAULT_APP_CONFIG_PATH, DEFAULT_APP_PK_PATH, DEFAULT_APP_VK_PATH},
    util::read_config_toml_or_default,
};

#[derive(Parser)]
#[command(name = "keygen", about = "Generate an application proving key")]
pub struct KeygenCmd {
    #[clap(long, action, help = "Path to app config TOML file", default_value = DEFAULT_APP_CONFIG_PATH)]
    config: PathBuf,

    #[clap(
        long,
        action,
        help = "Path to output app proving key file",
        default_value = DEFAULT_APP_PK_PATH
    )]
    output: PathBuf,

    #[clap(
        long,
        action,
        help = "Path to output app verifying key file",
        default_value = DEFAULT_APP_VK_PATH
    )]
    vk_output: PathBuf,
}

impl KeygenCmd {
    pub fn run(&self) -> Result<()> {
        let app_config = read_config_toml_or_default(&self.config)?;
        let app_pk = Sdk.app_keygen(app_config)?;
        write_app_vk_to_file(app_pk.get_app_vk(), &self.vk_output)?;
        write_app_pk_to_file(app_pk, &self.output)?;
        Ok(())
    }
}