Helper: derive classical public key from private key using ethers.js
| 67 | |
| 68 | // Helper: derive classical public key from private key using ethers.js |
| 69 | static Address deriveClassicalPublicKey(const PrivateKey &private_key) { |
| 70 | // Use the same approach as e2e_test.sh - call ethers.js from ethereum-sdk |
| 71 | std::string command = "cd " + |
| 72 | std::string(getenv("PWD") ? getenv("PWD") : ".") + |
| 73 | "/ethereum-sdk && node -e \"console.log(new " |
| 74 | "(require('ethers').Wallet)('" + |
| 75 | private_key + "').address)\""; |
| 76 | |
| 77 | FILE *pipe = popen(command.c_str(), "r"); |
| 78 | if (!pipe) { |
| 79 | throw std::runtime_error("Failed to execute ethers.js command"); |
| 80 | } |
| 81 | |
| 82 | std::string result; |
| 83 | char buffer[128]; |
| 84 | while (fgets(buffer, sizeof(buffer), pipe) != nullptr) { |
| 85 | result += buffer; |
| 86 | } |
| 87 | |
| 88 | int status = pclose(pipe); |
| 89 | if (status != 0) { |
| 90 | throw std::runtime_error("ethers.js command failed: " + result); |
| 91 | } |
| 92 | |
| 93 | // Remove newline and return the address |
| 94 | if (!result.empty() && result[result.length() - 1] == '\n') { |
| 95 | result.erase(result.length() - 1); |
| 96 | } |
| 97 | |
| 98 | return toChecksumAddress(result); |
| 99 | } |
| 100 | |
| 101 | // Helper: generate a cryptographically secure random 32-byte array |
| 102 | static std::array<uint8_t, 32> randomSeed32() { |
no test coverage detected