Skip to main content

encode_shares

Function encode_shares 

Source
pub fn encode_shares(
    tag: Tag,
    threshold: Threshold,
    n: usize,
    secret: &Payload,
) -> Result<Vec<String>>
Expand description

Split a secret (entr or mnem) into n codex32 K-of-N shares.

  • threshold == ZERO: n MUST be 1; returns a single string byte-identical to encode(tag, secret) — the v0.1 single-string construction (from_seed(HRP, 0, tag, Fe::S, [prefix]||payload), deterministic). The id stays the type tag (NOT random) — load-bearing for byte-identity.
  • threshold == k ∈ 2..=9: validate k <= n <= 31 (else InvalidShareCount). A random 4-char id (not in RESERVED_ID_BLOCKLIST) keys the share-set. The secret-at-S (Fe::S) holds the real payload; k-1 random defining shares at fixed canonical non-s indices + interpolate_at for the remaining n-(k-1) indices produce the n distributed shares. The secret-at-S is NEVER returned (it is the recovery target only).

Works identically for entr and mnem (byte-agnostic); language survives a mnem split (it rides the secret-at-S wire bytes).