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

Method handleDeposit

src/cli.cpp:218–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218bool CLI::handleDeposit(const std::vector<std::string> &args) {
219 Amount amount = 0;
220 std::string entropy = "";
221 std::string vault_id_hex = "";
222
223 // Parse flags
224 for (size_t i = 0; i < args.size(); ++i) {
225 if (args[i] == "--amount" && i + 1 < args.size()) {
226 std::string amount_str = args[++i];
227 // Remove quotes if present
228 if (amount_str.front() == '"' && amount_str.back() == '"') {
229 amount_str = amount_str.substr(1, amount_str.size() - 2);
230 }
231 amount = std::stoull(amount_str);
232 } else if (args[i] == "--entropy" && i + 1 < args.size()) {
233 entropy = args[++i];
234 if (entropy.front() == '"' && entropy.back() == '"') {
235 entropy = entropy.substr(1, entropy.size() - 2);
236 }
237 } else if (args[i] == "--vault-id" && i + 1 < args.size()) {
238 vault_id_hex = args[++i];
239 if (vault_id_hex.front() == '"' && vault_id_hex.back() == '"') {
240 vault_id_hex = vault_id_hex.substr(1, vault_id_hex.size() - 2);
241 }
242 } else {
243 std::cerr << "Unknown or incomplete flag: " << args[i] << std::endl;
244 std::cerr << "Usage: deposit [--amount <amount>] [--entropy <entropy>] "
245 "[--vault-id <vault_id>]"
246 << std::endl;
247 return false;
248 }
249 }
250
251 try {
252 // Note: We use std::random_device for cryptographically secure randomness
253
254 // Prepare quantum secret
255 std::array<uint8_t, 32> quantum_secret;
256 bool secret_was_generated = false;
257 if (entropy.empty()) {
258 secret_was_generated = true;
259 // Generate cryptographically secure random quantum secret
260 quantum_secret = randomSeed32();
261 } else {
262 std::vector<uint8_t> entropyBytes = fromHex(entropy);
263 if (entropyBytes.size() != 32) {
264 throw std::runtime_error(
265 "Provided entropy for quantum secret must be a 32-byte hex string");
266 }
267 std::copy(entropyBytes.begin(), entropyBytes.end(),
268 quantum_secret.begin());
269 }
270
271 // Generate or use provided vault ID
272 VaultId vaultId;
273 if (vault_id_hex.empty()) {
274 vaultId = generateVaultId("");
275 } else {

Callers

nothing calls this directly

Calls 8

randomSeed32Function · 0.85
fromHexFunction · 0.85
generateVaultIdFunction · 0.85
deriveClassicalPublicKeyFunction · 0.85
toChecksumAddressFunction · 0.85
toHexFunction · 0.85
generateKeyPairMethod · 0.80
depositToWinternitzMethod · 0.45

Tested by

no test coverage detected