Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- This applies to `submit`, `signAndSubmit`, `restoreFootprint`, and therefore to `ContractClient.invoke` when it submits.
- fix: always encode text as UTF-8 in `Scv.toString(String)`, `Sep10Challenge` (`web_auth_domain` / `client_domain`), `Util.paddedByteArray(String, int)`, and the `SorobanServer` request body. They used the JVM default charset, so non-ASCII text produced different bytes on JVMs where that is not UTF-8.
- chore: upgrade generated XDR definitions to Protocol 30.
- fix: `StrKey.decodeClaimableBalance` and `StrKey.isValidClaimableBalance` now reject a claimable balance strkey (`B...`) whose type byte is not 0, as SEP-23 requires; `CLAIMABLE_BALANCE_ID_TYPE_V0` is the only type. Such a key used to be accepted, so `new Address(...)` took it and the error only surfaced in `Address.toSCAddress`. `new Address(...)` now throws `IllegalArgumentException` up front.
- refactor: deprecate `GetEventsResponse.EventInfo.inSuccessfulContractCall`. Stellar RPC no longer returns it from `getEvents` ([stellar-rpc#1050](https://github.com/stellar/stellar-rpc/pull/1050)), so it is `null` with newer servers. It will be removed in the next major release.

## 5.0.0
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/stellar/sdk/StrKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ static byte[] decodeCheck(VersionByte versionByte, char[] encoded) {
throw new IllegalArgumentException(
"Invalid data length, expected 33 bytes, got " + data.length);
}
// SEP-23: the first byte is the claimable balance type, and CLAIMABLE_BALANCE_ID_TYPE_V0
// is the only one.
if (data[0] != 0) {
throw new IllegalArgumentException(
"Invalid claimable balance type, expected 0 (CLAIMABLE_BALANCE_ID_TYPE_V0), got "
+ data[0]);
}
break;
default:
if (data.length != 32) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/kotlin/org/stellar/sdk/AddressTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ class AddressTest :
address.addressType shouldBe Address.AddressType.LIQUIDITY_POOL
}

test("should throw exception for claimable balance ID with a non-zero type") {
val exception =
shouldThrow<IllegalArgumentException> {
Address("BAAT6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGXACA")
}
exception.message shouldBe "Unsupported address type"
}

test("should throw exception for invalid address") {
val exception = shouldThrow<IllegalArgumentException> { Address(invalidAddress) }
exception.message shouldBe "Unsupported address type"
Expand Down
20 changes: 17 additions & 3 deletions src/test/kotlin/org/stellar/sdk/StrKeyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ class StrKeyTest :
StrKey.isValidClaimableBalance(
"BAT7RRVQBTQ3TEDLDICV7GNX6GE3KVQFJCNOESUI4QNA4TYYR44P2FS5PZYQ"
) shouldBe false
// SEP-23: invalid claimable balance type (first byte of binary key is not 0)
StrKey.isValidClaimableBalance(
"BAAT6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGXACA"
) shouldBe false
}

test("decode rejects a non-zero claimable balance type") {
val exception =
shouldThrow<IllegalArgumentException> {
StrKey.decodeClaimableBalance(
"BAAT6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGXACA"
)
}
exception.message shouldBe
"Invalid claimable balance type, expected 0 (CLAIMABLE_BALANCE_ID_TYPE_V0), got 1"
}
}

Expand Down Expand Up @@ -355,9 +370,8 @@ class StrKeyTest :
"PA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAOQCAQDAQCQMBYIBEFAWDANBYHRAEISCMKBKFQXDAMRUGY4Z2PQ",
"PA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAOQCAQDAQCQMBYIBEFAWDANBYHRAEISCMKBKFQXDAMRUGY4DXFH6",
"BAAD6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGR4TV",
// We should consider this valid
// Invalid claimablebalance type (first byte of binary key is not 0),
// "BAAT6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGXACA"
// Invalid claimable balance type (first byte of binary key is not 0)
"BAAT6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGXACA",
"",
) { key ->
shouldThrow<IllegalArgumentException> { StrKey.decodeEd25519PublicKey(key) }
Expand Down
Loading