feat(intid): add _check variants for Crockford Base32 and Base58Check#76
Conversation
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Adds checksum-bearing
_checkvariants of the integer-typed encoders/decoders inyabase/intidfor both Crockford Base32 and Base58Check. Closes #73.Changes
src/yabase/intid.gleamencode_int_base32_crockford_check(value: Int) -> Stringdecode_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 to0)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 surfacesInvalidChecksum— the whole point of the_checkvariant.CHANGELOG.md— Unreleased entry under### Added.Design Decisions
String; decoders returnResult(Int, CodecError); bounded decoders take labeledinput:/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.0. The byte-orientedyabase/base58check.encoderequires a version, but the int-typed entry point is used for opaque integer IDs (autoincrement keys, sequence numbers).0is the Bitcoin mainnet P2PKH default and the only choice that letsencode_int_base58checkreturnString(notResult(String, _)). Callers who care about the version still haveyabase/base58check.encode/2directly. The encoder usesresult.unwrap("")over the underlyingResultbecause version0is always in range — the""branch is unreachable, and the docstring spells out why it isn't surfaced.decode_int_*in the module: callers can distinguish "no ID supplied" from "ID is zero" without ceremony.decode_int_*_boundedand returnError(Overflow)if the decoded value exceedsmax. The checksum is verified before the bounds check, so a corrupted input fails asInvalidChecksumrather thanOverflow— clearer signal for the caller.Limitations
0. Callers who need a different version byte must drop toyabase/base58check.encode/2with their ownBitArraypayload. The docstring onencode_int_base58checkcalls this out.