c32check
Generating and decoding addresses on the Stacks blockchain.
The Stacks blockchain uses c32-encoded public key hashes as addresses. Specifically, a c32check address is a c32check-encoded ripemd160 hash. This library is meant for generating and decoding addresses on the Stacks blockchain.
How it works
Each c32check string encodes a 1-byte version and a 4-byte checksum. When decoded as a hex string, the wire format looks like this:
0 1 n+1 n+5
|------|-----------------------------|---------------|
version n-byte hex payload 4-byte hashIf version is the version byte (a 1-byte number) and payload is the raw bytes (e.g. as a string), then the checksum is calculated as follows:
checksum = sha256(sha256(version + payload)).substring(0,4)In other words, the checksum is the first four bytes of the double-sha256 of the bytestring concatenation of the version and payload. This is similar to base58check encoding, for example.
Examples
Installation
npm install c32check> c32 = require('c32check')
{ c32encode: [Function: c32encode],
c32decode: [Function: c32decode],
c32checkEncode: [Function: c32checkEncode],
c32checkDecode: [Function: c32checkDecode],
c32address: [Function: c32address],
c32addressDecode: [Function: c32addressDecode],
versions:
{ mainnet: { p2pkh: 22, p2sh: 20 },
testnet: { p2pkh: 26, p2sh: 21 } },
c32ToB58: [Function: c32ToB58],
b58ToC32: [Function: b58ToC32] }c32encode, c32decode
c32checkEncode, c32checkDecode
c32address, c32addressDecode
Note: These methods only work on ripemd160 hashes
c32ToB58, b58ToC32
Convert a Stacks address to its corresponding Bitcoin address, or vice versa.
Note: Common address versions are converted between c32check and base58check seamlessly, in order to accommodate Stacks addresses.
Last updated
Was this helpful?
