[][src]Struct p0w::Proofs

pub struct Proofs { /* fields omitted */ }

The actual Proof-of-work

Implementations

impl Proofs[src]

pub fn new<Desc: Into<Vec<u8>>>(
    desc: Desc,
    levels: usize,
    proofs: usize,
    nodes: BTreeMap<usize, [u8; 32]>
) -> Self
[src]

Creates a new Proofs instance from a service description, number of levels, number of proofs and BTreeMap associating the index of nodes to their hash.

Panics

This function will panic if levels is less than 2, or if proofs is 0 or greater than the number of leaves the tree contains (leaves = 2 ^ (levels - 1)).

Example

use p0w::{Proofs, Tree};

let tree = Tree::new("foobar", 8);
let proofs = tree.gen_proofs_with(64);

let nodes = proofs.into_nodes();
let proofs = Proofs::new("foobar", 8, 64, nodes);

assert!(proofs.verify().is_ok());

pub fn description(&self) -> &[u8][src]

Returns the tree's service description (as passed to Tree::new()).

Example

use p0w::Tree;

let tree = Tree::new("foobar", 8);
let proofs = tree.gen_proofs();

assert_eq!(proofs.description(), b"foobar");

pub fn levels(&self) -> usize[src]

Returns the number of levels (including the root) this tree contains (as passed to Tree::new()).

Example

use p0w::Tree;

let tree = Tree::new("foobar", 8);
let proofs = tree.gen_proofs();

assert_eq!(proofs.levels(), 8);

pub fn proofs(&self) -> usize[src]

Returns the number of proofs (leaves / 2) included in the Proofs (as passed to Tree::gen_proofs_with() or 8 * levels if Tree::gen_proofs() was used).

Example

use p0w::Tree;

let tree = Tree::new("foobar", 8);
let proofs = tree.gen_proofs_with(64);

assert_eq!(proofs.proofs(), 64);

pub fn as_nodes(&self) -> &BTreeMap<usize, [u8; 32]>[src]

Returns a reference to a BTreeMap associating the index of the nodes included in the Proofs to their hash.

Example

use p0w::Tree;

let tree_a = Tree::new("foobar", 8);
let proofs_a = tree_a.gen_proofs();

let tree_b = Tree::new("foobar", 8);
let proofs_b = tree_b.gen_proofs();

assert_eq!(proofs_a.as_nodes(), proofs_b.as_nodes());

pub fn into_nodes(self) -> BTreeMap<usize, [u8; 32]>[src]

Returns a BTreeMap associating the index of the nodes included in the Proofs to their hash, consuming the Proofs.

Example

use p0w::Tree;

let tree_a = Tree::new("foobar", 8);
let proofs_a = tree_a.gen_proofs();

let tree_b = Tree::new("foobar", 8);
let proofs_b = tree_b.gen_proofs();

assert_eq!(proofs_a.into_nodes(), proofs_b.into_nodes());

pub fn verify(&self) -> Result<(), Error>[src]

Verifies that the proofs are valid, returning an [Error] otherwise.

This function does the following verification (in order):

  • the nodes that are included in the proofs allow to verify the tree
  • there are no unnecessary nodes included in the proofs
  • the included leaves have the right hashes
  • the right leaves were included

Example

use p0w::Tree;

let tree = Tree::new("foobar", 8);
let proofs = tree.gen_proofs();

assert!(proofs.verify().is_ok());

Trait Implementations

impl Debug for Proofs[src]

impl Into<BTreeMap<usize, [u8; 32]>> for Proofs[src]

Auto Trait Implementations

impl RefUnwindSafe for Proofs

impl Send for Proofs

impl Sync for Proofs

impl Unpin for Proofs

impl UnwindSafe for Proofs

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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