Generate a random vault ID using entropy
| 94 | |
| 95 | // Generate a random vault ID using entropy |
| 96 | inline VaultId generateVaultId(const string &entropy = "") { |
| 97 | VaultId vaultId; |
| 98 | if (entropy.empty()) { |
| 99 | // Generate cryptographically secure random vault ID |
| 100 | std::random_device rd; |
| 101 | for (size_t i = 0; i < 32; i += 4) { |
| 102 | uint32_t random_val = rd(); |
| 103 | vaultId[i] = static_cast<uint8_t>(random_val & 0xFF); |
| 104 | if (i + 1 < 32) |
| 105 | vaultId[i + 1] = static_cast<uint8_t>((random_val >> 8) & 0xFF); |
| 106 | if (i + 2 < 32) |
| 107 | vaultId[i + 2] = static_cast<uint8_t>((random_val >> 16) & 0xFF); |
| 108 | if (i + 3 < 32) |
| 109 | vaultId[i + 3] = static_cast<uint8_t>((random_val >> 24) & 0xFF); |
| 110 | } |
| 111 | } else { |
| 112 | // Use provided entropy to generate deterministic vault ID |
| 113 | vector<uint8_t> entropyBytes = fromHex(entropy); |
| 114 | if (entropyBytes.size() < 32) { |
| 115 | // Pad with zeros if entropy is too short |
| 116 | entropyBytes.resize(32, 0); |
| 117 | } else if (entropyBytes.size() > 32) { |
| 118 | // Truncate if entropy is too long |
| 119 | entropyBytes.resize(32); |
| 120 | } |
| 121 | std::copy(entropyBytes.begin(), entropyBytes.end(), vaultId.begin()); |
| 122 | } |
| 123 | return vaultId; |
| 124 | } |
| 125 | |
| 126 | // ABI encoding function (shared between quip_wallet and quip_factory) |
| 127 | string abiEncode(const string &function_name, const string &abi_json, |
no test coverage detected