npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d-address-codec

v0.7.2

Published

crypto currency address codec

Downloads

2

Readme

d-address-codec NPM Build Status codecov.io

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.

  • divvy
  • ripple
  • tipple
  • bitcoin
  • stellar
  • payshares

API

var apiFactory = require('../');
var createHash = require('create-hash');

var api = apiFactory({
  // We probably have your favorite alphabet, if not, contact us
  defaultAlphabet: 'stellar',
  // But we insist you bring your own hash to the party :)
  sha256: function(bytes) {
    return createHash('sha256').update(new Buffer(bytes)).digest();
  },
  // We'll endow your api with encode|decode* for you
  codecMethods : {
    // public keys
    AccountID : {version: 0x00},
    // secrets
    Seed: {version: 0x21}
  },
  // Why the hell don't we just export these versions too?
  // Err.. Shutup :) We're getting to it.
});

var buf = new Buffer("00000000000000000000000000000000", 'hex');
// It can encode a Buffer
var encoded = api.encodeSeed(buf);
// It returns Array<Number>
var decoded = api.decodeSeed(encoded);
// It can of course encode an Array<Number> too
var reencoded = api.encodeSeed(decoded)

console.log(encoded);
console.log(reencoded);
// ps6JS7f14BuwFY8Mw6bTtLKWauoUp
// ps6JS7f14BuwFY8Mw6bTtLKWauoUp

console.log(decoded);
// [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

We could actually encode the seed as a divvy one if we chose :)

console.log(api.encode(decoded, {alphabet: 'divvy', version: 33}));
// sp6JS7f14BuwFY8Mw6bTtLKWauoUs

Wait, what if we wanted to create a prefix for the new nifty spaceMan secrets?

var prefix = api.codecs.stellar.findPrefix(16 /* bytes */, 'spaceMan');
var spacey = api.encode(decoded, {version: prefix});
console.log(spacey);
// spaceMan7qBfYEUBHSWDsZjJHctnNQi2pCTn
console.log(api.decode(spacey, {version: prefix}));
// [ 0, 0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0 ]

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)
/*
{ Codec: [Function: AddressCodec],
  codecs:
   { bitcoin:
      { alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
        codec: [Object],
        base: 58 },
     divvy:
      { alphabet: 'dpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcreCg65jkm8oFqi1tuvAxyz',
        codec: [Object],
        base: 58 },
     ripple:
      { alphabet: 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz',
        codec: [Object],
        base: 58 },
     tipple:
      { alphabet: 'RPShNAF39wBUDnEGHJKLM4pQrsT7VWXYZ2bcdeCg65jkm8ofqi1tuvaxyz',
        codec: [Object],
        base: 58 },
     stellar:
      { alphabet: 'gsphnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCr65jkm8oFqi1tuvAxyz',
        codec: [Object],
        base: 58 } },
     payshares:
      { alphabet: 'xsphnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCr65jkm8oFqi1tuvAgyz',
        codec: [Object],
        base: 58 } },
  decode: [Function: decode],
  encode: [Function: encode],
  decodeAccountID: [Function],
  encodeAccountID: [Function],
  decodeSeed: [Function],
  encodeSeed: [Function] }
*/