From 2db95f47d4de1d7b99f9b8c63950a0514c3bde8d Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 8 Jul 2015 15:34:34 -0700 Subject: [PATCH] Add documentation --- .jshintignore | 1 + .jshintrc | 10 +++++++ README.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++-- package.json | 26 +++++++++++++++--- tests/id-test.js | 0 5 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 .jshintignore create mode 100644 .jshintrc create mode 100644 tests/id-test.js diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..997b3f7 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,10 @@ +{ + "node": true, + + "curly": true, + "latedef": true, + "quotmark": true, + "undef": true, + "unused": true, + "trailing": true +} diff --git a/README.md b/README.md index 3602b01..ff233bf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,66 @@ -# node-ipfs-peer-id -IPFS Peer Id implementation in Node.js +ipfs-peer-id Node.js implementation +=================================== + +![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square) + +> IPFS Peer Id implementation in Node.js + +# Description + +A IPFS Peer Id is based on a sha256 has of the peer public key, using [multihash](https://github.com/jbenet/multihash) + +# Usage + +### Installing + +``` +$ npm install ipfs-peer-id +``` + +### Creating a new Id + +``` +var PeerId = require('ipfs-peer') + +// Create a new Id +var id = new Id.create() + +// Recreate an Id from Hex string +var id = new Id.createFromHexString(str) + +// Recreate an Id from a Buffer +var id = new Id.createFromBytes(buf) + +// Recreate an B58 String +var id = new Id.createFromB58String(str) + +// Recreate from a Public Key +var id = new Id.createFromPubKey(pubKey) + +// Recreate from a Private Key +var id = new Id.createFromPrivKey(privKey) +``` + +### Exporting an Id + +``` +// Print friendly format +id.toPrint() // returns an object with id, privKey and pubKey in hex format + +// Export to an hex string +id.toHexString() + +// Export to Buffer +id.toBytes() (same as id.id) + +// Export to a B58 string +id.toB58String() +``` + +### Id format + +``` +id.pubKey // Buffer containing the Public Key +id.privKey // Buffer containing the Private Key +id.id // Buffer containing the multihash +``` diff --git a/package.json b/package.json index 7b9cee6..94a9e63 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,31 @@ "description": "IPFS Peer Id implementation in Node.js", "main": "src/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "./node_modules/.bin/lab tests/*-test.js", + "coverage": "./node_modules/.bin/lab -t 100 tests/*-test.js", + "codestyle": "./node_modules/.bin/standard --format" }, "keywords": [ "IPFS" ], - "author": "David Dias ", - "license": "MIT" + "author": "David Dias ", + "license": "MIT", + "pre-commit": [ + "codestyle", + "test" + ], + "bugs": { + "url": "https://github.com/diasdavid/node-ipfs-peer-id/issues" + }, + "homepage": "https://github.com/diasdavid/node-ipfs-peer-id", + "devDependencies": { + "code": "^1.4.1", + "lab": "^5.13.0", + "precommit-hook": "^3.0.0", + "standard": "^4.5.2" + }, + "dependencies": { + "bs58": "^2.0.1", + "multihashing": "^0.1.2" + } } diff --git a/tests/id-test.js b/tests/id-test.js new file mode 100644 index 0000000..e69de29