MoonGuard is a pure-MoonBit supply chain security toolchain providing Ed25519 package signing and verification, SHA-256 manifest integrity checks, JSON+PEM trusted key management, Levenshtein and homoglyph typosquat detection, CVSS-style cumulative risk scores, JSON security reports, and a `moon_guard` CLI with subcommands for keygen, sign, verify, trust, typosquat, manifest, hash, audit, and version. Includes a runnable end-to-end audit example at `examples/basic_audit`. MoonGuard 是用纯 MoonBit 实现的 MoonBit 包供应链安全工具链,提供 Ed25519 签名、SHA-256 清单、JSON+PEM 可信密钥管理、Levenshtein 与同形(homoglyph)双模式 typosquat 检测、CVSS 风格风险评分、JSON 安全报告与 9 子命令 CLI。
moon_guard/
├── lib/
│ ├── manifest/ # Package manifest + SHA-256 hash calculation
│ ├── crypto/ # Ed25519 sign/verify (field arithmetic, SHA-512)
│ ├── trust/ # Trusted key store (in-memory, JSON and PEM persistence)
│ ├── verify/ # Audit pipeline, typosquat detection (Levenshtein + strict)
│ └── report/ # JSON security report with risk score
├── cmd/main/ # CLI entry point (moon_guard)
├── examples/ # Runnable usage examples (see examples/basic_audit)
├── moon.mod.json # Module manifest
├── README.md # This file
└── LICENSE # Apache-2.0moon run cmd/main -- <command> [args]moon_guard keygen [seed] Generate Ed25519 keypair; emit PEM envelope.
moon_guard sign <msg> <seed> Sign a UTF-8 message with a hex seed.
moon_guard verify <msg> <sig_hex> <pubkey> Verify an Ed25519 signature.
moon_guard trust add <key_id> <pubkey> <owner> [level]
Add a trusted key (level = full|partial|untrusted).
moon_guard trust list List all keys in the store.
moon_guard trust remove <key_id> Remove a trusted key.
moon_guard typosquat <name> <known...> Strict typosquat check (homoglyph aware).
moon_guard manifest gen <pkg> <ver> [f:c...] Generate manifest from path:content pairs.
moon_guard manifest verify <pkg> <ver> [f:c] Verify a manifest against inputs.
moon_guard hash <content> Compute SHA-256 hash.
moon_guard audit <pkg> <ver> [f:c...] Run full audit + emit JSON report.
moon_guard version Print version and exit.
moon_guard help Print usage.# 1. Generate a deterministic Ed25519 keypair.
moon run cmd/main -- keygen
# 2. Compute a SHA-256 hash over arbitrary content.
moon run cmd/main -- hash "Hello, MoonBit"
# 3. Sign a UTF-8 message.
moon run cmd/main -- sign "Hello, MoonBit" 9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60
# 4. Run a full audit on a synthetic package (with two files).
moon run cmd/main -- audit demo-pkg 1.0.0 \
"src/main.mbt:fn main { println(\"hello\") }" \
"src/lib.mbt:pub fn add(a: Int, b: Int) -> Int { a + b }"
# 5. Detect typosquats.
moon run cmd/main -- typosquat 1odash lodash react expressmoon run examples/basic_audit| Command | Purpose |
|---|---|
| moon test | Run the full test suite (81+ tests across 5 modules + CLI). |
| moon test --target wasm | Force the wasm backend (matches the CI matrix). |
| moon check | Lint and type-check. |
| moon check --deny-warn | Fail the build on any warning. |
| moon fmt --check | Verify formatting (CI fails on diff). |
| moon fmt | Auto-format the code. |
| moon info | Regenerate the .mbti interface files. |
| moon coverage analyze | Print uncovered code paths. |
moon login # one-time: paste your mooncakes.io token
moon publish # uploads the module as chenzehaoo/moon_guard| OS | target |
|---|---|
| ubuntu-latest | wasm |
| ubuntu-latest | native |
| macos-latest | wasm |
| macos-latest | native |
| windows-latest | wasm |
fn manifest_sha256(data : String) -> Stringfn verify_package(package_name : String, signature_hex : String, public_key_hex : String, content : String) -> VerifyResultMoonGuard is a pure-MoonBit supply chain security toolchain providing Ed25519 package signing and verification, SHA-256 manifest integrity checks, JSON+PEM trusted key management, Levenshtein and homoglyph typosquat detection, CVSS-style cumulative risk scores, JSON security reports, and a `moon_guard` CLI with subcommands for keygen, sign, verify, trust, typosquat, manifest, hash, audit, and version. Includes a runnable end-to-end audit example at `examples/basic_audit`. MoonGuard 是用纯 MoonBit 实现的 MoonBit 包供应链安全工具链,提供 Ed25519 签名、SHA-256 清单、JSON+PEM 可信密钥管理、Levenshtein 与同形(homoglyph)双模式 typosquat 检测、CVSS 风格风险评分、JSON 安全报告与 9 子命令 CLI。