{"_id":"x-address-codec-ext","_rev":"3-afc4aa67d6f81261c06ff906a1cfd661","name":"x-address-codec-ext","time":{"modified":"2022-05-24T20:53:53.112Z","created":"2017-11-29T03:37:03.149Z","0.7.2":"2017-11-29T03:37:03.149Z","0.7.3":"2017-11-29T06:54:39.860Z"},"maintainers":[{"name":"peersafe","email":"admin@peersafe.cn"}],"dist-tags":{"latest":"0.7.3"},"description":"crypto currency address codec","readme":"# x-address-codec_ext [![NPM](https://img.shields.io/npm/v/x-address-codec.svg)](https://npmjs.org/package/x-address-codec) [![Build Status](https://img.shields.io/travis/ripple/x-address-codec/master.svg)](https://travis-ci.org/ripple/x-address-codec) [![codecov.io](http://codecov.io/github/ripple/x-address-codec/coverage.svg?branch=master)](http://codecov.io/github/ripple/x-address-codec?branch=master)\r\n\r\nThis is a meta package, that exposes an api factory. It's really not as boring\r\nas it sounds. We only ask you bring your own hash\r\n([create-hash](https://www.npmjs.com/package/create-hash),\r\n [crypto](https://nodejs.org/api/crypto.html)) to the party, as we already\r\nprovide a free [base-x](https://github.com/dcousens/base-x) codec for your\r\nheavy lifting pleasure.\r\n\r\n# What, what? This does what exactly ?\r\n\r\nAt the party, mostly people just stand around and encode/decode crypto coin\r\naddress strings to bytes and back. Thrilling right?\r\n\r\n# Alphabet Soup\r\n\r\nWe currently serve these alphabets. Make a pull request if you'd like to add one\r\nto the menu.\r\n\r\n* ripple\r\n* tipple\r\n* bitcoin\r\n* stellar\r\n* chainsql\r\n\r\n# API\r\n\r\n```js\r\nvar apiFactory = require('../');\r\nvar createHash = require('create-hash');\r\n\r\nvar api = apiFactory({\r\n  // We probably have your favorite alphabet, if not, contact us\r\n  defaultAlphabet: 'stellar',\r\n  // But we insist you bring your own hash to the party :)\r\n  sha256: function(bytes) {\r\n    return createHash('sha256').update(new Buffer(bytes)).digest();\r\n  },\r\n  // We'll endow your api with encode|decode* for you\r\n  codecMethods : {\r\n    // public keys\r\n    AccountID : {version: 0x00},\r\n    // secrets\r\n    Seed: {version: 0x21}\r\n  },\r\n  // Why the hell don't we just export these versions too?\r\n  // Err.. Shutup :) We're getting to it.\r\n});\r\n\r\nvar buf = new Buffer(\"00000000000000000000000000000000\", 'hex');\r\n// It can encode a Buffer\r\nvar encoded = api.encodeSeed(buf);\r\n// It returns Array<Number>\r\nvar decoded = api.decodeSeed(encoded);\r\n// It can of course encode an Array<Number> too\r\nvar reencoded = api.encodeSeed(decoded)\r\n\r\nconsole.log(encoded);\r\nconsole.log(reencoded);\r\n// ps6JS7f14BuwFY8Mw6bTtLKWauoUp\r\n// ps6JS7f14BuwFY8Mw6bTtLKWauoUp\r\n\r\nconsole.log(decoded);\r\n// [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]\r\n```\r\n\r\n## We could actually encode the seed as a ripple one if we chose :)\r\n\r\n```js\r\nconsole.log(api.encode(decoded, {alphabet: 'ripple', version: 33}));\r\n// sp6JS7f14BuwFY8Mw6bTtLKWauoUs\r\n```\r\n\r\n## Wait, what if we wanted to create a prefix for the new nifty spaceMan secrets?\r\n```js\r\nvar prefix = api.codecs.stellar.findPrefix(16 /* bytes */, 'spaceMan');\r\nvar spacey = api.encode(decoded, {version: prefix});\r\nconsole.log(spacey);\r\n// spaceMan7qBfYEUBHSWDsZjJHctnNQi2pCTn\r\nconsole.log(api.decode(spacey, {version: prefix}));\r\n// [ 0, 0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0 ]\r\n```\r\n\r\n## You may as well make a little mini module, and export it :)\r\n\r\n```js\r\nmodule.exports = api;\r\n```\r\n\r\n## Hell, you could even npm publish it :)\r\n```bash\r\n$ npm publish\r\n```\r\n\r\n## Anway, what is actually exported here?\r\n```js\r\nconsole.log(api)\r\n/*\r\n{ Codec: [Function: AddressCodec],\r\n  codecs:\r\n   { bitcoin:\r\n      { alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',\r\n        codec: [Object],\r\n        base: 58 },\r\n     ripple:\r\n      { alphabet: 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz',\r\n        codec: [Object],\r\n        base: 58 },\r\n     tipple:\r\n      { alphabet: 'RPShNAF39wBUDnEGHJKLM4pQrsT7VWXYZ2bcdeCg65jkm8ofqi1tuvaxyz',\r\n        codec: [Object],\r\n        base: 58 },\r\n     stellar:\r\n      { alphabet: 'gsphnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCr65jkm8oFqi1tuvAxyz',\r\n        codec: [Object],\r\n        base: 58 } },\r\n  decode: [Function: decode],\r\n  encode: [Function: encode],\r\n  decodeAccountID: [Function],\r\n  encodeAccountID: [Function],\r\n  decodeSeed: [Function],\r\n  encodeSeed: [Function] }\r\n*/\r\n```\r\n","versions":{"0.7.3":{"name":"x-address-codec-ext","version":"0.7.3","license":"ISC","description":"crypto currency address codec","files":["dist/npm/*"],"main":"dist/npm/","directories":{"test":"test"},"dependencies":{"base-x":"^1.0.1"},"devDependencies":{"assert-diff":"^1.0.1","babel":"^5.8.23","babel-core":"^5.8.25","babel-eslint":"^4.1.3","babel-loader":"^5.3.2","bn.js":"^3.2.0","codecov.io":"^0.1.6","coveralls":"~2.11.4","create-hash":"^1.1.2","eslint":"^1.6.0","eventemitter2":"^0.4.14","hash.js":"^1.0.3","istanbul":"~0.3.21","lodash":"^3.10.1","map-stream":"~0.1.0","mocha":"~2.3.3","nock":"^2.13.0","webpack":"~1.12.2","yargs":"~3.26.0"},"scripts":{"build":"gulp","compile":"babel -i runtime -d dist/npm/ src/","compile-with-source-maps":"babel -i runtime -s -t -d dist/npm/ src/","prepublish":"npm run compile","test":"istanbul test _mocha","codecov":"cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js"},"repository":{"type":"git","url":"git://github.com/ripple/x-address-codec.git"},"engines":{"node":">=0.12.0"},"gitHead":"ae6ce313cc6e8e4ec2ce71190af8b13ffb1d0747","bugs":{"url":"https://github.com/ripple/x-address-codec/issues"},"homepage":"https://github.com/ripple/x-address-codec#readme","_id":"x-address-codec-ext@0.7.3","_npmVersion":"5.3.0","_nodeVersion":"8.4.0","_npmUser":{"name":"peersafe","email":"admin@peersafe.cn"},"dist":{"integrity":"sha512-ercj18Q82HoUbsDsE7fME7qanPTi6C3S8jEBgGj0r56o7uD/Ybl0wzQv7jobqYk1Citxj4ZM94DilbnJkHVD3w==","shasum":"4ecb0e418eb9bde9223542a55a706b9724c0ee0c","tarball":"https://registry.npmjs.org/x-address-codec-ext/-/x-address-codec-ext-0.7.3.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD/H3lG7EiLIWvcE7ZKeQuEsB8IrzMGKscW9F4whCGfJgIgbnI2mTXN3bDzBtSLAVpqCGIFQiA12eARnRRjoqbm2BY="}]},"maintainers":[{"name":"peersafe","email":"admin@peersafe.cn"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/x-address-codec-ext-0.7.3.tgz_1511938479770_0.17437120899558067"}}},"homepage":"https://github.com/ripple/x-address-codec#readme","repository":{"type":"git","url":"git://github.com/ripple/x-address-codec.git"},"bugs":{"url":"https://github.com/ripple/x-address-codec/issues"},"license":"ISC","readmeFilename":"README.md"}