Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce claimable balance IDs to be 72-byte strings. #390

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## Update

- Add an additional parameter check to `claimClaimableBalance` to fail faster ([#390](https://github.com/stellar/js-stellar-base/pull/390)).

## [v4.0.3](https://github.com/stellar/js-stellar-base/compare/v4.0.2..v4.0.3)

## Update
Expand Down
5 changes: 4 additions & 1 deletion src/operations/claim_claimable_balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import xdr from '../generated/stellar-xdr_generated';
*
*/
export function claimClaimableBalance(opts = {}) {
if (typeof opts.balanceId !== 'string') {
if (
typeof opts.balanceId !== 'string' ||
opts.balanceId.length !== 8 + 64 /* 8b discriminant + 64b string */
) {
throw new Error('must provide a valid claimable balance Id');
}
const attributes = {};
Expand Down
7 changes: 7 additions & 0 deletions test/unit/operation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,13 @@ describe('Operation', function() {
/must provide a valid claimable balance Id/
);
});
it('throws an error for invalid balanceIds', function() {
expect(() =>
StellarBase.Operation.claimClaimableBalance({
balanceId: 'badc0ffee'
})
).to.throw(/must provide a valid claimable balance Id/);
});
});

describe('beginSponsoringFutureReserves()', function() {
Expand Down