Skip to content

Accept 32-byte claimable balance StrKeys#974

Open
chrisx9z wants to merge 1 commit into
stellar:masterfrom
chrisx9z:fix/claimable-balance-strkey-length
Open

Accept 32-byte claimable balance StrKeys#974
chrisx9z wants to merge 1 commit into
stellar:masterfrom
chrisx9z:fix/claimable-balance-strkey-length

Conversation

@chrisx9z

@chrisx9z chrisx9z commented Jun 6, 2026

Copy link
Copy Markdown

Summary

  • accept standard 56-character / 32-byte claimable balance B-addresses in StrKey validation
  • keep existing 58-character / 33-byte v0 claimable balance validation for compatibility
  • reject 33-byte claimable balance payloads with a non-v0 discriminant
  • add focused StrKey tests for both accepted forms and the invalid discriminant case

Fixes #965.

Verification

  • node --check src/strkey.js
  • node --check test/unit/strkey_test.js
  • corepack yarn mocha test/unit/strkey_test.js --grep claimableBalances --require @babel/register --require ./test/test-helper.js
  • corepack yarn mocha test/unit/strkey_test.js --require @babel/register --require ./test/test-helper.js
  • corepack yarn eslint -c ./config/.eslintrc.js src/strkey.js
  • git diff --check

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.

Copilot AI review requested due to automatic review settings June 6, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/strkey.js
Comment on lines +305 to 307
if (encoded.length !== 56 && encoded.length !== 58) {
return false;
}
Comment thread src/strkey.js
Comment on lines +344 to +347
return (
decoded.length === 32 ||
(decoded.length === 32 + 1 && decoded[0] === 0)
);
Comment thread test/unit/strkey_test.js
Comment on lines +460 to +465
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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/strkey.js
case 'claimableBalance':
return decoded.length === 32 + 1; // +1 byte for discriminant
return (
decoded.length === 32 ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

StrKey validation for claimable balance ID expects 58 character string instead of 56

2 participants