Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

README.md

1.80 Kb · 39 lines

gno.land/p/moul/x/daily/luhn/v0

Luhn mod-10 checksumValid, CheckDigit, Append, MaxLen.

The check behind credit-card numbers, IMEIs and many national ID schemes (Hans Peter Luhn, 1954). Spaces and hyphens are ignored, so the formatting a human would paste works as-is.

1import "gno.land/p/moul/x/daily/luhn/v0"
2
3luhn.Valid("4539 1488 0343 6467")   // true  — separators ignored
4luhn.Valid("4539148803436468")      // false — one digit off
5luhn.CheckDigit("7992739871")       // 3, true
6luhn.Append("7992739871")           // "79927398713", true

⚠️ A typo check, not a security check. Luhn catches every single-digit error and nearly every transposition of adjacent digits, but anyone can compute a valid number in a second, and validity says nothing about whether the identifier exists. Never use it to authorize anything on-chain.

MaxLen (64) bounds an input so validation gas stays predictable. Note that a string of zeros is technically Luhn-valid and is accepted — reject it in the caller if your domain needs to.

Live demo: r/moul/x/daily/luhndemo · render it at /r/moul/x/daily/luhndemo/v0.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.