Skip to main content

Crate ms_codec

Crate ms_codec 

Source
Expand description

ms-codec — reference implementation of the ms1 backup format (HRP ms).

ms1 is a Bitcoin self-custody backup format for BIP-39 entropy, layered atop BIP-93 codex32 via Andrew Poelstra’s rust-codex32 crate (CC0). Designed for steel-plate engraving alongside sibling formats mk1 (xpubs) and md1 (descriptors). Every wire-format decision is judged against “does this make a steel-plate backup more correct, or less?”

See SPEC_ms_v0_1.md for the full wire-format specification and MIGRATION.md for the v0.1 → v0.2 K-of-N share-encoding migration contract.

§Quickstart

use ms_codec::{encode, decode, Payload, Tag};

let entropy = vec![0xAAu8; 16]; // 12-word BIP-39 entropy
let s = encode(Tag::ENTR, &Payload::Entr(entropy.clone())).unwrap();
assert_eq!(s.len(), 50); // 12-word entr = 50-char ms1 string

let (tag, payload) = decode(&s).unwrap();
assert_eq!(tag, Tag::ENTR);
assert_eq!(payload, Payload::Entr(entropy));

§v0.1 scope

  • In: BIP-39 entropy (16/20/24/28/32 B). Tag: entr.
  • Out: Direct BIP-32 master seed (64 B) and serialized xpriv (78 B) — reserved-not-emitted in v0.1; deferred to v0.2+ with separate framing (they overflow BIP-93 codex32’s length brackets when prepended with the v0.2-migration prefix byte). The master-seed backup use case is preserved via the application-layer routing BIP-39 phrase → entropy → ms1 entr → engrave → recover → BIP-39 mnemonic → PBKDF2 → master seed. See SPEC §1.2.

Re-exports§

pub use decode::decode;
pub use encode::encode;
pub use error::Error;
pub use error::Result;
pub use inspect::inspect;
pub use inspect::InspectReport;
pub use payload::Payload;
pub use payload::PayloadKind;
pub use tag::Tag;

Modules§

consts
v0.1 wire-format constants.
decode
Public decoder. Applies SPEC §4 validity rules in order.
encode
Public encoder. v0.1 entr-only; future kinds in v0.2+ via the envelope seam.
error
ms-codec error taxonomy. Variants mirror SPEC §4 decoder validity rules plus the encoder-side validation surface from SPEC §3.5 / §3.5.1.
inspect
Structural inspection of an ms1 string for debugging / future ms-cli.
payload
Payload type — v0.1: Entr (BIP-39 entropy) only.
tag
Tag type — 4-byte codex32-alphabet validated type tag.