Skip to content

[Good First Issue]: use stringToByteVector utility in extractSignatureBytes #1227

@rwalworth

Description

@rwalworth

🆕🐥 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

  1. Refactor extractSignatureBytes to use the existing internal::Utilities::stringToByteVector() utility, which simplifies the function and makes it consistent with the rest of the codebase.
  2. Add a trailing newline to the end of TransactionUnitTests.cc.

👩‍💻 Implementation Steps

Part 1: Refactor extractSignatureBytes

  1. Open src/sdk/main/src/Transaction.cc
  2. Locate the extractSignatureBytes function in the anonymous namespace near the top of the file (around line 84)
  3. 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 namespace

with:

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 namespace

Part 2: Fix trailing newline

  1. Open src/sdk/tests/unit/TransactionUnitTests.cc
  2. Go to the very end of the file
  3. 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 /assign to 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!

Metadata

Metadata

Assignees

Labels

kind: refactorCode changes that neither fix a bug nor add a featurepriority: lowNon-urgent tasks, nice-to-have improvements, or minor issuesskill: good first issueSimple, well-scoped tasks ideal for someone new to the repository or open source

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions