PeerId
A Peer ID is the SHA-256 multihash of a public key.
static
PeerId.create
create(opts: Object?, callback: function (Error, PeerId))
Create a new PeerId
by generating a new public/private keypair.
Parameters
Example
const PeerId = require('peer-id')
PeerId.create((err, id) => {
if (err) {
throw err
}
console.log('id', JSON.stringify(id))
})
PeerId.createFromHexString
createFromHexString(str: string): PeerId
Creates a Peer ID from hex string representing the key's multihash.
Parameters
Name
Description
str: string
Hex encoded id
Returns
PeerId.createFromBytes
createFromBytes(buf: Buffer): PeerId
Creates a Peer ID from a buffer representing the key's multihash.
Parameters
Name
Description
buf: Buffer
Returns
PeerId.createFromB58String
createFromB58String(str: string): PeerId
Creates a Peer ID from a base58
string representing the
key's multihash.
Parameters
Name
Description
str: string
base58
encoded id
Returns
PeerId.createFromPubKey
createFromPubKey(key: (string | Buffer), callback: function (Error, PeerId))
Creates a Peer ID from a buffer containing a public key.
PeerId.createFromPrivKey
createFromPrivKey(key: (string | Buffer), callback: function (Error, PeerId))
Creates a Peer ID from a buffer containing a private key.
PeerId.createFromJSON
createFromJSON(obj: PeerIdJson, callback: function (Error, PeerId))
Import a PeerId
from a serialized JSON object.
Parameters
Name
Description
obj: PeerIdJson
instance
constructor
constructor(id: Buffer, privKey: RSAPrivateKey?, pubKey: RSAPublickKey?)
Parameters
Name
Description
PeerId.prototype.marshalPubKey
marshalPubKey(): Buffer
Create the protobuf version of the public key, matching go-ipfs formatting.
Returns
Buffer
The marshalled public key
Throws
Error
Failure
PeerId.prototype.marshalPrivKey
marshalPrivKey(): Buffer
Create the protobuf version of the private key, matching go-ipfs formatting.
Returns
PeerId.prototype.toJSON
toJSON(): PeerIdJson
Return the jsonified version of the key, matching the formatting of go-ipfs for its config file.