Encode a Blech32 or Blech32m string. */
| 168 | |
| 169 | /** Encode a Blech32 or Blech32m string. */ |
| 170 | std::string Encode(Encoding encoding, const std::string& hrp, const data& values) { |
| 171 | // First ensure that the HRP is all lowercase. BIP-173 and BIP350 require an encoder |
| 172 | // to return a lowercase Blech32/Blech32m string, but if given an uppercase HRP, the |
| 173 | // result will always be invalid. |
| 174 | for (const char& c : hrp) assert(c < 'A' || c > 'Z'); |
| 175 | data checksum = CreateChecksum(encoding, hrp, values); |
| 176 | data combined = Cat(values, checksum); |
| 177 | std::string ret = hrp + '1'; |
| 178 | ret.reserve(ret.size() + combined.size()); |
| 179 | for (const auto c : combined) { |
| 180 | ret += CHARSET[c]; |
| 181 | } |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | /** Decode a Blech32 or Blech32m string. */ |
| 186 | DecodeResult Decode(const std::string& str) { |
nothing calls this directly
no test coverage detected