mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-25 06:22:24 +00:00
add coverage, fix codestyle
This commit is contained in:
parent
1f72aaf7b7
commit
845bd088fe
@ -1,7 +1,7 @@
|
|||||||
peer-id JavaScript implementation
|
peer-id JavaScript implementation
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
[](http://ipn.io) [[](http://webchat.freenode.net/?channels=%23ipfs) ](https://travis-ci.org/diasdavid/js-peer-id)  [](https://david-dm.org/diasdavid/js-peer-id) [](https://github.com/feross/standard)
|
[](http://ipn.io) [[](http://webchat.freenode.net/?channels=%23ipfs) ](https://travis-ci.org/diasdavid/js-peer-id)  [](https://david-dm.org/diasdavid/js-peer-id) [](https://github.com/feross/standard)
|
||||||
> IPFS Peer Id implementation in JavaScript
|
> IPFS Peer Id implementation in JavaScript
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
"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:node": "mocha tests/test.js",
|
|
||||||
"lint": "standard",
|
"lint": "standard",
|
||||||
"test": "npm run test:node && npm run test:browser",
|
"test": "npm run test:node && npm run test:browser",
|
||||||
"test:browser": "karma start karma.conf.js"
|
"test:node": "mocha tests/test.js",
|
||||||
|
"test:browser": "karma start karma.conf.js",
|
||||||
|
"coverage": "istanbul cover --print both -- _mocha tests/test.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"IPFS"
|
"IPFS"
|
||||||
@ -20,7 +21,8 @@
|
|||||||
],
|
],
|
||||||
"standard": {
|
"standard": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"dist"
|
"dist",
|
||||||
|
"deps"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@ -33,6 +35,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"buffer-loader": "0.0.1",
|
"buffer-loader": "0.0.1",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
|
"istanbul": "^0.4.2",
|
||||||
"json-loader": "^0.5.4",
|
"json-loader": "^0.5.4",
|
||||||
"karma": "^0.13.19",
|
"karma": "^0.13.19",
|
||||||
"karma-chrome-launcher": "^0.2.2",
|
"karma-chrome-launcher": "^0.2.2",
|
||||||
|
@ -11,7 +11,8 @@ var protobuf = require('protocol-buffers')
|
|||||||
var isNode = !global.window
|
var isNode = !global.window
|
||||||
|
|
||||||
// protobuf read from file
|
// protobuf read from file
|
||||||
var messages = isNode ? protobuf(fs.readFileSync(__dirname + '/../pb/crypto.proto')) : protobuf(require('buffer!./../pb/crypto.proto'))
|
var messages = isNode ? protobuf(fs.readFileSync(__dirname + '/../pb/crypto.proto'))
|
||||||
|
: protobuf(require('buffer!./../pb/crypto.proto'))
|
||||||
|
|
||||||
exports = module.exports = Id
|
exports = module.exports = Id
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ function Id (id, privKey, pubKey) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// unwrap the private key protobuf
|
// unwrap the private key protobuf
|
||||||
function unmarshal (key) {
|
function unmarshal (key) {
|
||||||
var dpb = messages.PrivateKey.decode(key)
|
var dpb = messages.PrivateKey.decode(key)
|
||||||
return dpb
|
return dpb
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
/* globals describe, it */
|
||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const expect = require('chai').expect
|
const expect = require('chai').expect
|
||||||
@ -16,32 +18,38 @@ const testIdBytes = new Buffer('1220151ab1658d8294ab34b71d5582cfe20d06414212f440
|
|||||||
const testIdB58String = 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A'
|
const testIdB58String = 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A'
|
||||||
|
|
||||||
describe('id', function (done) {
|
describe('id', function (done) {
|
||||||
this.timeout(30000)
|
this.timeout(30000)
|
||||||
|
|
||||||
it('create a new id', done => {
|
it('create a new id', done => {
|
||||||
var id = PeerId.create()
|
var id = PeerId.create()
|
||||||
expect(id.toB58String().length).to.equal(46)
|
expect(id.toB58String().length).to.equal(46)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('recreate an Id from Hex string', done => {
|
it('recreate an Id from Hex string', done => {
|
||||||
var id = PeerId.createFromHexString(testIdHex)
|
var id = PeerId.createFromHexString(testIdHex)
|
||||||
expect(testIdBytes).to.deep.equal(id.id)
|
expect(testIdBytes).to.deep.equal(id.id)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Recreate an Id from a Buffer', done => {
|
it('Recreate an Id from a Buffer', done => {
|
||||||
var id = PeerId.createFromBytes(testIdBytes)
|
var id = PeerId.createFromBytes(testIdBytes)
|
||||||
expect(testId.id).to.equal(id.toHexString())
|
expect(testId.id).to.equal(id.toHexString())
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Recreate a B58 String', done => {
|
it('Recreate a B58 String', done => {
|
||||||
var id = PeerId.createFromB58String(testIdB58String)
|
var id = PeerId.createFromB58String(testIdB58String)
|
||||||
expect(testIdB58String).to.equal(id.toB58String())
|
expect(testIdB58String).to.equal(id.toB58String())
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Recreate from a Public Key', done => {
|
it('Recreate from a Public Key', done => {
|
||||||
var id = PeerId.createFromPubKey(testId.pubKey)
|
var id = PeerId.createFromPubKey(testId.pubKey)
|
||||||
expect(testIdB58String).to.equal(id.toB58String())
|
expect(testIdB58String).to.equal(id.toB58String())
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Recreate from a Private Key', done => {
|
it('Recreate from a Private Key', done => {
|
||||||
var id = PeerId.createFromPrivKey(testId.privKey)
|
var id = PeerId.createFromPrivKey(testId.privKey)
|
||||||
expect(testIdB58String).to.equal(id.toB58String())
|
expect(testIdB58String).to.equal(id.toB58String())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user