Introduction
Generate, import, and export PeerIDs, for use with IPFS.
+font-weight: bold;}.hljs-deletion{background: #fdd;}.hljs-addition{background: #dfd;}.hljs-emphasis{font-style: italic;}.hljs-strong{font-weight: bold;}Introduction
Generate, import, and export PeerIDs, for use with IPFS.
A Peer ID is the SHA-256 multihash of a public key.
The public key is a base64 encoded string of a protobuf containing an RSA DER buffer. This uses a node buffer to pass the base64 encoded public key protobuf to the multihash for ID generation.
@@ -83,11 +83,11 @@ the global namespace.<script src="https://unpkg.com/peer-id/dist/index.min.js"></script> <!-- OR --> <script src="https://unpkg.com/peer-id/dist/index.js"></script>
-
PeerId
A Peer ID is the SHA-256 multihash of a public key.
See
static
PeerId.create
create(opts: Object?, callback: function (Error, PeerId)): undefined
Create a new PeerId
by generating a new public/private keypair.
static
PeerId.create
create(opts: Object?, callback: function (Error, PeerId)): undefined
Create a new PeerId
by generating a new public/private keypair.
Parameters
PeerId.createFromPrivKey
createFromPrivKey(key: (string | Buffer), callback: function (Error, PeerId)): undefined
Creates a Peer ID from a buffer containing a private key.
Parameters
Returns
PeerId.createFromJSON
createFromJSON(obj: PeerIdJson, callback: function (Error, PeerId)): undefined
Import a PeerId
from a serialized JSON object.
PeerId.createFromJSON
createFromJSON(obj: PeerIdJson, callback: function (Error, PeerId)): undefined
Import a PeerId
from a serialized JSON object.
Parameters
obj: PeerIdJson
:
Returns
instance
constructor
constructor(id: Buffer, privKey: RSAPrivateKey?, pubKey: RSAPublickKey?)
Parameters
id: Buffer
:privKey: RSAPrivateKey?
:pubKey: RSAPublickKey?
:
PeerId.prototype.id
id: Buffer
PeerId.prototype.privKey
privKey: (RSAPrivateKey | undefined)
The private key of this id, if it exists.
-PeerId.prototype.marshalPubKey
marshalPubKey(): Buffer
Create the protobuf version of the public key, +
instance
constructor
constructor(id: Buffer, privKey: RSAPrivateKey?, pubKey: RSAPublickKey?)
Parameters
id: Buffer
:privKey: RSAPrivateKey?
:pubKey: RSAPublickKey?
:
PeerId.prototype.id
id: Buffer
PeerId.prototype.privKey
privKey: (RSAPrivateKey | undefined)
The private key of this id, if it exists.
+PeerId.prototype.marshalPubKey
marshalPubKey(): Buffer
Create the protobuf version of the public key, matching go-ipfs formatting.
Returns
Buffer
The marshalled public key
-PeerId.prototype.marshalPrivKey
marshalPrivKey(): Buffer
Create the protobuf version of the private key, +
PeerId.prototype.toJSON
toJSON(): PeerIdJson
Return the jsonified version of the key, matching the formatting +
PeerId.prototype.toJSON
toJSON(): PeerIdJson
Return the jsonified version of the key, matching the formatting of go-ipfs for its config file.