Skip to main content

split

Function split 

Source
pub fn split(
    channels: &[ChannelId],
    secret_id: u64,
    version: u32,
    secret_data: impl AsRef<[u8]>,
    threshold: usize,
) -> Result<SplitResult, Error>
Expand description

Splits a secret into verifiable committed shares, one per Helper channel.

In DeRec, the sharing flow splits a secret into independently verifiable shares using a Verifiable Secret Sharing (VSS) scheme. Each generated share is:

  • Bound to a specific secret_id and version
  • Committed using a Merkle commitment and proof
  • Returned as a CommittedDeRecShare ready to be delivered to its Helper

To send a share to a Helper, pass the returned CommittedDeRecShare to produce together with the Helper’s shared key to produce the encrypted delivery envelope.

§Deterministic channel/share assignment

The input channels slice is sorted by ChannelId before shares are assigned. Generated VSS shares are assigned in that sorted order. Duplicate channel IDs are rejected with SharingError::DuplicateChannelId.

§Arguments

  • channels - Slice of Helper ChannelId values. Each entry receives exactly one committed share. Must not be empty. Duplicate entries are rejected.
  • secret_id - Identifier of the secret being protected. Embedded into each generated share. Must not be empty.
  • version - Logical version of this secret distribution. Embedded into each generated share.
  • secret_data - Raw secret bytes to split using VSS. Must not be empty.
  • threshold - Minimum number of shares required to reconstruct the secret. Must satisfy 2 <= threshold <= channels.len().

§Returns

On success returns SplitResult containing:

  • shares: HashMap<ChannelId, CommittedDeRecShare> — one committed share per channel.

§Errors

Returns crate::Error (specifically Error::Sharing(...)) in the following cases:

§Security Notes

  • The caller is responsible for securely managing the original secret_data.

§Example

use derec_library::primitives::sharing::request::{split, SplitResult};
use derec_library::types::ChannelId;

let channels = [ChannelId(1), ChannelId(2), ChannelId(3)];

let SplitResult { shares } = split(
    &channels,
    1,
    1,
    b"super_secret_value",
    2,
).expect("split failed");

assert_eq!(shares.len(), 3);