pub fn exec(opts: GenerateOpts) -> AnyhowResult {
    if Path::new(&opts.seed_file).exists() && !opts.overwrite_seed_file {
        return Err(anyhow!("Seed file exists and overwrite is not set."));
    }
    if let Some(path) = &opts.pem_file {
        if Path::new(path).exists() && !opts.overwrite_pem_file {
            return Err(anyhow!("PEM file exists and overwrite is not set."));
        }
    }
    let bytes = match opts.words {
        12 => 16,
        24 => 32,
        _ => return Err(anyhow!("Words must be 12 or 24.")),
    };
    let mnemonic = match opts.phrase {
        Some(phrase) => Mnemonic::parse(phrase).unwrap(),
        None => {
            let mut key = vec![0u8; bytes];
            OsRng.fill_bytes(&mut key);
            Mnemonic::from_entropy_in(Language::English, &key).unwrap()
        }
    };
    let pem = mnemonic_to_pem(&mnemonic);
    let mut phrase = mnemonic
        .word_iter()
        .collect::<Vec<&'static str>>()
        .join(" ");
    phrase.push('\n');
    std::fs::write(opts.seed_file, phrase)?;
    if let Some(path) = opts.pem_file {
        std::fs::write(path, pem.clone())?;
    }
    let (principal_id, account_id) = crate::commands::public::get_ids(&Some(pem))?;
    println!("Principal id: {}", principal_id);
    println!("Account id: {}", account_id);
    Ok(())
}
/// Generate or recover mnemonic seed phrase and/or PEM file.
Generate or recover mnemonic seed phrase and/or PEM file.
Generate or recover mnemonic seed phrase and / or PEM file .
pub fn exec(opts: GenerateOpts) -> AnyhowResult {
    if Path::new(&opts.seed_file).exists() && !opts.overwrite_seed_file {
        return Err(anyhow!("Seed file exists and overwrite is not set."));
    }
    if let Some(path) = &opts.pem_file {
        if Path::new(path).exists() && !opts.overwrite_pem_file {
            return Err(anyhow!("PEM file exists and overwrite is not set."));
        }
    }
    let bytes = match opts.words {
        12 => 16,
        24 => 32,
        _ => return Err(anyhow!("Words must be 12 or 24.")),
    };
    let mnemonic = match opts.phrase {
        Some(phrase) => Mnemonic::parse(phrase).unwrap(),
        None => {
            let mut key = vec![0u8; bytes];
            OsRng.fill_bytes(&mut key);
            Mnemonic::from_entropy_in(Language::English, &key).unwrap()
        }
    };
    let pem = mnemonic_to_pem(&mnemonic);
    let mut phrase = mnemonic
        .word_iter()
        .collect::<Vec<&'static str>>()
        .join(" ");
    phrase.push('\n');
    std::fs::write(opts.seed_file, phrase)?;
    if let Some(path) = opts.pem_file {
        std::fs::write(path, pem.clone())?;
    }
    let (principal_id, account_id) = crate::commands::public::get_ids(&Some(pem))?;
    println!("Principal id: {}", principal_id);
    println!("Account id: {}", account_id);
    Ok(())
}
pub fn exec ( opts : GenerateOpts ) -> AnyhowResult { if Path :: new ( & opts . seed_file ) . exists ( ) && ! opts . overwrite_seed_file { return Err ( anyhow ! ( " " ) ) ; } if let Some ( path ) = & opts . pem_file { if Path :: new ( path ) . exists ( ) && ! opts . overwrite_pem_file { return Err ( anyhow ! ( " " ) ) ; } } let bytes = match opts . words { 12 => 16 , 24 => 32 , _ => return Err ( anyhow ! ( " " ) ) , } ; let mnemonic = match opts . phrase { Some ( phrase ) => Mnemonic :: parse ( phrase ) . unwrap ( ) , None => { let mut key = vec ! [ 0u8 bytes ] ; OsRng . fill_bytes ( & mut key ) ; Mnemonic :: from_entropy_in ( Language :: English , & key ) . unwrap ( ) } } ; let pem = mnemonic_to_pem ( & mnemonic ) ; let mut phrase = mnemonic . word_iter ( ) . collect :: < Vec < & ' static str > > ( ) . join ( " " ) ; phrase . push ( '\n' ) ; std :: fs :: write ( opts . seed_file , phrase ) ? ; if let Some ( path ) = opts . pem_file { std :: fs :: write ( path , pem . clone ( ) ) ? ; } let ( principal_id , account_id ) = crate :: commands :: public :: get_ids ( & Some ( pem ) ) ? ; println ! ( " " principal_id ) ; println ! ( " " account_id ) ; Ok ( ( ) ) }
Generate or recover mnemonic seed phrase and/or PEM file.
Generate or recover mnemonic seed phrase and / or PEM file .
opts
GenerateOpts