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.
*
* @returns {Buffer} - The marshalled public key
* @throws {Error} - Failure
*/
marshalPubKey () {
if (this.pubKey) {
@ -138,9 +137,8 @@ class PeerId {
toB58String () {
return mh.toB58String(this.id)
}
}
/**
/**
* Create a new `PeerId` by generating a new public/private keypair.
*
* @param {Object=} opts - Configuration object.
@ -159,7 +157,7 @@ class PeerId {
* })
*
*/
PeerId.create = function (opts, callback) {
static create (opts, callback) {
if (typeof opts === 'function') {
callback = opts
opts = {}
@ -179,47 +177,47 @@ PeerId.create = function (opts, callback) {
callback(null, new PeerId(digest, privKey))
})
}
}
/**
/**
* Creates a Peer ID from hex string representing the key's multihash.
*
* @param {string} str - Hex encoded id
* @returns {PeerId}
*/
PeerId.createFromHexString = function (str) {
static createFromHexString (str) {
return new PeerId(mh.fromHexString(str))
}
}
/**
/**
* Creates a Peer ID from a buffer representing the key's multihash.
*
* @param {Buffer} buf
* @returns {PeerId}
*/
PeerId.createFromBytes = function (buf) {
static createFromBytes (buf) {
return new PeerId(buf)
}
}
/**
/**
* Creates a Peer ID from a `base58` string representing the
* key's multihash.
*
* @param {string} str - `base58` encoded id
* @returns {PeerId}
*/
PeerId.createFromB58String = function (str) {
static createFromB58String (str) {
return new PeerId(mh.fromB58String(str))
}
}
/**
/**
* Creates a Peer ID from a buffer containing a public key.
*
* @param {string|Buffer} key
* @param {function(Error, PeerId)} callback
* @returns {undefined}
*/
PeerId.createFromPubKey = function (key, callback) {
static createFromPubKey (key, callback) {
let buf = key
if (typeof buf === 'string') {
buf = new Buffer(key, 'base64')
@ -237,9 +235,9 @@ PeerId.createFromPubKey = function (key, callback) {
callback(null, new PeerId(digest, null, pubKey))
})
}
}
/**
/**
* Creates a Peer ID from a buffer containing a private key.
*
* @param {string|Buffer} key - The private key, if passed as
@ -247,7 +245,7 @@ PeerId.createFromPubKey = function (key, callback) {
* @param {function(Error, PeerId)} callback
* @returns {undefined}
*/
PeerId.createFromPrivKey = function (key, callback) {
static createFromPrivKey (key, callback) {
let buf = key
if (typeof buf === 'string') {
buf = new Buffer(key, 'base64')
@ -269,16 +267,16 @@ PeerId.createFromPrivKey = function (key, callback) {
callback(null, new PeerId(digest, privKey))
})
}
}
/**
/**
* Import a `PeerId` from a serialized JSON object.
*
* @param {PeerIdJson} obj
* @param {function(Error, PeerId)} callback
* @returns {undefined}
*/
PeerId.createFromJSON = function (obj, callback) {
static createFromJSON (obj, callback) {
if (typeof callback !== 'function') {
throw new Error('callback is required')
}
@ -321,6 +319,7 @@ PeerId.createFromJSON = function (obj, callback) {
} else {
callback(null, new PeerId(id, null, pub))
}
}
}
/**