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: StringImplementations§
Sourcepub fn new(
points: Vec<PointInFiniteField>,
threshold: usize,
integrity: String,
) -> Self
pub fn new( points: Vec<PointInFiniteField>, threshold: usize, integrity: String, ) -> Self
Create a new KeyShares instance.
Sourcepub fn split(
key: &PrivateKey,
threshold: usize,
total: usize,
) -> Result<Self, PrimitivesError>
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 splitthreshold- 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.
Sourcepub fn to_backup_format(&self) -> Vec<String>
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”
Sourcepub fn from_backup_format(shares: &[String]) -> Result<Self, PrimitivesError>
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”
Sourcepub fn reconstruct(shares: &KeyShares) -> Result<PrivateKey, PrimitivesError>
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.