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