Skip to content

feat(intid): add _check variants for Crockford Base32 and Base58Check#76

Merged
nao1215 merged 2 commits into
mainfrom
feat/issue-73-intid-check-variants
May 9, 2026
Merged

feat(intid): add _check variants for Crockford Base32 and Base58Check#76
nao1215 merged 2 commits into
mainfrom
feat/issue-73-intid-check-variants

Conversation

@nao1215

@nao1215 nao1215 commented May 9, 2026

Copy link
Copy Markdown
Owner

Summary

Adds checksum-bearing _check variants of the integer-typed encoders/decoders in yabase/intid for both Crockford Base32 and Base58Check. Closes #73.

Changes

  • src/yabase/intid.gleam
    • encode_int_base32_crockford_check(value: Int) -> String
    • decode_int_base32_crockford_check(input: String) -> Result(Int, CodecError)
    • decode_int_base32_crockford_check_bounded(input:, max:) -> Result(Int, CodecError)
    • encode_int_base58check(value: Int) -> String (fixes version byte to 0)
    • decode_int_base58check(input: String) -> Result(Int, CodecError)
    • decode_int_base58check_bounded(input:, max:) -> Result(Int, CodecError)
  • test/intid_test.gleam — round-trip, empty-input, bounded, and typo-detection tests for both checksummed codec families. The typo tests mutate the first body character of an encoded value and assert the decoder surfaces InvalidChecksum — the whole point of the _check variant.
  • CHANGELOG.md — Unreleased entry under ### Added.

Design Decisions

  • Same shape as the existing int helpers. Encoders return String; decoders return Result(Int, CodecError); bounded decoders take labeled input:/max: arguments. Callers can swap a checked variant for an unchecked one just by changing the function name, which is the ergonomic the issue asks for.
  • Base58Check version is fixed at 0. The byte-oriented yabase/base58check.encode requires a version, but the int-typed entry point is used for opaque integer IDs (autoincrement keys, sequence numbers). 0 is the Bitcoin mainnet P2PKH default and the only choice that lets encode_int_base58check return String (not Result(String, _)). Callers who care about the version still have yabase/base58check.encode/2 directly. The encoder uses result.unwrap("") over the underlying Result because version 0 is always in range — the "" branch is unreachable, and the docstring spells out why it isn't surfaced.
  • Empty inputs are rejected, consistent with every other decode_int_* in the module: callers can distinguish "no ID supplied" from "ID is zero" without ceremony.
  • Bounded variants mirror decode_int_*_bounded and return Error(Overflow) if the decoded value exceeds max. The checksum is verified before the bounds check, so a corrupted input fails as InvalidChecksum rather than Overflow — clearer signal for the caller.

Limitations

  • Base58Check version is hard-coded at 0. Callers who need a different version byte must drop to yabase/base58check.encode/2 with their own BitArray payload. The docstring on encode_int_base58check calls this out.

@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@nao1215 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 44 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ac74a69a-83d7-43b9-a32d-aaaaf446fff9

📥 Commits

Reviewing files that changed from the base of the PR and between 7e9a056 and 3d6bc9a.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/yabase/intid.gleam
  • test/intid_test.gleam
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-73-intid-check-variants

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nao1215 nao1215 merged commit 6039923 into main May 9, 2026
8 checks passed
@nao1215 nao1215 deleted the feat/issue-73-intid-check-variants branch May 9, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intid: add _check variants for crockford and base58 to remove the int↔BitArray dance

1 participant