Struct secured_linked_list::SecuredLinkedList
source · [−]pub struct SecuredLinkedList { /* private fields */ }
Expand description
Chain of BLS keys where every key is proven (signed) by its parent key, except the first one.
CRDT
The operations that mutate the chain (insert
and merge
) are
commutative, associative and idempotent. This means the chain is a
CRDT.
Forks
It’s possible to insert multiple keys that all have the same parent key. This is called a “fork”. The chain implements automatic fork resolution which means that even in the presence of forks the chain presents the blocks in a well-defined unique and deterministic order.
Block order
Block are ordered primarily according to their parent-child relation (parents always precede
children) and forks are resolved by additionally ordering the sibling blocks according to the
Ord
relation of their public key. That is, “lower” keys precede “higher” keys.
Implementations
sourceimpl SecuredLinkedList
impl SecuredLinkedList
sourcepub fn insert(
&mut self,
parent_key: &PublicKey,
key: PublicKey,
signature: Signature
) -> Result<(), Error>
pub fn insert(
&mut self,
parent_key: &PublicKey,
key: PublicKey,
signature: Signature
) -> Result<(), Error>
Insert new key into the chain. parent_key
must exists in the chain and must validate
signature
, otherwise error is returned.
sourcepub fn join(&mut self, other: Self) -> Result<(), Error>
pub fn join(&mut self, other: Self) -> Result<(), Error>
Merges two chains into one.
This succeeds only if the root key of one of the chain is present in the other one.
Otherwise it returns Error::InvalidOperation
sourcepub fn get_proof_chain(
&self,
from_key: &PublicKey,
to_key: &PublicKey
) -> Result<Self, Error>
pub fn get_proof_chain(
&self,
from_key: &PublicKey,
to_key: &PublicKey
) -> Result<Self, Error>
Creates a sub-chain from given from
and to
keys.
Returns Error::KeyNotFound
if the given keys are not present in the chain.
sourcepub fn minimize<'a, I>(&self, required_keys: I) -> Result<Self, Error> where
I: IntoIterator<Item = &'a PublicKey>,
pub fn minimize<'a, I>(&self, required_keys: I) -> Result<Self, Error> where
I: IntoIterator<Item = &'a PublicKey>,
Creates a minimal sub-chain of self
that contains all required_keys
.
Returns Error::KeyNotFound
if some of required_keys
is not present in self
.
Note: “minimal” means it contains the fewest number of blocks of all such sub-chains.
sourcepub fn truncate(&self, count: usize) -> Self
pub fn truncate(&self, count: usize) -> Self
Returns a sub-chain of self
truncated to the last count
keys.
NOTE: a chain must have at least 1 block, so if count
is 0 it is treated the same as if
it was 1.
sourcepub fn extend(
&self,
trusted_key: &PublicKey,
super_chain: &Self
) -> Result<Self, Error>
pub fn extend(
&self,
trusted_key: &PublicKey,
super_chain: &Self
) -> Result<Self, Error>
Returns the smallest super-chain of self
that would be trusted by a peer that trust
trusted_key
. Ensures that the last key of the resuling chain is the same as the last key
of self
.
Returns Error::KeyNotFound
if any of trusted_key
, self.root_key()
or self.last_key()
is not present in super_chain
.
Returns Error::InvalidOperation
if trusted_key
is not reachable from self.last_key()
.
sourcepub fn keys(&self) -> impl DoubleEndedIterator<Item = &PublicKey>
pub fn keys(&self) -> impl DoubleEndedIterator<Item = &PublicKey>
Iterator over all the keys in the chain in order.
sourcepub fn root_key(&self) -> &PublicKey
pub fn root_key(&self) -> &PublicKey
Returns the root key of this chain. This is the first key in the chain and is the only key that doesn’t have a parent key.
sourcepub fn prev_key(&self) -> &PublicKey
pub fn prev_key(&self) -> &PublicKey
Returns the parent key of the last key or the root key if this chain has only one key.
sourcepub fn self_verify(&self) -> bool
pub fn self_verify(&self) -> bool
Verify every BLS key in this chain is proven (signed) by its parent key, except the first one.
sourcepub fn check_trust<'a, I>(&self, trusted_keys: I) -> bool where
I: IntoIterator<Item = &'a PublicKey>,
pub fn check_trust<'a, I>(&self, trusted_keys: I) -> bool where
I: IntoIterator<Item = &'a PublicKey>,
Given a collection of keys that are already trusted, returns whether this chain is also
trusted. A chain is considered trusted only if at least one of the trusted_keys
is on its
main branch.
Explanation
Consider this chain that contains fork:
A->B->C
|
+->D
Now if the only trusted key is D
, then there is no way to prove the chain is trusted,
because this chain would be indistinguishable in terms of trust from any other chain with
the same general “shape”, say:
W->X->Y->Z
|
+->D
So an adversary is easily able to forge any such chain.
When the trusted key is on the main branch, on the other hand:
D->E->F
|
+->G
Then such chain is impossible to forge because the adversary would have to have access to
the secret key corresponding to D
in order to validly sign E
. Thus such chain can be
safely considered trusted.
sourcepub fn cmp_by_position(&self, lhs: &PublicKey, rhs: &PublicKey) -> Ordering
pub fn cmp_by_position(&self, lhs: &PublicKey, rhs: &PublicKey) -> Ordering
Compare the two keys by their position in the chain. The key that is higher (closer to the
last key) is considered Greater
. If exactly one of the keys is not in the chain, the other
one is implicitly considered Greater
. If none are in the chain, they are considered
Equal
.
sourcepub fn main_branch_len(&self) -> usize
pub fn main_branch_len(&self) -> usize
Returns the number of block on the main branch of the chain - that is - the ones reachable from the last block.
NOTE: this is a O(n)
operation.
Trait Implementations
sourceimpl Clone for SecuredLinkedList
impl Clone for SecuredLinkedList
sourcefn clone(&self) -> SecuredLinkedList
fn clone(&self) -> SecuredLinkedList
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for SecuredLinkedList
impl Debug for SecuredLinkedList
sourceimpl<'de> Deserialize<'de> for SecuredLinkedList
impl<'de> Deserialize<'de> for SecuredLinkedList
sourcefn 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
sourceimpl Hash for SecuredLinkedList
impl Hash for SecuredLinkedList
sourceimpl PartialEq<SecuredLinkedList> for SecuredLinkedList
impl PartialEq<SecuredLinkedList> for SecuredLinkedList
sourcefn eq(&self, other: &SecuredLinkedList) -> bool
fn eq(&self, other: &SecuredLinkedList) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &SecuredLinkedList) -> bool
fn ne(&self, other: &SecuredLinkedList) -> bool
This method tests for !=
.
sourceimpl Serialize for SecuredLinkedList
impl Serialize for SecuredLinkedList
impl Eq for SecuredLinkedList
impl StructuralEq for SecuredLinkedList
impl StructuralPartialEq for SecuredLinkedList
Auto Trait Implementations
impl RefUnwindSafe for SecuredLinkedList
impl Send for SecuredLinkedList
impl Sync for SecuredLinkedList
impl Unpin for SecuredLinkedList
impl UnwindSafe for SecuredLinkedList
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
Pipes by value. This is generally the method you want to use. Read more
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the Deref::Target
of a value. Read more
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the Deref::Target
of a value. Read more
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more