MCPcopy Create free account
hub / github.com/ElementsProject/elements / VerifyChecksum

Function VerifyChecksum

src/bech32.cpp:324–335  ·  view source on GitHub ↗

Verify a checksum. */

Source from the content-addressed store, hash-verified

322
323/** Verify a checksum. */
324Encoding 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. */
338data CreateChecksum(Encoding encoding, const std::string& hrp, const data& values)

Callers 1

DecodeFunction · 0.70

Calls 4

PolyModFunction · 0.70
CatFunction · 0.70
ExpandHRPFunction · 0.70
EncodingConstantFunction · 0.70

Tested by

no test coverage detected