{"id":16819557,"url":"https://github.com/slowli/bech32-buffer","last_synced_at":"2025-04-06T19:12:42.781Z","repository":{"id":23070071,"uuid":"98062266","full_name":"slowli/bech32-buffer","owner":"slowli","description":"Bech32 encoding for byte buffers","archived":false,"fork":false,"pushed_at":"2025-03-28T22:13:03.000Z","size":2502,"stargazers_count":21,"open_issues_count":6,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T17:11:11.026Z","etag":null,"topics":["base32","bech32"],"latest_commit_sha":null,"homepage":"https://slowli.github.io/bech32-buffer/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slowli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-07-22T22:58:12.000Z","updated_at":"2025-01-02T20:32:19.000Z","dependencies_parsed_at":"2023-10-02T08:12:15.990Z","dependency_job_id":"18374dbd-531f-47a2-9ea4-15c68cc9dd0c","html_url":"https://github.com/slowli/bech32-buffer","commit_stats":{"total_commits":209,"total_committers":2,"mean_commits":104.5,"dds":"0.36363636363636365","last_synced_commit":"11ce557a9958bce7137af19617489f1875257d21"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fbech32-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fbech32-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fbech32-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fbech32-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slowli","download_url":"https://codeload.github.com/slowli/bech32-buffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535519,"owners_count":20954576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["base32","bech32"],"created_at":"2024-10-13T10:53:49.618Z","updated_at":"2025-04-06T19:12:42.757Z","avatar_url":"https://github.com/slowli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bech32(m) Encoding for Arbitrary Buffers\n\n[![Build status][workflow-image]][workflow-url]\n[![Code coverage][coveralls-image]][coveralls-url]\n[![Demo][demo-image]][demo-url]\n\n[workflow-image]: https://github.com/slowli/bech32-buffer/workflows/CI/badge.svg?branch=master\n[workflow-url]: https://github.com/slowli/bech32-buffer/actions\n[coveralls-image]: https://img.shields.io/coveralls/slowli/bech32-buffer.svg\n[coveralls-url]: https://coveralls.io/github/slowli/bech32-buffer\n[demo-image]: https://img.shields.io/badge/demo-live-blue.svg\n[demo-url]: https://slowli.github.io/bech32-buffer/\n\n**Bech32** is a Bitcoin address format specified in [BIP 173][bip-173] and [BIP 350][bip-350].\nAmong its advantages are: better adaptability to QR codes and in voice conversations,\nand improved error detection. This library generalizes Bech32 and its modified version\n(Bech32m) to encode any reasonably short byte buffers.\n\n## Usage\n\n### Encoding data\n\n```typescript\ndeclare function encode(\n  prefix: string,\n  data: Uint8Array,\n  encoding: 'bech32' | 'bech32m' = 'bech32'\n): string;\n```\n\nEncodes binary `data` with the specified human-readable `prefix` into a Bech32(m) string.\nThe case is preserved: if the prefix is uppercase, then the output will be uppercase\nas well; otherwise, the output will be lowercase (including the case when the prefix does\nnot contain any letters).\n\n#### Arguments\n\n- **prefix:** string  \n  Human-readable prefix to hint what kind of data Bech32 encodes. Must contain\n  ASCII chars in the range 33-126\n- **data:** Uint8Array  \n  Binary data to encode\n- **encoding:** `bech32` or `bech32m`  \n  Specifies whether to use the original Bech32 encoding from [BIP 173][bip-173]\n  or the modified encoding from [BIP 350][bip-350]; they differ\n  in how a checksum is computed. If omitted, the original encoding is used.\n\n#### Return value\n\nString containing:\n\n1. `prefix`\n2. `'1'` separator char\n3. `data` encoded with the variant of base32 encoding used by Bech32, and\n4. 6-char checksum calculated based on `prefix` and `data`\n\n#### Example\n\n```javascript\nconst bech32 = require('bech32-buffer');\nconst data = new Uint8Array(20);\nbech32.encode('test', data);\n// 'test1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqql6aptf'\n```\n\n### Decoding data\n\n```typescript\ndeclare function decode(message: string): {\n  prefix: string,\n  encoding: 'bech32' | 'bech32m',\n  data: Uint8Array\n};\n```\n\nExtracts human-readable prefix and binary data from the Bech32-encoded string.\n\n#### Arguments\n\n- **data:** string  \n  String to decode\n\n#### Return value\n\nAn object with the following fields:\n\n- **prefix:** string  \n  Human-readable prefix\n- **encoding:** `bech32` or `bech32m`  \n  Encoding variant inferred from the checksum.\n- **data:** Uint8Array  \n  Binary data encoded into the input string\n\nDecoding may fail for a variety of reasons (e.g., invalid checksum, or invalid\nchars in the input). In this case, `decode()` throws an exception\nwith a descriptive message.\n\n#### Example\n\n```javascript\nconst bech32 = require('bech32-buffer');\nconst data = 'lost1qsyq7yqh9gk0szs5';\nbech32.decode(data);\n// {\n//   prefix: 'lost',\n//   encoding: 'bech32',\n//   data: Uint8Array([ 4, 8, 15, 16, 23, 42 ])\n// }\n```\n\n### Bitcoin addresses\n\n```typescript\ndeclare class BitcoinAddress {\n  prefix: 'bc' | 'tb';\n  scriptVersion: number;\n  data: Uint8Array;\n\n  static decode(message: string): BitcoinAddress;\n  constructor(prefix: 'bc' | 'tb', scriptVersion: number, data: Uint8Array);\n  encode(): string;\n  type(): void | 'p2wsh' | 'p2wpkh';\n}\n```\n\nProvides basic functionality to work with Bech32 encoding of Bitcoin addresses.\nAddresses can be `decode`d from strings and `encode`d into strings.\nIt is also possible to check the `type` of an address. P2WSH and P2WPKH address\ntypes are defined per [BIP 141]. Encoding constraints are defined per [BIP 173][bip-173]\nand [BIP 350][bip-350].\n\n#### Example\n\n```javascript\nconst { BitcoinAddress } = require('bech32-buffer');\nconst address = BitcoinAddress.decode('BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4');\n// address.prefix === 'bc'\n// address.scriptVersion === 0\n// address.data.length === 20\n// address.type() === 'p2wpkh'\n```\n\n## Use in Browsers\n\nUse `dist/bech32-buffer.min.js` from the package distribution\nor your favorite browserifier. In the first case,\nthe library will be available as a `bech32` global variable:\n\n```html\n\u003cscript src=\"bech32-buffer.min.js\"\u003e\u003c/script\u003e\n\u003c!-- later --\u003e\n\u003cscript\u003e\nbech32.encode('test', new Uint8Array(20));\n\u003c/script\u003e\n```\n\nCheck out [the web demo](https://slowli.github.io/bech32-buffer/) to see how\n**bech32-buffer** works in browser. It is also available in the `examples`\ndirectory of the package.\n\n## Acknowledgements\n\n[BIP 173][bip-173] is authored by Pieter Wuille and Greg Maxwell and is licensed\nunder the 2-clause BSD license.\n[BIP 350][bip-350] is authored by Pieter Wuille and is licensed\nunder the 2-clause BSD license.\n\nThere are at least 2 existing implementations of Bech32 for JavaScript:\n\n- [The reference implementation][ref] by Pieter Wuille\n- [Another implementation][bech32] available as the [`bech32` package][bech32-pkg]\n\nBoth implementations are Bitcoin-specific, and the reference implementation\nis also not in the Npm / yarn package manager.\n\n## License\n\n**bech32-buffer** is available under [Apache-2.0 license](LICENSE).\n\n[bip-173]: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki\n[bip-350]: https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki\n[ref]: https://github.com/sipa/bech32/tree/master/ref/javascript\n[bech32]: https://github.com/bitcoinjs/bech32\n[bech32-pkg]: https://www.npmjs.com/package/bech32\n[BIP 141]: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslowli%2Fbech32-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslowli%2Fbech32-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslowli%2Fbech32-buffer/lists"}