Encode a Bech32 string. */
| 103 | |
| 104 | /** Encode a Bech32 string. */ |
| 105 | std::string encode(const std::string& hrp, const bech32_data& values) { |
| 106 | bech32_data checksum = create_checksum(hrp, values); |
| 107 | bech32_data combined = cat(values, checksum); |
| 108 | std::string ret = hrp + '1'; |
| 109 | ret.reserve(ret.size() + combined.size()); |
| 110 | for (size_t i = 0; i < combined.size(); ++i) { |
| 111 | ret += charset[combined[i]]; |
| 112 | } |
| 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | /** Decode a Bech32 string. */ |
| 117 | std::pair<std::string, bech32_data> decode(const std::string& str) { |
no test coverage detected