x-address-codec
This is a meta package, that exposes an api factory. It's really not as boring
as it sounds. We only ask you bring your own hash
(create-hash,
crypto) to the party, as we already
provide a free base-x codec for your
heavy lifting pleasure.
What, what? This does what exactly ?
At the party, mostly people just stand around and encode/decode crypto coin
address strings to bytes and back. Thrilling right?
Alphabet Soup
We currently serve these alphabets. Make a pull request if you'd like to add one
to the menu.
- ripple
- tipple
- bitcoin
- stellar
API
var apiFactory = require('../');
var createHash = require('create-hash');
var api = apiFactory({
defaultAlphabet: 'stellar',
sha256: function(bytes) {
return createHash('sha256').update(new Buffer(bytes)).digest();
},
codecMethods : {
AccountID : {version: 0x00},
Seed: {version: 0x21}
},
});
var buf = new Buffer("00000000000000000000000000000000", 'hex');
var encoded = api.encodeSeed(buf);
var decoded = api.decodeSeed(encoded);
var reencoded = api.encodeSeed(decoded)
console.log(encoded);
console.log(reencoded);
console.log(decoded);
We could actually encode the seed as a ripple one if we chose :)
console.log(api.encode(decoded, {alphabet: 'ripple', version: 33}));
Wait, what if we wanted to create a prefix for the new nifty spaceMan secrets?
var prefix = api.codecs.stellar.findPrefix(16 , 'spaceMan');
var spacey = api.encode(decoded, {version: prefix});
console.log(spacey);
console.log(api.decode(spacey, {version: prefix}));
You may as well make a little mini module, and export it :)
module.exports = api;
Hell, you could even npm publish it :)
$ npm publish
Anway, what is actually exported here?
console.log(api)