mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-06-06 10:51:31 +00:00
use static keyword
This commit is contained in:
parent
1be7d888d6
commit
3ef704ba32
43
src/index.js
43
src/index.js
@ -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,9 +137,8 @@ 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.
|
||||||
*
|
*
|
||||||
* @param {Object=} opts - Configuration object.
|
* @param {Object=} opts - Configuration object.
|
||||||
@ -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 = {}
|
||||||
@ -179,47 +177,47 @@ PeerId.create = function (opts, callback) {
|
|||||||
|
|
||||||
callback(null, new PeerId(digest, privKey))
|
callback(null, new PeerId(digest, privKey))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Peer ID from hex string representing the key's multihash.
|
* Creates a Peer ID from hex string representing the key's multihash.
|
||||||
*
|
*
|
||||||
* @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))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Peer ID from a buffer representing the key's multihash.
|
* Creates a Peer ID from a buffer representing the key's multihash.
|
||||||
*
|
*
|
||||||
* @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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Peer ID from a `base58` string representing the
|
* Creates a Peer ID from a `base58` string representing the
|
||||||
* key's multihash.
|
* key's multihash.
|
||||||
*
|
*
|
||||||
* @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))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Peer ID from a buffer containing a public key.
|
* Creates a Peer ID from a buffer containing a public key.
|
||||||
*
|
*
|
||||||
* @param {string|Buffer} key
|
* @param {string|Buffer} key
|
||||||
* @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')
|
||||||
@ -237,9 +235,9 @@ PeerId.createFromPubKey = function (key, callback) {
|
|||||||
|
|
||||||
callback(null, new PeerId(digest, null, pubKey))
|
callback(null, new PeerId(digest, null, pubKey))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Peer ID from a buffer containing a private key.
|
* Creates a Peer ID from a buffer containing a private key.
|
||||||
*
|
*
|
||||||
* @param {string|Buffer} key - The private key, if passed as
|
* @param {string|Buffer} key - The private key, if passed as
|
||||||
@ -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')
|
||||||
@ -269,16 +267,16 @@ PeerId.createFromPrivKey = function (key, callback) {
|
|||||||
|
|
||||||
callback(null, new PeerId(digest, privKey))
|
callback(null, new PeerId(digest, privKey))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import a `PeerId` from a serialized JSON object.
|
* Import a `PeerId` from a serialized JSON object.
|
||||||
*
|
*
|
||||||
* @param {PeerIdJson} obj
|
* @param {PeerIdJson} obj
|
||||||
* @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')
|
||||||
}
|
}
|
||||||
@ -321,6 +319,7 @@ PeerId.createFromJSON = function (obj, callback) {
|
|||||||
} else {
|
} else {
|
||||||
callback(null, new PeerId(id, null, pub))
|
callback(null, new PeerId(id, null, pub))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user