moonbit-shard-note

Printable short-message shard cards with checksum validation and one-card parity recovery.

moonbit
offline
recovery
parity
checksum
paper-backup
moon add JJ-ai-nb/moonbit-shard-note@0.1.0
Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
5 hours ago
Downloads
3
README

#JJ-ai-nb/moonbit-shard-note

MoonBit package for printable short-message shard cards.

///| test { let payload = [77, 79, 79, 78, 66, 73, 84] let cards = @moonbit-shard-note.weave("readme-demo", payload, 3) let partial = [cards[0], cards[2], cards[3]] match @moonbit-shard-note.recover(partial) { @moonbit-shard-note.Restored(restored) => inspect(restored, content="[77, 79, 79, 78, 66, 73, 84]") _ => inspect("not restored", content="not restored") } }

#
Recovery

pub(all) enum Recovery {
Restored(Array[Int])
NeedCards(Array[Int])
Damaged(String)
} derive(Eq,
Debug
)

Recovery result for a deck of shard cards.

#
ShardCard

pub(all) struct ShardCard {
deck : String
index : Int
data_count : Int
width : Int
original_len : Int
checksum : Int
cells : Array[Int]
} derive(Eq,
Debug
)

A printable shard card. index == data_count is the parity card.

#
demo_payload

fn demo_payload() -> Array[Int]

A small built-in demo payload. It spells "MOONBIT" as byte values.

#
recover

fn recover(cards : Array[ShardCard]) -> Recovery

Recover the original payload when all data cards exist, or when exactly one data card is missing but the parity card is present.

#
render_card

fn render_card(card : ShardCard) -> String

Return a compact, copy-friendly line for one card.

#
render_sheet

fn render_sheet(cards : Array[ShardCard]) -> String

Render several cards as one printable note sheet.

#
validate_card

fn validate_card(card : ShardCard) -> Bool

Check the checksum carried by one card.

#
validation_commands

fn validation_commands() -> Array[String]

Return the expected validation commands for this package.

#
weave

fn weave(deck : String, payload : Array[Int], data_count : Int) -> Array[ShardCard]

Build data cards plus one parity card. The parity card can recover one missing data card, and every card carries a checksum for copy mistakes.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io