Skip to content

Commit

Permalink
update README with info regarding bech32m checksum changes
Browse files Browse the repository at this point in the history
  • Loading branch information
danpape committed Feb 2, 2021
1 parent 01fef50 commit 3ddd0d6
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ make test
### Installing prerequirements

If the above doesn't work, you probably need to install some
prerequirements. For example, on a fresh Debian Stretch system:
prerequirements. For example, on a fresh Debian 10 ("buster") system:

```
sudo apt-get install make gcc g++
Expand All @@ -38,16 +38,18 @@ sudo apt-get install make gcc g++
It is worth getting the latest cmake, so install that the hard way:

```
wget https://cmake.org/files/v3.13/cmake-3.13.2.tar.gz
tar xzf cmake-3.13.2.tar.gz
cd cmake-3.13.2
wget https://cmake.org/files/v3.19/cmake-3.19.4.tar.gz
tar xzf cmake-3.19.4.tar.gz
cd cmake-3.19.4
./configure
make
sudo make install
```

Now you can again try to build libbech32.

## Example Code

### C++ Usage Example

```cpp
Expand Down Expand Up @@ -75,6 +77,8 @@ int main() {
}
```

For more C++ examples, see `examples/cpp_example.cpp`

### C Usage Example

```C
Expand Down Expand Up @@ -113,3 +117,43 @@ int main() {
bech32_free_bstring(bstring);
}
```

For more C examples, see `examples/c_example.cpp`


## Regarding bech32 checksums

The Bech32 data encoding format was first proposed by Pieter Wuille in early 2017 in
[BIP 0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki). Later, in November 2019, Pieter published
some research regarding that an exponent used in the bech32 checksum algorithm (value = 1) may not be
optimal for the error detecting properties of bech32. In February 2021, Pieter published
[BIP 0350](http://www.example.com) reporting that "exhaustive analysis" showed the best possible exponent value is
0x2bc830a3. This improved variant of Bech32 is called "Bech32m".

When decoding a possible bech32 encoded string, libbech32 returns an enum value showing whether bech32m or bech32
was used to encode. This can be seen in the exaples above.

When encoding data, libbech32 defaults to using the new exponent value of 0x2bc830a3. If the original exponent value
of 1 is desired, then the following functions may be used:

### C++ Usage Example

```cpp
/// ... as above ...

// encode
std::string bstr = bech32::encodeUsingOriginalConstant(hrp, data);

/// ... as above ...
```

### C Usage Example

```C
/// ... as above ...

// encode
assert(bech32_encode_using_original_constant(bstring, hrp, dp, sizeof(dp)) == E_BECH32_SUCCESS);

/// ... as above ...
```

0 comments on commit 3ddd0d6

Please sign in to comment.