Compare commits

..

10 Commits

Author SHA1 Message Date
David Dias
6624c27d8d chore: release version v0.8.1 2016-12-18 08:06:16 +00:00
David Dias
26ac06d21c chore: update contributors 2016-12-18 08:06:16 +00:00
David Dias
f0d72b7bfe Merge pull request #44 from libp2p/feat/cache
feat: cache b58 id
2016-12-18 08:05:41 +00:00
Friedel Ziegelmayer
78d96d0b14 feat: create b58 string on creation and throw on id mutation 2016-12-18 09:02:37 +01:00
Friedel Ziegelmayer
bebb0a7eae feat: cache b58 id 2016-12-14 09:05:07 +01:00
Greenkeeper
5d6a962b6c chore(package): update aegir to version 9.2.1 (#43)
https://greenkeeper.io/
2016-12-10 11:59:28 -08:00
Prashanth Chandra
531c9f1086 Fix typo in README example (#42) 2016-12-04 21:52:26 -08:00
Greenkeeper
06f93cd961 chore(package): update aegir to version 9.1.2 (#39)
https://greenkeeper.io/
2016-11-28 15:52:39 +00:00
Greenkeeper
1452f233c8 chore(package): update multihashes to version 0.3.0 (#40)
https://greenkeeper.io/
2016-11-28 15:34:50 +00:00
Greenkeeper
77900c7b45 chore(package): update aegir to version 9.1.0 (#38)
https://greenkeeper.io/
2016-11-03 17:59:54 +00:00
4 changed files with 29 additions and 8 deletions

View File

@@ -58,7 +58,7 @@ var PeerId = require('peer-id')
var bs58 = require('bs58')
PeerId.create({ bits: 1024 }, (err, id) => {
console.log(JSON.stringify(id.toJSON(), null, 2)
console.log(JSON.stringify(id.toJSON(), null, 2))
})
```

View File

@@ -1,6 +1,6 @@
{
"name": "peer-id",
"version": "0.8.0",
"version": "0.8.1",
"description": "IPFS Peer Id implementation in Node.js",
"main": "src/index.js",
"bin": "src/bin.js",
@@ -33,14 +33,14 @@
},
"homepage": "https://github.com/libp2p/js-peer-id",
"devDependencies": {
"aegir": "^9.0.1",
"aegir": "^9.2.1",
"chai": "^3.5.0",
"pre-commit": "^1.1.3"
},
"dependencies": {
"async": "^2.0.1",
"libp2p-crypto": "^0.7.0",
"multihashes": "^0.2.2"
"multihashes": "^0.3.0"
},
"repository": {
"type": "git",
@@ -50,9 +50,10 @@
"David Dias <daviddias.p@gmail.com>",
"David Dias <mail@daviddias.me>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Greenkeeper <support@greenkeeper.io>",
"Prashanth Chandra <coolshanth94@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>",
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]

View File

@@ -17,11 +17,20 @@ class PeerId {
assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments')
}
this.id = id
this._id = id
this._idB58String = mh.toB58String(this.id)
this._privKey = privKey
this._pubKey = pubKey
}
get id () {
return this._id
}
set id (val) {
throw new Error('Id is immutable')
}
get privKey () {
return this._privKey
}
@@ -61,7 +70,7 @@ class PeerId {
// of go-ipfs for its config file
toJSON () {
return {
id: mh.toB58String(this.id),
id: this.toB58String(),
privKey: toB64Opt(this.marshalPrivKey()),
pubKey: toB64Opt(this.marshalPubKey())
}
@@ -77,7 +86,7 @@ class PeerId {
}
toB58String () {
return mh.toB58String(this.id)
return this._idB58String
}
}

View File

@@ -29,6 +29,17 @@ describe('PeerId', () => {
})
})
it('throws on changing the id', (done) => {
PeerId.create((err, id) => {
expect(err).to.not.exist
expect(id.toB58String().length).to.equal(46)
expect(() => {
id.id = new Buffer('hello')
}).to.throw(/immutable/)
done()
})
})
it('recreate an Id from Hex string', () => {
const id = PeerId.createFromHexString(testIdHex)
expect(testIdBytes).to.deep.equal(id.id)