{"id":37428175,"url":"https://github.com/dcdpr/libbech32","last_synced_at":"2026-01-16T06:32:37.356Z","repository":{"id":41922512,"uuid":"163809352","full_name":"dcdpr/libbech32","owner":"dcdpr","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-10T23:51:41.000Z","size":2273,"stargazers_count":8,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-11T00:34:16.982Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcdpr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-02T07:36:10.000Z","updated_at":"2024-05-10T23:51:47.000Z","dependencies_parsed_at":"2024-05-11T00:43:07.747Z","dependency_job_id":null,"html_url":"https://github.com/dcdpr/libbech32","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dcdpr/libbech32","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdpr%2Flibbech32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdpr%2Flibbech32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdpr%2Flibbech32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdpr%2Flibbech32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcdpr","download_url":"https://codeload.github.com/dcdpr/libbech32/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdpr%2Flibbech32/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-16T06:32:37.262Z","updated_at":"2026-01-16T06:32:37.344Z","avatar_url":"https://github.com/dcdpr.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libbech32\n\nThis is a C++ implementation of \"Bech32:\" a checksummed base32 data\nencoding format. It is primarily used as a new bitcoin address format\nspecified by [BIP 0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki). \n\n## Building libbech32\n\nTo build libbech32, you will need:\n\n* cmake\n* g++, clang or Visual Studio (community edition)\n\nlibbech32 uses a pretty standard cmake build system:\n\n```\nmkdir build\ncd build\ncmake ..\nmake\n```\n\nYou can also run all the tests:\n\n```\nmake test\n```\n\n### Installing prerequisites\n\nIf the above doesn't work, you probably need to install some\nprerequisites. For example, on a fresh Debian 12 (\"bookworm\") system:\n\n```\nsudo apt-get update\nsudo apt-get install make cmake git g++\n```\n\nNow you can again try to build libbech32.\n\n## Usage Examples\n\n### C++ Encoding Example\n\n```cpp\n#include \"libbech32.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    // simple human readable part with some data\n    std::string hrp = \"hello\";\n    std::vector\u003cunsigned char\u003e data = {14, 15, 3, 31, 13};\n\n    // encode\n    std::string bstr = bech32::encode(hrp, data);\n\n    std::cout \u003c\u003c bstr \u003c\u003c std::endl;\n    // prints \"hello1w0rldjn365x\"\n    // ... \"hello\" + Bech32.separator (\"1\") + encoded data (\"w0rld\") + 6 char checksum (\"jn365x\")\n}\n```\n\n### C++ Decoding Example\n\n```cpp\n#include \"libbech32.h\"\n\nint main() {\n    bech32::DecodedResult decodedResult = bech32::decode(\"hello1w0rldjn365x\");\n\n    // decodedResult.hrp == \"hello\"\n    // decodedResult.dp[0] == 14\n    // decodedResult.encoding == bech32::Encoding::Bech32m\n}\n```\n\nFor more C++ examples, see [examples/cpp_other_examples.cpp](examples/cpp_other_examples.cpp)\n\n### C Encoding Example\n\n```C\n#include \"libbech32.h\"\n#include \u003cstring.h\u003e\n#include \u003cstdio.h\u003e\n\nint main() {\n    // simple human readable part with some data\n    char hrp[] = \"hello\";\n    unsigned char dp[] = {14, 15, 3, 31, 13};\n\n    // create storage for bech32 string\n    bech32_bstring *bstring = bech32_create_bstring(strlen(hrp), sizeof(dp));\n    if(!bstring) {\n        printf(\"bech32 string can not be created\");\n        return E_BECH32_NO_MEMORY;\n    }\n\n    // encode\n    bech32_error err = bech32_encode(bstring, hrp, dp, sizeof(dp));\n    if(err != E_BECH32_SUCCESS) {\n        printf(\"%s\\n\", bech32_strerror(err));\n        bech32_free_bstring(bstring);\n        return err;\n    }\n\n    printf(\"bech32 encoding of human-readable part \\'hello\\' and data part \\'[14, 15, 3, 31, 13]\\' is:\\n\");\n    printf(\"%s\\n\", bstring-\u003estring);\n    // prints \"hello1w0rldjn365x\"\n    // ... \"hello\" + Bech32.separator (\"1\") + encoded data (\"w0rld\") + 6 char checksum (\"jn365x\")\n\n    // free memory\n    bech32_free_bstring(bstring);\n\n    return E_BECH32_SUCCESS;\n}\n```\n\n### C Decoding Example\n\n```C\n#include \"libbech32.h\"\n#include \u003cstring.h\u003e\n#include \u003cstdio.h\u003e\n\nint main() {\n\n    char str[] = \"hello1w0rldjn365x\";\n\n    // create storage for decoded bech32 data\n    bech32_DecodedResult * decodedResult = bech32_create_DecodedResult(str);\n    if(!decodedResult) {\n        printf(\"bech32 DecodedResult can not be created\");\n        return E_BECH32_NO_MEMORY;\n    }\n\n    // decode\n    bech32_error err = bech32_decode(decodedResult, str);\n    if(err != E_BECH32_SUCCESS) {\n        printf(\"%s\\n\", bech32_strerror(err));\n        bech32_free_DecodedResult(decodedResult);\n        return err;\n    }\n\n    // decodedResult-\u003ehrp == \"hello\"\n    // decodedResult-\u003edp[0] == 14\n    // decodedResult-\u003eencoding == ENCODING_BECH32M\n\n    // free memory\n    bech32_free_DecodedResult(decodedResult);\n}\n```\n\nFor more C examples, see [examples/c_other_examples.c](examples/c_other_examples.c)\n\n\n## Regarding bech32 checksums\n\nThe Bech32 data encoding format was first proposed by Pieter Wuille in early 2017 in\n[BIP 0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki). Later, in November 2019, Pieter published\nsome research that a constant used in the bech32 checksum algorithm (value = 1) may not be\noptimal for the error detecting properties of bech32. In February 2021, Pieter published\n[BIP 0350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki) reporting that \"exhaustive analysis\" showed the best possible constant value is\n0x2bc830a3. This improved variant of Bech32 is called \"Bech32m\".\n\nWhen decoding a possible bech32 encoded string, libbech32 returns an enum value showing whether bech32m or bech32\nwas used to encode. This can be seen in the examples above.\n\nWhen encoding data, libbech32 defaults to using the new constant value of 0x2bc830a3. If the original constant value\nof 1 is desired, then the following functions may be used:\n\n### C++ Usage Example\n\n```cpp\n    /// ... as above ...\n\n    // encode\n    std::string bstr = bech32::encodeUsingOriginalConstant(hrp, data);\n\n    /// ... as above ...\n```\n\n### C Usage Example\n\n```C\n    /// ... as above ...\n\n    // encode\n    bech32_error err = bech32_encode_using_original_constant(bstring, hrp, dp, sizeof(dp));\n\n    /// ... as above ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdpr%2Flibbech32","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcdpr%2Flibbech32","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdpr%2Flibbech32/lists"}