{"id":20987433,"url":"https://github.com/stacks-network/c32check","last_synced_at":"2025-07-07T22:05:30.447Z","repository":{"id":40730854,"uuid":"152631893","full_name":"stacks-network/c32check","owner":"stacks-network","description":"Crockford base-32 encoding with 4-byte checksum","archived":false,"fork":false,"pushed_at":"2025-04-30T16:36:23.000Z","size":13403,"stargazers_count":14,"open_issues_count":9,"forks_count":7,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-06-02T18:00:40.784Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/stacks-network.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,"zenodo":null}},"created_at":"2018-10-11T17:44:29.000Z","updated_at":"2025-04-29T17:57:46.000Z","dependencies_parsed_at":"2024-06-18T15:29:22.313Z","dependency_job_id":"53905686-1dee-4525-ba6c-8dda4988ee0c","html_url":"https://github.com/stacks-network/c32check","commit_stats":{"total_commits":52,"total_committers":5,"mean_commits":10.4,"dds":0.5,"last_synced_commit":"74b1bdb07a9ce92bd65c48d18a7e792870a3357a"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/stacks-network/c32check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacks-network%2Fc32check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacks-network%2Fc32check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacks-network%2Fc32check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacks-network%2Fc32check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacks-network","download_url":"https://codeload.github.com/stacks-network/c32check/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacks-network%2Fc32check/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262254150,"owners_count":23282574,"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":[],"created_at":"2024-11-19T06:16:56.398Z","updated_at":"2025-07-07T22:05:30.427Z","avatar_url":"https://github.com/stacks-network.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# c32check\n\n[Crockford base-32](https://en.wikipedia.org/wiki/Base32#Crockford's_Base32)\nencoding library with 4-byte checksum.\n\nThis library is meant for generating and decoding addresses on the Stacks\nblockchain.\n\n## How it works\n\nEach c32check string encodes a 1-byte version and a 4-byte checksum. When\ndecoded as a hex string, the wire format looks like this:\n\n```\n0      1                             n+1             n+5\n|------|-----------------------------|---------------|\nversion     n-byte hex payload          4-byte hash\n```\n\nIf `version` is the version byte (a 1-byte `number`) and `payload` is the raw\nbytes (e.g. as a `string`), then the `checksum` is calculated as follows:\n\n```\nchecksum = sha256(sha256(version + payload)).substring(0,4)\n```\n\nIn other words, the checksum is the first four bytes of the\ndouble-sha256 of the bytestring concatenation of the `version` and `payload`.\nThis is similar to base58check encoding, for example.\n\n## c32 Addresses\n\nThe Stacks blockchain uses c32-encoded public key hashes as addresses.\nSpecifically, a **c32check address** is a c32check-encoded ripemd160 hash.\n\n---\n\n# Examples\n\n```\n\u003e c32 = require('c32check')\n{ c32encode: [Function: c32encode],\n  c32decode: [Function: c32decode],\n  c32checkEncode: [Function: c32checkEncode],\n  c32checkDecode: [Function: c32checkDecode],\n  c32address: [Function: c32address],\n  c32addressDecode: [Function: c32addressDecode],\n  versions:\n   { mainnet: { p2pkh: 22, p2sh: 20 },\n     testnet: { p2pkh: 26, p2sh: 21 } },\n  c32ToB58: [Function: c32ToB58],\n  b58ToC32: [Function: b58ToC32] }\n```\n\n## c32encode, c32decode\n\n```\n\u003e c32check.c32encode(Buffer.from('hello world').toString('hex'))\n'38CNP6RVS0EXQQ4V34'\n\u003e c32check.c32decode('38CNP6RVS0EXQQ4V34')\n'68656c6c6f20776f726c64'\n\u003e Buffer.from('68656c6c6f20776f726c64', 'hex').toString()\n'hello world'\n```\n\n## c32checkEncode, c32checkDecode\n\n```\n\u003e version = 12\n12\n\u003e c32check.c32checkEncode(version, Buffer.from('hello world').toString('hex'))\n'CD1JPRV3F41VPYWKCCGRMASC8'\n\u003e c32check.c32checkDecode('CD1JPRV3F41VPYWKCCGRMASC8')\n[ 12, '68656c6c6f20776f726c64' ]\n\u003e Buffer.from('68656c6c6f20776f726c64', 'hex').toString()\n'hello world'\n```\n\n## c32address, c32addressDecode\n\n\u003e **Note**:\n\u003e These methods only work on ripemd160 hashes\n\n```\n\u003e hash160 = 'a46ff88886c2ef9762d970b4d2c63678835bd39d'\n'a46ff88886c2ef9762d970b4d2c63678835bd39d'\n\u003e version = c32check.versions.mainnet.p2pkh\n22\n\u003e c32check.c32address(version, hash160)\n'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7'\n\u003e c32check.c32addressDecode('SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7')\n[ 22, 'a46ff88886c2ef9762d970b4d2c63678835bd39d' ]\n```\n\n## c32ToB58, b58ToC32\n\n\u003e **Note**:\n\u003e Common address versions are converted between c32check and base58check\n\u003e seamlessly, in order to accommodate Stacks addresses.\n\n```\n\u003e b58addr = '16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg'\n'16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg'\n\u003e c32check.b58ToC32(b58addr)\n'SPWNYDJ3STG7XH7ERWXMV6MQ7Q6EATWVY5Q1QMP8'\n\u003e c32check.c32ToB58('SPWNYDJ3STG7XH7ERWXMV6MQ7Q6EATWVY5Q1QMP8')\n'16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg'\n```\n\n```\n\u003e b58addr = '3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r'\n'3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r'\n\u003e c32check.b58ToC32(b58addr)\n'SM1Y6EXF21RZ9739DFTEQKB1H044BMM0XVCM4A4NY'\n\u003e c32check.c32ToB58('SM1Y6EXF21RZ9739DFTEQKB1H044BMM0XVCM4A4NY')\n'3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacks-network%2Fc32check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacks-network%2Fc32check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacks-network%2Fc32check/lists"}