{"id":18158236,"url":"https://github.com/wout/base_x","last_synced_at":"2025-05-07T03:08:35.749Z","repository":{"id":136330675,"uuid":"469686172","full_name":"wout/base_x","owner":"wout","description":"A Crystal shard for base encoding / decoding of any given alphabet with optional bitcoin-style leading zero compression.","archived":false,"fork":false,"pushed_at":"2024-07-11T11:32:22.000Z","size":48,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T03:08:29.820Z","etag":null,"topics":["base","base11","base2","base32","base36","base45","base58","base62","base67","base8","basex","bitcoin","crystal","decode","decoder","encode","encoder","encoding","flicker","ripple"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wout.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":"2022-03-14T10:34:25.000Z","updated_at":"2024-07-11T11:32:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb243b68-716c-451b-a560-e6e1382fff0e","html_url":"https://github.com/wout/base_x","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wout%2Fbase_x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wout%2Fbase_x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wout%2Fbase_x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wout%2Fbase_x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wout","download_url":"https://codeload.github.com/wout/base_x/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252804217,"owners_count":21806770,"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":["base","base11","base2","base32","base36","base45","base58","base62","base67","base8","basex","bitcoin","crystal","decode","decoder","encode","encoder","encoding","flicker","ripple"],"created_at":"2024-11-02T07:05:55.915Z","updated_at":"2025-05-07T03:08:35.719Z","avatar_url":"https://github.com/wout.png","language":"Crystal","readme":"# BaseX\n\nA Crystal shard for base encoding/decoding of any given alphabet with optional\nbitcoin-style leading zero compression.\n\n![GitHub](https://img.shields.io/github/license/wout/base_x)\n![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/wout/base_x)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/wout/base_x/ci.yml?branch=main)\n\n## A note on performance\n\nBecause this library also decodes to integers, it relies on `BigInt`, which\nimplies a significant performance impact. If you are looking to decode/encode\nbase58 and you don't need to decode to integers,\n[wyhaines/base58.cr](https://github.com/wyhaines/base58.cr) is a better\nalternative as it's a lot faster.\n\n## Supported alphabets\n\nBase | Alphabet\n------------- | -------------\n2 | `01`\n8 | `01234567`\n11 | `0123456789a`\n26 | `ABCDEFGHIJKLMNOPQRSTUVWXYZ`\n26 | `abcdefghijklmnopqrstuvwxyz` (lowercase)\n32 | `ybndrfg8ejkmcpqxot1uwisza345h769` (z-base-32)\n36 | `0123456789abcdefghijklmnopqrstuvwxyz`\n45 | `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`\n52 | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`\n58 | `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz` (bitcoin)\n58 | `123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ` (flickr)\n58 | `rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz` (ripple)\n62 | `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`\n67 | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~`\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n  base_x:\n    github: wout/base_x\n```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"base_x\"\n```\n\n### Converting bytes\n\n```crystal\nBaseX::Base58.decode(\"6hKMCS\")\n# =\u003e Bytes[206, 233, 57, 134]\nBaseX::Base58.encode(Bytes[206, 233, 57, 134])\n# =\u003e \"6hKMCS\"\n```\n\nor:\n\n```crystal\nBaseX::Base45.decode(\"5R%/+F5SZ6LLW+J60D\")\n# =\u003e Bytes[231, 5, 88, 240, 215, 89, 21, 180, 87, 179, 227, 86]\nBaseX::Base45.encode(Bytes[231, 5, 88, 240, 215, 89, 21, 180, 87, 179, 227, 86])\n# =\u003e \"5R%/+F5SZ6LLW+J60D\"\n```\n\n**Note**: `BaseX::BaseXX.decode` is the same as `BaseX::BaseXX.decode_bytes`.\n\n### Converting integers\n\n```crystal\nBaseX::Base58.decode_int(\"6hKMCS\")\n# =\u003e 3471391110\nBaseX::Base58.encode(3471391110)\n# =\u003e \"6hKMCS\"\n```\n\n### Using other alphabets\n\n```crystal\nbase_16_alphabet = \"0123456789abcdef\"\nBaseX.decode(\"ff3300\", base_16_alphabet)\n# =\u003e Bytes[255, 51, 0]\nBaseX.encode(Bytes[255, 51, 0], base_16_alphabet)\n# =\u003e \"ff3300\"\n```\n\n### Leading zeroes\n\nSome protocols, such as Bitcoin, require leading zeros to be encoded. Passing\n`true` to the third argument of `BaseX::Base58.encode` will enable this\nbehaviour.\n\n```crystal\nbitcoin_address_hex = \"00000000000000000000123456789ABCDEF0\"\nbitcoin_address_bytes = String.new(bitcoin_address_hex.hexbytes)\n\nBaseX::Base58.encode(bitcoin_address_bytes, leading_zeroes: true)\n# =\u003e 111111111143c9JGph3DZ\n```\n\n## Development\nMake sure you have [Guardian.cr](https://github.com/f/guardian) installed. Then\nrun:\n\n```bash\n$ guardian\n```\n\nThis will automatically:\n- run ameba for src and spec files\n- run the relevant spec for any file in the src dir\n- run spec a file whenever it's saved\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/wout/base_x/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Wout](https://github.com/wout) - creator and maintainer\n\n## Acknowledgments\nThis shard pulls inspiration from the following projects:\n- [cryptocoinjs/base-x](https://github.com/cryptocoinjs/base-x)\n- [dougal/base58](https://github.com/dougal/base58)\n- [russ/base58](https://github.com/russ/base58)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwout%2Fbase_x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwout%2Fbase_x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwout%2Fbase_x/lists"}