Skip to main content

DapolConfig

Struct DapolConfig 

Source
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

Source

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:

  1. The file cannot be opened.
  2. The file cannot be read.
  3. 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();
Source

pub fn parse(self) -> Result<DapolTree, DapolConfigError>

Try to construct a DapolTree from the config.

Trait Implementations§

Source§

impl Debug for DapolConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for DapolConfig

Source§

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

Source§

fn eq(&self, other: &DapolConfig) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DapolConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V