-
Notifications
You must be signed in to change notification settings - Fork 5
Get the account id for a public key #20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |||||||
| #include <RippleKey.h> | ||||||||
| #include <Serialize.h> | ||||||||
|
|
||||||||
| #include <ripple/basics/Slice.h> | ||||||||
| #include <ripple/basics/StringUtilities.h> | ||||||||
| #include <ripple/beast/core/SemanticVersion.h> | ||||||||
| #include <ripple/beast/unit_test.h> | ||||||||
| #include <ripple/protocol/BuildInfo.h> | ||||||||
|
|
@@ -285,6 +287,36 @@ doCreateKeyfile( | |||||||
| return EXIT_SUCCESS; | ||||||||
| } | ||||||||
|
|
||||||||
| int | ||||||||
| doPublicKey(std::string const& publicKeyHex) | ||||||||
| { | ||||||||
| auto const error = [&publicKeyHex]() -> boost::optional<char const*> { | ||||||||
| using namespace ripple; | ||||||||
| if (auto blob = strUnHex(publicKeyHex)) | ||||||||
| { | ||||||||
| auto const slice = makeSlice(*blob); | ||||||||
| if (!publicKeyType(slice)) | ||||||||
| return "Bad public key format."; | ||||||||
| PublicKey const publicKey(slice); | ||||||||
| auto const idSigner = calcAccountID(publicKey); | ||||||||
| std::cout << "Public key: " << publicKey | ||||||||
| << "\nAccount ID: " << idSigner << std::endl; | ||||||||
|
||||||||
| << "\nAccount ID: " << idSigner << std::endl; | |
| << "\nAccount ID: " << toBase58(idSigner) << std::endl; |
Copilot
AI
Mar 4, 2026
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.
The publickey command action dereferences *publicKeyHex without a BOOST_ASSERT(publicKeyHex) like the other input-required commands (serialize, deserialize, sign, etc.). Even though runCommand should enforce the invariant, adding the assert keeps behavior consistent and avoids undefined behavior if the input dispatch changes later.
| [](auto const& publicKeyHex, auto const&, auto const&) { | |
| [](auto const& publicKeyHex, auto const&, auto const&) { | |
| BOOST_ASSERT(publicKeyHex); |
Copilot
AI
Mar 4, 2026
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.
The help text for publickey doesn't mention that --stdin is also accepted (since runCommand supports InputType::readstdin for commands with allowNoInput == false). Either document publickey <hex public key>|--stdin like the other commands, or explicitly reject --stdin for this command if it's not intended.
| publickey <hex public key> Get the account id from | |
| publickey <hex public key>|--stdin Get the account id from |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -625,6 +625,35 @@ class OfflineTool_test : public beast::unit_test::suite | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| void | ||||||
| testPublicKey() | ||||||
| { | ||||||
| testcase("Get AccountID from Public Key"); | ||||||
|
|
||||||
| std::string const pkHex{ | ||||||
| "036F382B723879499B6067B00B241DDF6FBA7599E9F6BF36A422150CEE75FF08F" | ||||||
| "8"}; | ||||||
| std::string const account{"rGse36vmL3teKPJwHvKaqgxKkrMKEbATGN"}; | ||||||
|
|
||||||
| auto const [out, err] = [&pkHex, this]() { | ||||||
|
||||||
| auto const [out, err] = [&pkHex, this]() { | |
| auto const [out, err] = [&pkHex]() { |
Copilot
AI
Mar 4, 2026
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.
testPublicKey doesn't currently exercise the failure paths added in doPublicKey (invalid hex and invalid public-key bytes). Adding negative tests here would protect the new error handling and output formatting from regressions.
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.
doPublicKeyintroducesboost::optionaljust to carry an error message, while the rest of this file primarily usesstd::optional. Consider switching this tostd::optional<std::string>(or similar) and returning owned strings instead ofchar const*to avoid mixing optional types and to keep error handling consistent.