Package Exports
- @anzerr/base.util
- @anzerr/base.util/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@anzerr/base.util) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Intro
base encoding / decoding of any given alphabet for bitcoin style leading zero compression and rfc4648
Install
npm install --save git+https://github.com/anzerr/base.util.git
npm install --save @anzerr/base.utilExample
const {bc58, b32, Compress, Base} = require('base.util');
const address = '003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187';
console.log(bc58.encode(Buffer.from(address, 'hex'), true)) // 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS
console.log(b32.encode(Buffer.from('foobar'), true)); // MZXW6YTBOI======
console.log(b32.encode(Buffer.from('foobar'))); // <Buffer 0c 19 17 16 1e 18 13 01 0e 08>
const base32 = (data, toString = true) => {
let handle = new Base('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', 40); // alphabet, pad size
return handle.encode(Buffer.from(data), toString);
}
console.log(base32('fooba')) // MZXW6YTB
let bitcoin58 = new Compress('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
console.log(bc58.encode(Buffer.from(address, 'hex'), true)) // 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS