Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Crypto Endeavour #33

Merged
merged 11 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .aegir.js

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ build/Release
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

lib
dist
dist
26 changes: 19 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
sudo: false
language: node_js
node_js:
- 4
- 5
- stable

matrix:
include:
- node_js: 4
env: CXX=g++-4.8
- node_js: 6
env: CXX=g++-4.8
- node_js: stable
env:
- SAUCE=true
- CXX=g++-4.8

# Make sure we have new NPM.
before_install:
Expand All @@ -14,12 +21,17 @@ script:
- npm test
- npm run coverage

addons:
firefox: 'latest'

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

addons:
firefox: latest
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
67 changes: 57 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,41 @@
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-peer-id/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-peer-id?branch=master)
[![Dependency Status](https://david-dm.org/libp2p/js-peer-id.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-id)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/js-peer-id.svg)](https://saucelabs.com/u/js-peer-i
d)

> [IPFS](https://github.com/ipfs/ipfs) Peer ID implementation in JavaScript.

- [Description](#description)
- [Example](#example)
- [Installation](#installation)
- [npm](#npm)
- [Setup](#setup)
- [Node.js](#nodejs)
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
- [Browser: `<script>` Tag](#browser-script-tag)
- [API](#api)
- [Create](#create)
- [`new PeerId(id[, privKey, pubKey])`](#new-peeridid-privkey-pubkey)
- [`create([opts], callback)`](#createopts-callback)
- [Import](#import)
- [`createFromHexString(str)`](#createfromhexstringstr)
- [`createFromBytes(buf)`](#createfrombytesbuf)
- [`createFromB58String(str)`](#createfromb58stringstr)
- [`createFromPubKey(pubKey)`](#createfrompubkeypubkey)
- [`createFromPrivKey(privKey)`](#createfromprivkeyprivkey)
- [`createFromJSON(obj)`](#createfromjsonobj)
- [Export](#export)
- [`toHexString()`](#tohexstring)
- [`toBytes()`](#tobytes)
- [`toB58String()`](#tob58string)
- [`toJSON()`](#tojson)
- [`toPrint()`](#toprint)
- [License](#license)

# Description

Generate, import, and export PeerIDs, for use with [IPFS](https://github.com/ipfs/ipfs).
Expand All @@ -26,17 +58,26 @@ to the multihash for ID generation.*
var PeerId = require('peer-id')
var bs58 = require('bs58')

var id = PeerId.create({ bits: 32 })

console.log('id ', id.toB58String())
console.log('priv key ', bs58.encode(id.privKey.bytes))
console.log('pub key ', bs58.encode(id.pubKey.bytes))
PeerId.create({ bits: 1024 }, (err, id) => {
console.log(JSON.stringify(id.toJSON(), null, 2)
})
```

```
id QmeeLFb92nkZJGj3gXLqXrEMzCMYs6uBgQLVNbrcXEvYXk
priv key 6ibrcPAbevzvPpkq6EA6XmLyuhmUrJrEvUfgQDtEiSEPzGnGU8Ejwf6b11DVm6opnFGo
pub key 2BeBZVKJ9RQs4i4LbGv4ReEeuBA5dck2Gje3wt67e44XuyyPq5jE
{
"id": "Qma9T5YraSnpRDZqRR4krcSJabThc8nwZuJV3LercPHufi",
"privKey": "CAAS4AQwggJcAgEAAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCYxtv5tDHrshPUqKu5yQB+QgmzSNNEXKL9FbF4IwsOsKkCiNR+x
hzjt4ePByrBjJADlrJR56piKxssEdJPiGdbdDwRsWtkQ+iKBuyI+i4Jl+q2mVLosBD4/o/WqeWj0oqIplIgqYAWR+WcHkLbAgMBAAECgYAsg+N5
8KWamZ4PeZNWwl5wYbyLBT821cAxsQWC+zmQiywM1ip3zimy4WXCPWgQqekJ/Ps6EKES8sbrFnJ4hss0XZ+BC0FTsPs1o3c5T1h9L7zN8RA9/Bs
V7kF9RKUOHG0Tr0oZ3CGzqRNDNUeznJPEUP3amb1YCXMJLPkR+AONQQJBAO5huuYxxEDEjNn4zCiJFGwdbZSA097Gyyi8PS0po+X/0KRx8WgQun
Za+dh+LohEmxEk85gQ+GJrvbaPG94G4aECQQDOmEK1zmuJvI2PRZ/QPHs9CgRL1bIZEg8rJfhnv0YDD7NUeTpyT8+3/A4nbJjw8/zsr0A2UdSW6
EfEaaaplsr7AkEAvJQ5q4MxMt+KYaEtuN+AdWruVi137mOrMgWAC+tGClxOLNkq1V1udNTRk892djx3w59MyT6bkBiVkwcxT3p4IQJAV914GdzF
7dmsly+0bZsbivVUqHAlg/YjT2WhxXYbL7ggvB+nFPEO1iA0YN4WGfybKIrMk42wDdKSm12XzW7duwJAS9oUNnPDNEWnmNYXQsrkSMSloKJPsyC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can trim these

WosGBHPvUQbuavAr0AWG0irShVma0J1WtNSIfs2w7Q+zxFlX4umjgDw==",
"pubKey": "CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCYxtv5tDHrshPUqKu5yQB+QgmzSN
NEXKL9FbF4IwsOsKkCiNR+xhzjt4ePByrBjJADlrJR56piKxssEdJPiGdbdDwRsWtkQ+iKBuyI+i4Jl+q2mVLosBD4/o/WqeWj0oqIplIgqYAWR
+WcHkLbAgMBAAE="
}
```

# Installation
Expand Down Expand Up @@ -93,11 +134,14 @@ const PeerId = require('peer-id')

The key format is detailed in [libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto).

### `create([opts])`
### `create([opts], callback)`

Generates a new Peer ID, complete with public/private keypair.

- `opts: Object`: Default: `{bits: 2048}`
- `callback: Function`

Calls back `callback` with `err, id`.

## Import

Expand All @@ -114,10 +158,14 @@ Creates a Peer ID from a Base58 string representing the key's multihash.

### `createFromPubKey(pubKey)`

- `publicKey: Buffer`

Creates a Peer ID from a buffer containing a public key.

### `createFromPrivKey(privKey)`

- `privKey: Buffer`

Creates a Peer ID from a buffer containing a private key.

### `createFromJSON(obj)`
Expand All @@ -126,7 +174,6 @@ Creates a Peer ID from a buffer containing a private key.
- `obj.pubKey: String` - The public key in protobuf format, encoded in 'base64'
- `obj.privKey: String` - The private key in protobuf format, encoded in 'base 64'


## Export

### `toHexString()`
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"name": "peer-id",
"version": "0.7.0",
"description": "IPFS Peer Id implementation in Node.js",
"main": "lib/index.js",
"main": "src/index.js",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO change before merge

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"bin": "src/bin.js",
"jsnext:main": "src/index.js",
"scripts": {
"lint": "aegir-lint",
"build": "aegir-build",
Expand All @@ -27,24 +26,25 @@
"test"
],
"engines": {
"node": "^4.3.0"
"node": ">=4.0.0"
},
"bugs": {
"url": "https://github.com/diasdavid/js-peer-id/issues"
"url": "https://github.com/libp2p/js-peer-id/issues"
},
"homepage": "https://github.com/diasdavid/js-peer-id",
"homepage": "https://github.com/libp2p/js-peer-id",
"devDependencies": {
"aegir": "^8.0.0",
"aegir": "^9.0.0",
"chai": "^3.5.0",
"pre-commit": "^1.1.3"
},
"dependencies": {
"async": "^2.0.1",
"libp2p-crypto": "^0.6.1",
"multihashes": "^0.2.2"
},
"repository": {
"type": "git",
"url": "https://github.com/diasdavid/js-peer-id.git"
"url": "https://github.com/libp2p/js-peer-id.git"
},
"contributors": [
"David Dias <[email protected]>",
Expand All @@ -53,4 +53,4 @@
"dignifiedquire <[email protected]>",
"nginnever <[email protected]>"
]
}
}
8 changes: 7 additions & 1 deletion src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@

const PeerId = require('./index.js')

console.log(JSON.stringify(PeerId.create().toJSON(), null, ' '))
PeerId.create((err, id) => {
if (err) {
throw err
}

console.log(JSON.stringify(id.toJSON(), null, 2))
})
Loading