-
Notifications
You must be signed in to change notification settings - Fork 70
[Good First Issue]: use stringToByteVector utility in extractSignatureBytes #1227
Description
🆕🐥 First-Time Friendly
This issue is especially welcoming for people who are new to contributing to the Hiero C++ SDK.
We know that opening your first pull request can feel like a big step.
Issues labeled Good First Issue are designed to make that experience easier, clearer, and more comfortable.
No prior knowledge of Hiero, Hedera, or distributed ledger technology is required.
Just a basic familiarity with C++ and Git is more than enough to get started.
👾 Description of the Issue
The extractSignatureBytes helper function in Transaction.cc manually converts a std::string to std::vector<std::byte> using std::transform, but the codebase already has a utility function that does exactly the same thing: internal::Utilities::stringToByteVector().
The current implementation:
std::vector<std::byte> sigBytes(sigStr->size());
std::transform(sigStr->begin(), sigStr->end(), sigBytes.begin(), [](char c) { return static_cast<std::byte>(c); });
return sigBytes;The rest of the file uses stringToByteVector for the same conversion (e.g., in getSignaturesInternal), so this helper should too.
Additionally, the test file TransactionUnitTests.cc is missing a trailing newline at the end of the file, which should be added for POSIX compliance and consistency with the other files in the repository.
💡 Proposed Solution
- Refactor
extractSignatureBytesto use the existinginternal::Utilities::stringToByteVector()utility, which simplifies the function and makes it consistent with the rest of the codebase. - Add a trailing newline to the end of
TransactionUnitTests.cc.
👩💻 Implementation Steps
Part 1: Refactor extractSignatureBytes
- Open
src/sdk/main/src/Transaction.cc - Locate the
extractSignatureBytesfunction in the anonymous namespace near the top of the file (around line 84) - Replace the current implementation:
namespace
{
/**
* Helper function - Extract the raw signature bytes from a protobuf SignaturePair.
*/
std::vector<std::byte> extractSignatureBytes(const proto::SignaturePair& pair)
{
const std::string* sigStr = nullptr;
if (pair.has_ed25519())
{
sigStr = &pair.ed25519();
}
else if (pair.has_ecdsa_secp256k1())
{
sigStr = &pair.ecdsa_secp256k1();
}
else
{
throw IllegalStateException("Unknown signature type");
}
std::vector<std::byte> sigBytes(sigStr->size());
std::transform(sigStr->begin(), sigStr->end(), sigBytes.begin(), [](char c) { return static_cast<std::byte>(c); });
return sigBytes;
}
} // anonymous namespacewith:
namespace
{
/**
* Extract the raw signature bytes from a protobuf SignaturePair.
*/
std::vector<std::byte> extractSignatureBytes(const proto::SignaturePair& pair)
{
if (pair.has_ed25519())
{
return internal::Utilities::stringToByteVector(pair.ed25519());
}
if (pair.has_ecdsa_secp256k1())
{
return internal::Utilities::stringToByteVector(pair.ecdsa_secp256k1());
}
throw IllegalStateException("Unknown signature type");
}
} // anonymous namespacePart 2: Fix trailing newline
- Open
src/sdk/tests/unit/TransactionUnitTests.cc - Go to the very end of the file
- Ensure there is a newline character after the final closing
}brace
Most editors will show this as "no newline at end of file" — simply press Enter after the last } to add one.
✅ Acceptance Criteria
To merge a pull request for this issue:
- Scope: Changes are limited to the two files listed below
- Behavior: No SDK behavior or public API changes (the refactored function produces identical output)
- Tests: Existing CI checks pass
- Review: All code review feedback addressed
📋 Step-by-Step Contribution Guide
- Comment
/assignto request the issue - Wait for assignment
- Fork the repository and create a branch
- Set up the project by following the instructions in
README.md - Make the requested changes
- Sign each commit using
-s -S - Push your branch and open a pull request
Read Workflow Guide for step-by-step workflow guidance.
Read README.md for setup instructions.
❗ Pull requests cannot be merged without S and s signed commits.
See the Signing Guide.
🤔 Additional Information
This issue was identified during the review of #1218 (which added the removeSignature and removeAllSignatures methods).
Files to Change
| File | Change |
|---|---|
src/sdk/main/src/Transaction.cc |
Refactor extractSignatureBytes to use stringToByteVector |
src/sdk/tests/unit/TransactionUnitTests.cc |
Add trailing newline at end of file |
Reference
The existing usage of stringToByteVector in the same file can be seen in the getSignaturesInternal method, which does the same string-to-byte-vector conversion for signature data.
If you have questions while working on this issue, feel free to ask!
You can reach the community and maintainers here:
Hiero-SDK-C++ Discord
Maintainers are happy to help first-time contributors succeed!