|
76 | 76 |
|
77 | 77 | namespace Hiero |
78 | 78 | { |
| 79 | + |
| 80 | +namespace |
| 81 | +{ |
| 82 | +/** |
| 83 | + * Helper function - Extract the raw signature bytes from a protobuf SignaturePair. |
| 84 | + */ |
| 85 | +std::vector<std::byte> extractSignatureBytes(const proto::SignaturePair& pair) |
| 86 | +{ |
| 87 | + const std::string* sigStr = nullptr; |
| 88 | + if (pair.has_ed25519()) |
| 89 | + { |
| 90 | + sigStr = &pair.ed25519(); |
| 91 | + } |
| 92 | + else if (pair.has_ecdsa_secp256k1()) |
| 93 | + { |
| 94 | + sigStr = &pair.ecdsa_secp256k1(); |
| 95 | + } |
| 96 | + else |
| 97 | + { |
| 98 | + throw IllegalStateException("Unknown signature type"); |
| 99 | + } |
| 100 | + |
| 101 | + std::vector<std::byte> sigBytes(sigStr->size()); |
| 102 | + std::transform(sigStr->begin(), sigStr->end(), sigBytes.begin(), [](char c) { return static_cast<std::byte>(c); }); |
| 103 | + return sigBytes; |
| 104 | +} |
| 105 | +} // anonymous namespace |
| 106 | + |
79 | 107 | //----- |
80 | 108 | template<typename SdkRequestType> |
81 | 109 | struct Transaction<SdkRequestType>::TransactionImpl |
@@ -566,7 +594,6 @@ std::vector<std::vector<std::byte>> Transaction<SdkRequestType>::removeSignature |
566 | 594 | throw IllegalStateException("Removing a signature from a Transaction requires " |
567 | 595 | "the Transaction to be frozen"); |
568 | 596 | } |
569 | | - |
570 | 597 | if (!keyAlreadySigned(publicKey)) |
571 | 598 | { |
572 | 599 | throw IllegalStateException("The public key has not signed this transaction"); |
@@ -597,30 +624,9 @@ std::vector<std::vector<std::byte>> Transaction<SdkRequestType>::removeSignature |
597 | 624 | for (int i = sigPairs->size() - 1; i >= 0; --i) |
598 | 625 | { |
599 | 626 | const auto& pair = sigPairs->at(i); |
600 | | - |
601 | 627 | if (pair.pubkeyprefix() == pubKeyPrefixStr) |
602 | 628 | { |
603 | | - const std::string* sigStr = nullptr; |
604 | | - if (pair.has_ed25519()) |
605 | | - { |
606 | | - sigStr = &pair.ed25519(); |
607 | | - } |
608 | | - else if (pair.has_ecdsa_secp256k1()) |
609 | | - { |
610 | | - sigStr = &pair.ecdsa_secp256k1(); |
611 | | - } |
612 | | - else |
613 | | - { |
614 | | - throw IllegalStateException("Unknown signature type"); |
615 | | - } |
616 | | - |
617 | | - // Extract the bytes and save them to return to the caller |
618 | | - std::vector<std::byte> sigBytes(sigStr->size()); |
619 | | - std::transform( |
620 | | - sigStr->begin(), sigStr->end(), sigBytes.begin(), [](char c) { return static_cast<std::byte>(c); }); |
621 | | - |
622 | | - removedSignatures.push_back(std::move(sigBytes)); |
623 | | - |
| 629 | + removedSignatures.push_back(extractSignatureBytes(pair)); |
624 | 630 | // Erase the signature directly from the Protobuf array |
625 | 631 | sigPairs->erase(sigPairs->begin() + i); |
626 | 632 | } |
@@ -682,25 +688,7 @@ Transaction<SdkRequestType>::removeAllSignatures() |
682 | 688 | auto it = prefixToKey.find(pair.pubkeyprefix()); |
683 | 689 | if (it != prefixToKey.end()) |
684 | 690 | { |
685 | | - const std::string* sigStr = nullptr; |
686 | | - if (pair.has_ed25519()) |
687 | | - { |
688 | | - sigStr = &pair.ed25519(); |
689 | | - } |
690 | | - else if (pair.has_ecdsa_secp256k1()) |
691 | | - { |
692 | | - sigStr = &pair.ecdsa_secp256k1(); |
693 | | - } |
694 | | - else |
695 | | - { |
696 | | - throw IllegalStateException("Unknown signature type"); |
697 | | - } |
698 | | - |
699 | | - // Convert and store the extracted signature bytes |
700 | | - std::vector<std::byte> sigBytes(sigStr->size()); |
701 | | - std::transform( |
702 | | - sigStr->begin(), sigStr->end(), sigBytes.begin(), [](char c) { return static_cast<std::byte>(c); }); |
703 | | - |
| 691 | + std::vector<std::byte> sigBytes = extractSignatureBytes(pair); |
704 | 692 | removedByKey[it->second].push_back(std::move(sigBytes)); |
705 | 693 | } |
706 | 694 | } |
|
0 commit comments