Skip to main content

VotingKeyTree

Struct VotingKeyTree 

Source
pub struct VotingKeyTree { /* private fields */ }
Expand description

投票鍵のファイル(votingkeys/private_key_tree1.dat など)。

Implementations§

Source§

impl VotingKeyTree

Source

pub fn generate<R: CryptoRng + ?Sized>( rng: &mut R, start_epoch: u32, end_epoch: u32, ) -> Result<Self, VotingKeyError>

start_epoch から end_epoch までの鍵を作る。catapult の BmPrivateKeyTree::Create。

根の秘密鍵は、子の鍵に署名したら捨てる。期間がネットワークで認められるかは、呼び出し側で確かめる。

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, VotingKeyError>

ファイルから読む。catapult の BmPrivateKeyTree::FromStream が読むものを読み、長さと期間が合わないものは弾く。 署名は VotingKeyTree::verify で確かめる。

Source

pub fn to_bytes(&self) -> Zeroizing<Vec<u8>>

ファイルに書くバイト列。子の秘密鍵が入るので、消えるようにして返す。

Source

pub fn can_sign(&self, epoch: u32) -> bool

エポック epoch の鍵で署名できるか。catapult の BmPrivateKeyTree::canSign と同じく、前に使ったエポックより 前と、期間の外ではできない。消した鍵でもできない

Source

pub fn sign(&mut self, epoch: u32, message: &[&[u8]]) -> Option<[u8; 192]>

message を続けたものに、エポック epoch の鍵で署名し、catapult の BmTreeSignature(根の公開鍵、根による 下の公開鍵への署名、下の公開鍵、下の署名)を返す。使ったエポックを覚える。署名できなければ None。

覚えたことはメモリの中だけなので、署名を誰かに渡す前に VotingKeyTree::to_bytes でファイルに書き戻す

Source

pub fn wipe_through(&mut self, epoch: u32)

期間の始めから epoch までの鍵を消す。catapult の BmPrivateKeyTree::wipe。前に消したところより前なら 何もしない。期間を超えるなら終わりまで消す

Source

pub fn public_key(&self) -> PublicKey

チェーンに紐づける公開鍵。

Source

pub fn start_epoch(&self) -> u32

Source

pub fn end_epoch(&self) -> u32

Source

pub fn last_used_epoch(&self) -> Option<u32>

ノードが最後に投票に使ったエポック。

Source

pub fn last_wiped_epoch(&self) -> Option<u32>

ノードが最後に消したエポック。これより前の鍵も消えている。

Source

pub fn remaining_keys(&self) -> usize

子の鍵がまだ残っているエポックの数。

Source

pub fn verify(&self) -> Result<(), u32>

残っている子の鍵について、根の公開鍵がそのエポックの鍵として署名していることを確かめる。 消した鍵は公開鍵がわからないので確かめられない。合わない最初のエポックを返す。

Trait Implementations§

Source§

impl Debug for VotingKeyTree

Source§

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

Formats the value using the given formatter. Read more

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<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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.