const MaxLen
MaxLen bounds an input so validation gas stays predictable.
Package luhn implements the Luhn mod-10 checksum (Hans Peter Luhn, 1954) as a pure, reusable package: the check used ...
gno.land/p/moul/x/daily/luhn/v0Luhn mod-10 checksum — Valid, 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.
Package luhn implements the Luhn mod-10 checksum (Hans Peter Luhn, 1954) as a pure, reusable package: the check used by credit-card numbers, IMEIs and many national ID schemes to catch typos and single-digit transpositions.
It is a *checksum*, not a security primitive: it detects every single-digit error and almost every adjacent transposition, but it is trivial to forge and says nothing about whether an identifier actually exists. Never use it to authorize anything on-chain.
No clocks, no randomness, no chain imports — same input, same output.
A live demo of this package is at r/moul/x/daily/luhndemo(/r/moul/x/daily/luhndemo/v0).
Append returns payload with its Luhn check digit appended (digits only, separators stripped), and whether the payload was usable.
CheckDigit returns the digit that must be appended to payload to make the whole string Luhn-valid, and whether the payload was usable.
Valid reports whether s carries a correct Luhn check digit.
Spaces and hyphens are ignored, so "4539 1488 0343 6467" and "4539-1488-0343-6467" both work. Any other non-digit makes it false, as does an empty/1-digit input or one longer than MaxLen. A string of all zeros is technically Luhn-valid and is accepted — reject it in the caller if your domain needs to.