MCPcopy Create free account
hub / github.com/QuipNetwork/cpp-sdk / deriveClassicalPublicKey

Function deriveClassicalPublicKey

src/cli.cpp:69–99  ·  view source on GitHub ↗

Helper: derive classical public key from private key using ethers.js

Source from the content-addressed store, hash-verified

67
68// Helper: derive classical public key from private key using ethers.js
69static 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
102static std::array<uint8_t, 32> randomSeed32() {

Callers 7

changePqOwnerMethod · 0.85
handleDepositMethod · 0.85
handleTransferMethod · 0.85
handleExecuteMethod · 0.85
handleChangePqOwnerMethod · 0.85

Calls 1

toChecksumAddressFunction · 0.85

Tested by

no test coverage detected