| 154 | } |
| 155 | |
| 156 | void WalletHDsqlite::load() { |
| 157 | std::string version; |
| 158 | if (!get("version", version)) { |
| 159 | throw Exception(api::WALLET_FILE_DECRYPT_ERROR, "Wallet password incorrect"); |
| 160 | } |
| 161 | if (version != current_version) |
| 162 | throw Exception(api::WALLET_FILE_DECRYPT_ERROR, "Wallet version unknown, please update walletd - " + version); |
| 163 | std::string coinname; |
| 164 | if (!get("coinname", coinname) || coinname != CRYPTONOTE_NAME) |
| 165 | throw Exception(api::WALLET_FILE_DECRYPT_ERROR, "Wallet is for different coin - " + coinname); |
| 166 | if (m_hw) { |
| 167 | m_A_plus_sH = m_hw->get_A_plus_SH(); |
| 168 | m_v_mul_A_plus_sH = m_hw->get_v_mul_A_plus_SH(); |
| 169 | m_view_public_key = m_hw->get_public_view_key(); |
| 170 | invariant(key_in_main_subgroup(m_A_plus_sH), "Hardware wallet error - spend key base is invalid"); |
| 171 | invariant(key_in_main_subgroup(m_v_mul_A_plus_sH), "Hardware wallet error - view key base is invalid"); |
| 172 | invariant(key_in_main_subgroup(m_view_public_key), "Hardware wallet error - view public key is invalid"); |
| 173 | BinaryArray ba; |
| 174 | if (get("view_key", ba)) { // hardware wallet with a view key |
| 175 | seria::from_binary(m_view_secret_key, ba); |
| 176 | invariant(keys_match(m_view_secret_key, m_view_public_key), "Hardware-backed wallet corrupted"); |
| 177 | } |
| 178 | } else { |
| 179 | std::string mnemonic; |
| 180 | std::string mnemonic_password; |
| 181 | if (get("mnemonic", mnemonic)) { |
| 182 | invariant(get("mnemonic-password", mnemonic_password), "Wallet corrupted - no mnemonic password"); |
| 183 | } else { // View only |
| 184 | // only if we have output_secret_derivation_seed, view-only wallet will be able to see outgoing addresses |
| 185 | BinaryArray ba; |
| 186 | if (get("view_seed", ba)) { |
| 187 | seria::from_binary(m_view_seed, ba); |
| 188 | } else { |
| 189 | invariant(get("view_key", ba), "Wallet corrupted - no view key"); |
| 190 | seria::from_binary(m_view_secret_key, ba); |
| 191 | invariant(get("view_key_audit", ba), "Wallet corrupted - no audit key base"); |
| 192 | seria::from_binary(m_audit_key_base.secret_key, ba); |
| 193 | } |
| 194 | invariant(get("sH", ba), "Wallet corrupted - no sH key"); |
| 195 | seria::from_binary(m_sH, ba); |
| 196 | invariant(get("view_secrets_signature", ba), "Wallet audit secrets are corrupted"); |
| 197 | seria::from_binary(m_view_secrets_signature, ba); |
| 198 | } |
| 199 | derive_secrets(mnemonic, mnemonic_password); |
| 200 | } |
| 201 | { |
| 202 | BinaryArray ba; |
| 203 | if (get(ADDRESS_COUNT_PREFIX, ba)) |
| 204 | seria::from_binary(m_used_address_count, ba); |
| 205 | // We do not read for all nets for simplicity. TODO - read |
| 206 | if (get(CREATION_TIMESTAMP_PREFIX + net_append(m_currency.net), ba)) { |
| 207 | Timestamp ts = 0; |
| 208 | seria::from_binary(ts, ba); |
| 209 | m_oldest_timestamp[m_currency.net] = ts; |
| 210 | } |
| 211 | } |
| 212 | generate_ahead(); |
| 213 |
nothing calls this directly
no test coverage detected