Verify a checksum. */
| 141 | |
| 142 | /** Verify a checksum. */ |
| 143 | Encoding VerifyChecksum(const std::string& hrp, const data& values) |
| 144 | { |
| 145 | // PolyMod computes what value to xor into the final values to make the checksum 0. However, |
| 146 | // if we required that the checksum was 0, it would be the case that appending a 0 to a valid |
| 147 | // list of values would result in a new valid list. For that reason, Blech32 requires the |
| 148 | // resulting checksum to be 1 instead. In Blech32m, this constant was amended. |
| 149 | const uint64_t check = PolyMod(Cat(ExpandHRP(hrp), values)); |
| 150 | if (check == EncodingConstant(Encoding::BLECH32)) return Encoding::BLECH32; |
| 151 | if (check == EncodingConstant(Encoding::BLECH32M)) return Encoding::BLECH32M; |
| 152 | return Encoding::INVALID; |
| 153 | } |
| 154 | |
| 155 | /** Create a checksum. */ |
| 156 | data CreateChecksum(Encoding encoding, const std::string& hrp, const data& values) |
no test coverage detected