pub struct SSKRShare(/* private fields */);
Expand description
A share of a secret split using Sharded Secret Key Reconstruction (SSKR).
SSKR is a protocol for splitting a secret into multiple shares across one or more groups, such that the secret can be reconstructed only when a threshold number of shares from a threshold number of groups are combined.
Each SSKR share contains:
- A unique identifier for the split
- Metadata about the group structure (thresholds, counts, indices)
- A portion of the secret data
SSKR shares follow a specific binary format that includes a 5-byte metadata header followed by the share value. The metadata encodes information about group thresholds, member thresholds, and the position of this share within the overall structure.
Implementations§
Sourcepub fn from_data(data: impl AsRef<[u8]>) -> Self
pub fn from_data(data: impl AsRef<[u8]>) -> Self
Creates a new SSKRShare
from raw binary data.
§Parameters
data
- The raw binary data of the SSKR share, including both metadata (5 bytes) and share value.
§Returns
A new SSKRShare
instance containing the provided data.
§Example
use bc_components::SSKRShare;
// Raw SSKR share data (typically from sskr_generate function)
let data = vec![0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC]; // Example data
let share = SSKRShare::from_data(data);
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns a reference to the raw binary data of this share.
§Returns
A reference to the byte vector containing the SSKR share data.
§Example
use bc_components::SSKRShare;
let data = vec![0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC]; // Example data
let share = SSKRShare::from_data(data.clone());
assert_eq!(share.as_bytes(), &data);
Sourcepub fn from_hex(hex: impl AsRef<str>) -> Self
pub fn from_hex(hex: impl AsRef<str>) -> Self
Creates a new SSKRShare
from a hexadecimal string.
§Parameters
hex
- A hexadecimal string representing the SSKR share data.
§Returns
A new SSKRShare
instance created from the decoded hex data.
§Panics
Panics if the hex string is invalid and cannot be decoded.
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_hex("1234213101aabbcc");
assert_eq!(share.hex(), "1234213101aabbcc");
Sourcepub fn identifier(&self) -> u16
pub fn identifier(&self) -> u16
Returns the unique identifier of the split to which this share belongs.
The identifier is a 16-bit value that is the same for all shares in a split and is used to verify that shares belong together when combining them.
§Returns
A 16-bit integer representing the unique identifier of the split.
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_data(vec![
0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC,
]);
assert_eq!(share.identifier(), 0x1234);
Sourcepub fn identifier_hex(&self) -> String
pub fn identifier_hex(&self) -> String
Returns the unique identifier of the split as a hexadecimal string.
§Returns
A hexadecimal string representing the 16-bit identifier.
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_data(vec![
0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC,
]);
assert_eq!(share.identifier_hex(), "1234");
Sourcepub fn group_threshold(&self) -> usize
pub fn group_threshold(&self) -> usize
Returns the minimum number of groups whose quorum must be met to reconstruct the secret.
This value is encoded as GroupThreshold - 1 in the metadata, so the actual threshold value is one more than the encoded value.
§Returns
The group threshold value (minimum number of groups required).
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_data(vec![0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC]);
// The encoded value 0x2 in the third byte's high nibble represents a threshold of 3
assert_eq!(share.group_threshold(), 3);
Sourcepub fn group_count(&self) -> usize
pub fn group_count(&self) -> usize
Returns the total number of groups in the split.
This value is encoded as GroupCount - 1 in the metadata, so the actual count is one more than the encoded value.
§Returns
The total number of groups in the split.
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_data(vec![0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC]);
// The encoded value 0x1 in the third byte's low nibble represents a count of 2
assert_eq!(share.group_count(), 2);
Sourcepub fn group_index(&self) -> usize
pub fn group_index(&self) -> usize
Returns the index of the group to which this share belongs.
This is a zero-based index identifying which group in the split this share is part of.
§Returns
The group index (0-based).
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_data(vec![0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC]);
// The encoded value 0x3 in the fourth byte's high nibble represents group index 3
assert_eq!(share.group_index(), 3);
Sourcepub fn member_threshold(&self) -> usize
pub fn member_threshold(&self) -> usize
Returns the minimum number of shares within the group to which this share belongs that must be combined to meet the group threshold.
This value is encoded as MemberThreshold - 1 in the metadata, so the actual threshold value is one more than the encoded value.
§Returns
The member threshold value (minimum number of shares required within this group).
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_data(vec![0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC]);
// The encoded value 0x1 in the fourth byte's low nibble represents a threshold of 2
assert_eq!(share.member_threshold(), 2);
Sourcepub fn member_index(&self) -> usize
pub fn member_index(&self) -> usize
Returns the index of this share within the group to which it belongs.
This is a zero-based index identifying which share within the group this specific share is.
§Returns
The member index (0-based) within the group.
§Example
use bc_components::SSKRShare;
let share = SSKRShare::from_data(vec![0x12, 0x34, 0x21, 0x31, 0x01, 0xAA, 0xBB, 0xCC]);
// The encoded value 0x1 in the fifth byte's low nibble represents member index 1
assert_eq!(share.member_index(), 1);
Trait Implementations§
This allows SSKR shares to be serialized with specific CBOR tags that identify them as SSKR shares.
Source§fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)