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

Method handleChangePqOwner

src/cli.cpp:635–846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

633}
634
635bool CLI::handleChangePqOwner(const std::vector<std::string> &args) {
636 if (args.size() != 2 && args.size() != 3 && args.size() != 4) {
637 std::cerr << "Usage: change-owner <quantum_secret_hex> <quip_wallet_address> [private_key_hex] [public_seed_hex]"
638 << std::endl;
639 std::cerr << " quantum_secret_hex: 32-byte quantum secret in hex format (0x...)"
640 << std::endl;
641 std::cerr << " quip_wallet_address: QuipWallet address (0x...)"
642 << std::endl;
643 std::cerr << " private_key_hex: Optional private key in hex format (0x...)"
644 << std::endl;
645 std::cerr << " public_seed_hex: Optional 32-byte public seed in hex format (0x...) - required if private_key_hex is provided"
646 << std::endl;
647 return false;
648 }
649
650 try {
651 // 1. Parse Arguments
652 std::string quantum_secret_hex = args[0];
653 if (quantum_secret_hex.front() == '"' && quantum_secret_hex.back() == '"') {
654 quantum_secret_hex =
655 quantum_secret_hex.substr(1, quantum_secret_hex.size() - 2);
656 }
657 std::array<uint8_t, 32> quantum_secret = fromHex32(quantum_secret_hex);
658
659 std::string quip_wallet_address_str = args[1];
660 if (quip_wallet_address_str.front() == '"' &&
661 quip_wallet_address_str.back() == '"') {
662 quip_wallet_address_str =
663 quip_wallet_address_str.substr(1, quip_wallet_address_str.size() - 2);
664 }
665 quip_wallet_address_str = toChecksumAddress(quip_wallet_address_str);
666 Address quip_wallet_address = parseAddress(quip_wallet_address_str);
667
668 // 2. Find the correct Vault
669 std::string private_key_env =
670 getenv("PRIVATE_KEY") ? getenv("PRIVATE_KEY") : "";
671 if (private_key_env.empty()) {
672 throw std::runtime_error("PRIVATE_KEY environment variable not set");
673 }
674 Address classical_pubkey = deriveClassicalPublicKey(private_key_env);
675 classical_pubkey = toChecksumAddress(classical_pubkey);
676
677 auto vaults = factory_->getVaults(classical_pubkey);
678
679 auto it =
680 std::find_if(vaults.begin(), vaults.end(), [&](const auto &vault) {
681 return toChecksumAddress(vault.classical_address) == toChecksumAddress(quip_wallet_address);
682 });
683
684 if (it == vaults.end()) {
685 throw std::runtime_error(
686 "Could not find a vault for the given wallet address.");
687 }
688 VaultId vault_id = it->id;
689
690 // 3. Get current on-chain public key
691 auto wallet = std::make_unique<QuipWallet>(rpc_url_, quip_wallet_address);
692 std::string current_pq_owner_hex = wallet->getPqOwner();

Callers

nothing calls this directly

Calls 13

fromHex32Function · 0.85
toChecksumAddressFunction · 0.85
deriveClassicalPublicKeyFunction · 0.85
fromHexFunction · 0.85
keccak256Function · 0.85
toHexFunction · 0.85
recoverKeyPairMethod · 0.80
generateKeyPairMethod · 0.80
signMethod · 0.80
getVaultsMethod · 0.45
getPqOwnerMethod · 0.45

Tested by

no test coverage detected