pub struct DapolConfig { /* private fields */ }Expand description
Configuration needed to construct a DapolTree.
The config is defined by a struct. A builder pattern is used to construct the config, but it can also be constructed by deserializing a file. Currently only toml files are supported, with the following format:
# There are various different accumulator types (e.g. NDM-SMT).
#
# This value must be set.
accumulator_type = "ndm-smt"
# This is a public value that is used to aid the KDF when generating secret
# blinding factors for the Pedersen commitments.
#
# If it is not set then it will be randomly generated.
salt_b = "salt_b"
# This is a public value that is used to aid the KDF when generating secret
# salt values, which are in turn used in the hash function when generating
# node hashes.
#
# If it is not set then it will be randomly generated.
salt_s = "salt_s"
# Height of the tree.
#
# If not set the default height will be used:
# `dapol::Height::default()`.
height = 16
# This is a public value representing the maximum amount that any single
# entity's liability can be, and is used in the range proofs:
# $[0, 2^{\text{height}} \times \text{max_liability}]$
#
# If not set then the default value will be used:
# `2.pow(dapol::DEFAULT_RANGE_PROOF_UPPER_BOUND_BIT_LENGTH)`.
max_liability = 10_000_000
# Max number of threads to be spawned for multi-threading algorithms.
#
# If not set the max parallelism of the underlying machine will be used.
max_thread_count = 8
# Can be a file or directory (default file name given in this case)
#
# If not set then no serialization is done.
serialization_path = "./tree.dapoltree"
# At least one of file_path or generate_random must be present.
#
# If both are given then file_path is preferred and generate_random is ignored.
[entities]
# Path to a file containing a list of entity IDs and their liabilities.
file_path = "./entities_example.csv"
# Generate the given number of entities, with random IDs & liabilities.
# This is useful for testing.
num_random_entities= 100
# At least on of file_path or master_secret must be present.
# The master secret is known only to the tree generator and is used to
# generate all other secret values required by the tree.
#
# If both are given then file_path is preferred and master_secret is ignored.
[secrets]
# Path to a file containing a list of entity IDs and their liabilities.
file_path = "./dapol_secrets_example.toml"
# String value of the master secret.
master_secret = "master_secret"Example of how to use the builder to construct a DapolTree:
use std::{path::PathBuf, str::FromStr};
use dapol::{
AccumulatorType, DapolConfigBuilder, DapolTree, Entity, Height,
MaxLiability, MaxThreadCount, Salt, Secret,
};
let secrets_file_path =
PathBuf::from("./examples/dapol_secrets_example.toml");
let entities_file_path = PathBuf::from("./examples/entities_example.csv");
let height = Height::expect_from(8);
let salt_b = Salt::from_str("salt_b").unwrap();
let salt_s = Salt::from_str("salt_s").unwrap();
let max_liability = MaxLiability::from(10_000_000);
let max_thread_count = MaxThreadCount::from(8);
// The builder requires at least the following to be given:
// - accumulator_type
// - entities
// - secrets
let dapol_config = DapolConfigBuilder::default()
.accumulator_type(AccumulatorType::NdmSmt)
.height(height.clone())
.salt_b(salt_b.clone())
.salt_s(salt_s.clone())
.max_liability(max_liability.clone())
.max_thread_count(max_thread_count.clone())
.secrets_file_path(secrets_file_path.clone())
.entities_file_path(entities_file_path.clone())
.build()
.unwrap();Example of how to use a config file to construct a DapolTree:
use std::{path::PathBuf, str::FromStr};
use dapol::DapolConfig;
let config_file_path =
PathBuf::from("./examples/dapol_config_example.toml");
let dapol_config_from_file =
DapolConfig::deserialize(config_file_path).unwrap();Note that you can also construct a DapolTree by calling the constructor directly (see DapolTree).
Implementations§
Source§impl DapolConfig
impl DapolConfig
Sourcepub fn deserialize(config_file_path: PathBuf) -> Result<Self, DapolConfigError>
pub fn deserialize(config_file_path: PathBuf) -> Result<Self, DapolConfigError>
Open the file, then try to create the DapolConfig struct.
An error is returned if:
- The file cannot be opened.
- The file cannot be read.
- The file type is not supported.
Config deserialization example:
use std::path::PathBuf;
use dapol::DapolConfig;
let file_path = PathBuf::from("./examples/dapol_config_example.toml");
let config = DapolConfig::deserialize(file_path).unwrap();Trait Implementations§
Source§impl Debug for DapolConfig
impl Debug for DapolConfig
Source§impl<'de> Deserialize<'de> for DapolConfig
impl<'de> Deserialize<'de> for DapolConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for DapolConfig
impl PartialEq for DapolConfig
impl StructuralPartialEq for DapolConfig
Auto Trait Implementations§
impl Freeze for DapolConfig
impl RefUnwindSafe for DapolConfig
impl Send for DapolConfig
impl Sync for DapolConfig
impl Unpin for DapolConfig
impl UnsafeUnpin for DapolConfig
impl UnwindSafe for DapolConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more