Skip to main content

KeyShares

Struct KeyShares 

Source
pub struct KeyShares {
    pub points: Vec<PointInFiniteField>,
    pub threshold: usize,
    pub integrity: String,
}
Expand description

Shamir’s Secret Sharing for PrivateKey backup and recovery.

Splits a private key into total shares such that any threshold shares can reconstruct the original key, but fewer shares reveal nothing about the secret.

Share format (backup string): “base58(x).base58(y).threshold.integrity” where integrity is the first 8 hex chars of hash160(pubkey) as hex.

Fields§

§points: Vec<PointInFiniteField>§threshold: usize§integrity: String

Implementations§

Source§

impl KeyShares

Source

pub fn new( points: Vec<PointInFiniteField>, threshold: usize, integrity: String, ) -> Self

Create a new KeyShares instance.

Source

pub fn split( key: &PrivateKey, threshold: usize, total: usize, ) -> Result<Self, PrimitivesError>

Split a private key into shares using Shamir’s Secret Sharing.

§Arguments
  • key - The private key to split
  • threshold - Minimum shares needed to reconstruct (must be >= 2)
  • total - Total shares to generate (must be >= threshold)
§Returns

A KeyShares instance containing the shares, threshold, and integrity hash.

Source

pub fn to_backup_format(&self) -> Vec<String>

Convert shares to backup format strings.

Each share is formatted as: “base58(x).base58(y).threshold.integrity”

Source

pub fn from_backup_format(shares: &[String]) -> Result<Self, PrimitivesError>

Parse shares from backup format strings.

Each share must be in format: “base58(x).base58(y).threshold.integrity”

Source

pub fn reconstruct(shares: &KeyShares) -> Result<PrivateKey, PrimitivesError>

Reconstruct a private key from shares.

Requires at least threshold shares. Uses Lagrange interpolation to recover the secret (polynomial value at x=0).

§Arguments
  • shares - The KeyShares containing points, threshold, and integrity hash
§Returns

The reconstructed PrivateKey, validated against the integrity hash.

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, 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.