Accept 32-byte claimable balance StrKeys#974
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for claimable balance StrKeys that omit the discriminant byte while tightening validation for discriminant-bearing payloads.
Changes:
- Accept claimable balance StrKeys encoding either 32-byte payloads (no discriminant) or 33-byte payloads (v0 discriminant only).
- Add unit coverage for 32-byte claimable balance StrKeys and rejection of non-v0 discriminants.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/unit/strkey_test.js | Adds tests for 32-byte claimable balance StrKeys and invalid non-v0 discriminant cases. |
| src/strkey.js | Updates isValid logic for claimable balance StrKeys to accept 56/58-char encodings and enforce v0 discriminant semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (encoded.length !== 56 && encoded.length !== 58) { | ||
| return false; | ||
| } |
| return ( | ||
| decoded.length === 32 || | ||
| (decoded.length === 32 + 1 && decoded[0] === 0) | ||
| ); |
| it('rejects a 33-byte strkey with a non-v0 discriminant', function () { | ||
| const asHex = | ||
| '013f0c34bf93ad0d9971d04ccc90f705511c838aad9734a4a2fb0d7a03fc7fe89a'; | ||
| const strkey = StellarBase.StrKey.encodeClaimableBalance( | ||
| Buffer.from(asHex, 'hex') | ||
| ); |
Comment: Allows standard 32-byte claimable balance B-address validation while preserving v0 legacy support.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2823285cdd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case 'claimableBalance': | ||
| return decoded.length === 32 + 1; // +1 byte for discriminant | ||
| return ( | ||
| decoded.length === 32 || |
There was a problem hiding this comment.
Preserve the v0 discriminant for Address conversion
When a standard 56-character claimable-balance StrKey is now accepted here, new Address(bAddress) stores only the 32-byte hash returned by decodeClaimableBalance; later Address.toScAddress() treats this._key.at(0) as the claimable-balance discriminant and subarray(1) as the payload. For any code that parses one of these newly-valid B-addresses and converts it to an ScAddress, the first hash byte is used as the enum value instead of v0, so conversion throws or builds the wrong XDR. The newly accepted 32-byte form needs to be normalized to the existing v0+hash representation before Address uses it.
Useful? React with 👍 / 👎.
Summary
Fixes #965.
Verification
Note: linting the whole legacy strkey_test.js file reports pre-existing style violations, so the source lint check was scoped to src/strkey.js while the full strkey test file was verified with mocha.