snarkos_cli/helpers/
dev.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkOS library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use snarkvm::{console::network::Network, prelude::PrivateKey};
17
18use anyhow::Result;
19use rand::SeedableRng;
20use rand_chacha::ChaChaRng;
21
22/// The development mode RNG seed.
23pub const DEVELOPMENT_MODE_RNG_SEED: u64 = 1234567890u64;
24
25/// The development mode number of genesis committee members.
26pub const DEVELOPMENT_MODE_NUM_GENESIS_COMMITTEE_MEMBERS: u16 = 4;
27
28/// Get the private key for a validator in development mode.
29pub fn get_development_key<N: Network>(index: u16) -> Result<PrivateKey<N>> {
30    // Sample the private key of this node.
31    // Initialize the (fixed) RNG.
32    let mut rng = ChaChaRng::seed_from_u64(DEVELOPMENT_MODE_RNG_SEED);
33    // Iterate through 'dev' address instances to match the account.
34    for _ in 0..index {
35        let _ = PrivateKey::<N>::new(&mut rng)?;
36    }
37
38    PrivateKey::<N>::new(&mut rng)
39}