Verify a checksum. */
| 325 | |
| 326 | /** Verify a checksum. */ |
| 327 | Encoding VerifyChecksum(const std::string& hrp, const data& values) |
| 328 | { |
| 329 | // PolyMod computes what value to xor into the final values to make the checksum 0. However, |
| 330 | // if we required that the checksum was 0, it would be the case that appending a 0 to a valid |
| 331 | // list of values would result in a new valid list. For that reason, Bech32 requires the |
| 332 | // resulting checksum to be 1 instead. In Bech32m, this constant was amended. See |
| 333 | // https://gist.github.com/sipa/14c248c288c3880a3b191f978a34508e for details. |
| 334 | auto enc = PreparePolynomialCoefficients(hrp, values); |
| 335 | const uint32_t check = PolyMod(enc); |
| 336 | if (check == EncodingConstant(Encoding::BECH32)) return Encoding::BECH32; |
| 337 | if (check == EncodingConstant(Encoding::BECH32M)) return Encoding::BECH32M; |
| 338 | return Encoding::INVALID; |
| 339 | } |
| 340 | |
| 341 | /** Create a checksum. */ |
| 342 | data CreateChecksum(Encoding encoding, const std::string& hrp, const data& values) |
no test coverage detected