java-stellar-sdk
java-stellar-sdk copied to clipboard
Feature Request: Provide a simple way for decoding the public key as simple String.
Hi, Stellar SDK team
What problem does your feature solve?
Provide a simple way for decoding the public key as simple String
What would you like to see?
StrKey.class
is closed. Maybe makes sense to make it opened?
What alternatives are there?
I don't see any other solutions. E.g. I have 'Set Option Operation' with the Signer object. I have used KeyPair.fromXdrSignerKey(operation.signer).accountId
for retrieve String representation of Public Key. But in some cases, it returns 'Invalid Public Key' exception -> 'not a valid GroupElement'. Good. But I just need to try to decode the byte array in this case.
Can you please suggest any other solution to retrieve a simple String representation of Public Key e.g. from the byte array?
On IOS SDK it retrieved like PublicKey(xdr: x).accountId
On Backend just used:
key = StrKey.decode_ed25519_public_key(public_key)
return Keypair.from_raw_ed25519_public_key(key)
Summary: It would be nice if the SDK had simple methods available for decoding, for example, an array of bytes (e.g for ed25519.uint256). As in the StrKey.class, which is closed.
Thanks.
@VicMikhailau StrKey.encodeStellarAccountId()
will convert an AccountID
instance into a string. If that function does not help you can you please provide a specific example with a sample public key
@VicMikhailau
StrKey.encodeStellarAccountId()
will convert anAccountID
instance into a string. If that function does not help you can you please provide a specific example with a sample public key
Checked. It's worked fine - I need just to receive a simple String public key (from byte array) representation:
Here I passed byte array from operation.signer.ed25519.uint256
->
StrKey.encodeStellarAccountId(byte[] data).
like StrKey.encodeStellarAccountId(operation.signer.ed25519.uint256)
And it returns the right String representation of data for all cases.
Inner method of the KeyPair class use this method StrKey.encodeStellarAccountId(byte[] data) like:
KeyPair -> public String getAccountId() {
return StrKey.encodeStellarAccountId(this.mPublicKey.getAbyte());
}
E.g. on Backend just used:
key = StrKey.decode_ed25519_public_key(public_key)
return Keypair.from_raw_ed25519_public_key(key)
But for Java Stellar SDK StrKey.class is closed. I don't see other methods for decode the byte array as a simple string.
@tamirms Updated issue description. Summary: It would be nice if the SDK had simple methods available for decoding, for example, an array of bytes (e.g for ed25519.uint256). As in the StrKey.class, which is closed. For cases when the Public Key can be not valid for some reason and must be just decoded as String.
Thanks.
Should we provide some utils for converting addresses, values, and other information in XDR? A few of functions are currently available in the Python SDK, I may add more in the future depending on user demand.
@overcat Why not? Sounds good. Additional methods and etc can be always useful. Thanks.
Please do the StrKey.class public. It can help avoiding the StrKey.class duplication on the app side.
Use case:
org.stellar.sdk.xdr.SC Address Type.SC_ADDRESS_TYPE_ACCOUNT ->
StrKey.encodeStellarAccountId(address.accountId.accountID.ed25519.uint256)