Skip to main content

mk_codec/
lib.rs

1//! `mk-codec` — reference implementation of the **Mnemonic Key (MK)** backup format.
2//!
3//! Status: v0.1 implementation in progress. Wire format is locked
4//! per the closure design at
5//! `docs/superpowers/specs/2026-04-29-mk1-open-questions-closure-design.md`.
6//! The bytecode and string-layer encoders/decoders land in subsequent
7//! phases of `design/IMPLEMENTATION_PLAN_mk_v0_1.md`.
8//!
9//! See for the design surface:
10//!
11//! - `design/SPEC_mk_v0_1.md` — wire-format spec (post-closure)
12//! - `design/DECISIONS.md` — rolling decisions log including D-1..D-15 and Q-1..Q-10 closures
13//! - `design/IMPLEMENTATION_PLAN_mk_v0_1.md` — v0.1 implementation plan
14//! - `design/FOLLOWUPS.md` — deferred items, pre-BIP-submission audit gates, cross-repo coordination
15//! - `bip/bip-mnemonic-key.mediawiki` — BIP draft
16//!
17//! See for related sibling project:
18//!
19//! - [`bg002h/descriptor-mnemonic`](https://github.com/bg002h/descriptor-mnemonic) —
20//!   the MD policy-template format and its `md-codec` reference implementation. MK
21//!   is designed to engrave alongside MD policy cards for foreign-xpub multisig
22//!   recovery.
23//!
24//! # Eventual factoring
25//!
26//! Per `design/DECISIONS.md` D-13, this crate initially **forks** the
27//! BCH primitives from the sibling `md-codec`. The shared codex32-derived
28//! plumbing extracts to a third crate (`mc-codex32`, likely a third
29//! sibling repo) once both formats are implementation-validated; the
30//! trigger condition (closure Q-9) is "both md-codec and mk-codec at v1.0
31//! with cross-validated conformance vectors and stable public APIs."
32//! Until then, fork-from-md-codec; both implementations carry their own
33//! BCH-primitives copy.
34
35#![cfg_attr(not(test), deny(missing_docs))]
36
37pub mod bytecode;
38pub mod consts;
39pub mod error;
40pub mod key_card;
41pub mod string_layer;
42pub mod test_vectors;
43
44pub use consts::{
45    CHUNKED_FRAGMENT_LONG_BYTES, CHUNKED_FRAGMENT_REGULAR_BYTES, CROSS_CHUNK_HASH_BYTES,
46    GENERATOR_FAMILY, HRP, MAX_CHUNKS, MAX_PATH_COMPONENTS, MK_LONG_CONST, MK_REGULAR_CONST,
47    NUMS_DOMAIN, ORIGIN_FINGERPRINT_BYTES, POLICY_ID_STUB_BYTES, SINGLE_STRING_LONG_BYTES,
48    SINGLE_STRING_REGULAR_BYTES, XPUB_COMPACT_BYTES,
49};
50pub use error::{Error, Result};
51pub use key_card::{KeyCard, decode, encode, encode_with_chunk_set_id};