-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update checksum create/validate code based on Pieter Wuille's recent …
…research
- Loading branch information
Showing
10 changed files
with
428 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "libbech32.h" | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
// make sure we can check these examples even when building a release version | ||
#undef NDEBUG | ||
#include <assert.h> | ||
|
||
int main() { | ||
// simple human readable part with some data | ||
char hrp[] = "hello"; | ||
unsigned char dp[] = {14, 15, 3, 31, 13}; | ||
|
||
// create output array for bech32 string | ||
char bstr[sizeof(hrp) + 1 + sizeof(dp) + 6] = {0}; | ||
|
||
// encode | ||
assert(bech32_encode(bstr, sizeof(bstr), hrp, sizeof(hrp), dp, sizeof(dp)) == E_BECH32_SUCCESS); | ||
|
||
// prints "hello1w0rldcs7fw6" : "hello" + Bech32.separator + encoded data + 6 char checksum | ||
printf("bech32 encoding of human-readable part \'hello\' and data part \'[14, 15, 3, 31, 13]\' is:\n"); | ||
printf("%s\n", bstr); | ||
|
||
// allocate memory for decoded data | ||
bech32_HrpAndDp * hrpdp = create_HrpAndDp_storage(bstr); | ||
|
||
// decode | ||
assert(bech32_decode(hrpdp, bstr, sizeof(bstr)) == E_BECH32_SUCCESS); | ||
assert(strcmp(hrpdp->hrp, "hello") == 0); | ||
|
||
// free memory | ||
free_HrpAndDp_storage(hrpdp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "libbech32.h" | ||
#include <iostream> | ||
|
||
// make sure we can check these examples even when building a release version | ||
#undef NDEBUG | ||
#include <cassert> | ||
|
||
int main() { | ||
// simple human readable part with some data | ||
std::string hrp = "hello"; | ||
std::vector<unsigned char> data = {14, 15, 3, 31, 13}; | ||
|
||
// encode | ||
std::string bstr = bech32::encode(hrp, data); | ||
|
||
// prints "hello1w0rldcs7fw6" : "hello" + Bech32.separator + encoded data + 6 char checksum | ||
std::cout << R"(bech32 encoding of human-readable part 'hello' and data part '[14, 15, 3, 31, 13]' is:)" << std::endl; | ||
std::cout << bstr << std::endl; | ||
|
||
// decode | ||
bech32::HrpAndDp hd = bech32::decode(bstr); | ||
|
||
assert(hrp == hd.hrp); | ||
assert(data == hd.dp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.