How to use the peer-id.PeerId.createFromPrivKey function in peer-id

To help you get started, we’ve selected a few peer-id examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ChainSafe / lodestar / src / p2p / index.ts View on Github external
return new Promise((resolve, reject) => {
      const handler = (err, peerInfo) => {
        if (err) {
	  return reject(err);
        }
        this.peerBook.getAll().forEach((peer) => {
	  peer.multiaddrs.forEach((multiaddr) => {
	    peerInfo.multiaddrs.add(multiaddr);
	    resolve(peerInfo);
	  });
        });
      };
      if (this.privateKey) {
        PeerId.createFromPrivKey(this.privateKey, (err, id) => {
	  if (err) {
	    return reject(err);
	  }
	  PeerInfo.create(id, handler);	  
        });
      } else {
        PeerInfo.create(handler);
      } 
    });
  }