-
Notifications
You must be signed in to change notification settings - Fork 159
feat: improve StrKey.
#702
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
Conversation
- feat: add `isValidEd25519SecretSeed`, `isValidPreAuthTx` and `isValidSha256Hash` to `StrKey` class, these functions can be used to validate the corresponding strkey. - feat: add med25519 public key support to `StrKey`. - refactor!: the following functions in `StrKey` are marked as deprecated, they will be removed in the next major release; please refer to the documentation for each function to see the corresponding replacement functions: - `StrKey#encodeEd25519PublicKey(AccountID)` - `StrKey#encodeMuxedAccount(MuxedAccount)` - `StrKey#decodeMuxedAccount(String)` - `StrKey#encodeToXDRAccountId(String)` - `StrKey#encodeToXDRMuxedAccount(String)`
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## add-protocol23-support #702 +/- ##
=========================================================
Coverage ? 80.46%
Complexity ? 1247
=========================================================
Files ? 213
Lines ? 4961
Branches ? 416
=========================================================
Hits ? 3992
Misses ? 713
Partials ? 256
🚀 New features to boost your workflow:
|
- feat: add `isValidEd25519SecretSeed`, `isValidPreAuthTx` and `isValidSha256Hash` to `StrKey` class, these functions can be used to validate the corresponding strkey. - feat: add med25519 public key support to `StrKey`. - refactor!: the following functions in `StrKey` are marked as deprecated, they will be removed in the next major release; please refer to the documentation for each function to see the corresponding replacement functions: - `StrKey#encodeEd25519PublicKey(AccountID)` - `StrKey#encodeMuxedAccount(MuxedAccount)` - `StrKey#decodeMuxedAccount(String)` - `StrKey#encodeToXDRAccountId(String)` - `StrKey#encodeToXDRMuxedAccount(String)`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the StrKey utility with new validation methods, adds full support for med25519 (“M…”) public keys, and refactors legacy XDR encoding/decoding calls to use MuxedAccount and KeyPair APIs.
- Added
isValid*methods (seed, preauth tx, SHA-256 hash, contract, liquidity pool, claimable balance, Ed25519, med25519) plusencodeMed25519PublicKey/decodeMed25519PublicKeyinStrKey. - Deprecated old StrKey encode/decode methods (
encodeEd25519PublicKey(AccountID),encodeMuxedAccount,decodeMuxedAccount,encodeToXDRAccountId,encodeToXDRMuxedAccount) ahead of the next major release. - Updated XDR conversion across operations and transaction classes to replace
StrKey-based calls withMuxedAccountandKeyPair.fromAccountId.
Reviewed Changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File or Package | Description |
|---|---|
| src/main/java/org/stellar/sdk/StrKey.java | Introduced validation methods and med25519 support; deprecated legacy StrKey encode/decode. |
| src/test/java/org/stellar/sdk/StrKeyTest.java | Added tests for many new isValid* methods and med25519 public key support. |
| src/main/java/org/stellar/sdk/operations/* | Replaced all StrKey.encode*/decode* XDR calls with MuxedAccount and KeyPair. |
| src/main/java/org/stellar/sdk/MuxedAccount.java | Overhauled constructor and getAddress to handle med25519; removed legacy StrKey use. |
| src/main/java/org/stellar/sdk/Server.java | Updated memo-required logic to use StrKey.isValidMed25519PublicKey instead of hashMemoId. |
| CHANGELOG.md | Documented new features and breaking changes. |
Comments suppressed due to low confidence (2)
src/main/java/org/stellar/sdk/StrKey.java:58
- Add unit tests for isValidEd25519PublicKey to ensure correct validation behavior for valid and invalid G... account IDs.
public static boolean isValidEd25519PublicKey(String accountID) {
src/main/java/org/stellar/sdk/StrKey.java:281
- Add unit tests for isValidLiquidityPool and isValidClaimableBalance to cover valid and invalid L... and B... identifiers.
public static boolean isValidLiquidityPool(String liquidityPoolId) {
| SetTrustLineFlagsOp op = new SetTrustLineFlagsOp(); | ||
|
|
||
| op.setTrustor(StrKey.encodeToXDRAccountId(this.trustor)); | ||
| op.setTrustor(KeyPair.fromAccountId(this.trustor).getXdrAccountId()); |
Copilot
AI
Jul 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The conversion from a string account ID to XDR AccountID is repeated across operations; consider extracting this into a shared utility method (e.g., toXdrAccountId) to reduce duplication.
| this.accountId = StrKey.encodeEd25519PublicKey(ed25519PublicKey); | ||
| this.muxedId = new BigInteger(1, muxedIdBytes); | ||
| } else { | ||
| throw new IllegalArgumentException("Invalid address"); |
Copilot
AI
Jul 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the invalid address in the exception message to make debugging easier, for example: Invalid address: " + address.
| throw new IllegalArgumentException("Invalid address"); | |
| throw new IllegalArgumentException("Invalid address: " + address); |
isValidEd25519SecretSeed,isValidPreAuthTxandisValidSha256HashtoStrKeyclass, these functions can be used to validate the corresponding strkey.StrKey.StrKeyare marked as deprecated, they will be removed in the next major release; please refer to the documentation for each function to see the corresponding replacement functions:StrKey#encodeEd25519PublicKey(AccountID)StrKey#encodeMuxedAccount(MuxedAccount)StrKey#decodeMuxedAccount(String)StrKey#encodeToXDRAccountId(String)StrKey#encodeToXDRMuxedAccount(String)