mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-27 06:02:28 +00:00
Add documentation
This commit is contained in:
parent
5a58bb22f2
commit
2db95f47d4
1
.jshintignore
Normal file
1
.jshintignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
10
.jshintrc
Normal file
10
.jshintrc
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"node": true,
|
||||||
|
|
||||||
|
"curly": true,
|
||||||
|
"latedef": true,
|
||||||
|
"quotmark": true,
|
||||||
|
"undef": true,
|
||||||
|
"unused": true,
|
||||||
|
"trailing": true
|
||||||
|
}
|
68
README.md
68
README.md
@ -1,2 +1,66 @@
|
|||||||
# node-ipfs-peer-id
|
ipfs-peer-id Node.js implementation
|
||||||
IPFS Peer Id implementation in Node.js
|
===================================
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> 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
|
||||||
|
```
|
||||||
|
26
package.json
26
package.json
@ -4,11 +4,31 @@
|
|||||||
"description": "IPFS Peer Id implementation in Node.js",
|
"description": "IPFS Peer Id implementation in Node.js",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"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": [
|
"keywords": [
|
||||||
"IPFS"
|
"IPFS"
|
||||||
],
|
],
|
||||||
"author": "David Dias <mail@daviddias.me>",
|
"author": "David Dias <daviddias@ipfs.io>",
|
||||||
"license": "MIT"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
0
tests/id-test.js
Normal file
0
tests/id-test.js
Normal file
Loading…
x
Reference in New Issue
Block a user