use static keyword

This commit is contained in:
Friedel Ziegelmayer 2016-12-05 20:48:29 +01:00
parent 1be7d888d6
commit 3ef704ba32

View File

@ -70,7 +70,6 @@ class PeerId {
* matching go-ipfs formatting. * matching go-ipfs formatting.
* *
* @returns {Buffer} - The marshalled public key * @returns {Buffer} - The marshalled public key
* @throws {Error} - Failure
*/ */
marshalPubKey () { marshalPubKey () {
if (this.pubKey) { if (this.pubKey) {
@ -138,7 +137,6 @@ class PeerId {
toB58String () { toB58String () {
return mh.toB58String(this.id) return mh.toB58String(this.id)
} }
}
/** /**
* Create a new `PeerId` by generating a new public/private keypair. * Create a new `PeerId` by generating a new public/private keypair.
@ -159,7 +157,7 @@ class PeerId {
* }) * })
* *
*/ */
PeerId.create = function (opts, callback) { static create (opts, callback) {
if (typeof opts === 'function') { if (typeof opts === 'function') {
callback = opts callback = opts
opts = {} opts = {}
@ -187,7 +185,7 @@ PeerId.create = function (opts, callback) {
* @param {string} str - Hex encoded id * @param {string} str - Hex encoded id
* @returns {PeerId} * @returns {PeerId}
*/ */
PeerId.createFromHexString = function (str) { static createFromHexString (str) {
return new PeerId(mh.fromHexString(str)) return new PeerId(mh.fromHexString(str))
} }
@ -197,7 +195,7 @@ PeerId.createFromHexString = function (str) {
* @param {Buffer} buf * @param {Buffer} buf
* @returns {PeerId} * @returns {PeerId}
*/ */
PeerId.createFromBytes = function (buf) { static createFromBytes (buf) {
return new PeerId(buf) return new PeerId(buf)
} }
@ -208,7 +206,7 @@ PeerId.createFromBytes = function (buf) {
* @param {string} str - `base58` encoded id * @param {string} str - `base58` encoded id
* @returns {PeerId} * @returns {PeerId}
*/ */
PeerId.createFromB58String = function (str) { static createFromB58String (str) {
return new PeerId(mh.fromB58String(str)) return new PeerId(mh.fromB58String(str))
} }
@ -219,7 +217,7 @@ PeerId.createFromB58String = function (str) {
* @param {function(Error, PeerId)} callback * @param {function(Error, PeerId)} callback
* @returns {undefined} * @returns {undefined}
*/ */
PeerId.createFromPubKey = function (key, callback) { static createFromPubKey (key, callback) {
let buf = key let buf = key
if (typeof buf === 'string') { if (typeof buf === 'string') {
buf = new Buffer(key, 'base64') buf = new Buffer(key, 'base64')
@ -247,7 +245,7 @@ PeerId.createFromPubKey = function (key, callback) {
* @param {function(Error, PeerId)} callback * @param {function(Error, PeerId)} callback
* @returns {undefined} * @returns {undefined}
*/ */
PeerId.createFromPrivKey = function (key, callback) { static createFromPrivKey (key, callback) {
let buf = key let buf = key
if (typeof buf === 'string') { if (typeof buf === 'string') {
buf = new Buffer(key, 'base64') buf = new Buffer(key, 'base64')
@ -278,7 +276,7 @@ PeerId.createFromPrivKey = function (key, callback) {
* @param {function(Error, PeerId)} callback * @param {function(Error, PeerId)} callback
* @returns {undefined} * @returns {undefined}
*/ */
PeerId.createFromJSON = function (obj, callback) { static createFromJSON (obj, callback) {
if (typeof callback !== 'function') { if (typeof callback !== 'function') {
throw new Error('callback is required') throw new Error('callback is required')
} }
@ -322,6 +320,7 @@ PeerId.createFromJSON = function (obj, callback) {
callback(null, new PeerId(id, null, pub)) callback(null, new PeerId(id, null, pub))
} }
} }
}
/** /**
* Convert a given `Buffer` to a `base64` encoded string. * Convert a given `Buffer` to a `base64` encoded string.