Nano-Base32
A small, quick, self-contained implementation of the Base32 encoding/decoding scheme used by the cryptocurrency Nano.
Installation
$ yarn add nano-base32
or
$ npm install --save nano-base32
Usage
const nanoBase32 = require('nano-base32')
const hexToArrayBuffer = require('hex-to-array-buffer')
const arrayBufferToHex = require('array-buffer-to-hex')
const blake = require('blakejs')
const pubKey = '0D7471E5D11FADDCE5315C97B23B464184AFA8C4C396DCF219696B2682D0ADF6'
const buffer = new Uint8Array(hexToArrayBuffer(pubKey))
const encoded = nanoBase32.encode(buffer)
const checksum = blake.blake2b(buffer, null, 5).reverse()
const checksumEncoded = nanoBase32.encode(checksum)
const address = `xrb_${encoded}${checksumEncoded}`
const decoded = nanoBase32.decode(encoded)
const decodedHex = arrayBufferToHex(decoded.buffer).toUpperCase()
const decodedChecksum = nanoBase32.decode(checksumEncoded)
API
function decode (input)
function encode (view)
Running Tests
$ git clone https://github.com/termhn/node-base32
$ cd node-base32
$ yarn install
$ yarn test
Credit
Encoding and decoding algorithms based on: