How to use the peer-id.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 IDEO-coLAB / nomad / src / utils / ipfs-overload.js View on Github external
(exists, cb) => {
          if (exists === true) {
            return cb(new Error('repo already exists'))
          }

          // Generate peer identity keypair + transform to desired format + add to config.
          opts.log(`generating ${opts.bits}-bit RSA keypair...`, false)

          if (opts.privKey) {
            peerId.createFromPrivKey(opts.privKey, cb)
          } else {
            peerId.create({bits: opts.bits}, cb)
          }
        },
        (keys, cb) => {
github nicola / js-gossip-cyclon / test / cyclon.spec.js View on Github external
describe('cyclon-peer', function () {
  this.timeout(20000)
  const AliceId = PeerId.createFromPrivKey(alice.privKey)
  const Bob = new CyclonPeer({peers: [new PeerInfo(PeerId.createFromB58String(AliceId.toB58String()))]})
  const Charles = new CyclonPeer()
  const Eve = new CyclonPeer()

  it('create with bootstrap peers', (done) => {
    const Alice = new CyclonPeer({peer: new PeerInfo(AliceId)})
    expect(Alice).to.exist
    expect(Bob).to.exist
    expect(Bob.partialView).to.have.lengthOf(1)
    expect(Object.keys(Bob.partialView.peers)[0]).to.eql(Bob.partialView.peerToId(Alice.peer))
    expect(Bob.partialView.get(Alice.peer)).to.exist
    done()
  })

  it('partialView is within the maxPeers limit', (done) => {
    const Alice = new CyclonPeer({peer: new PeerInfo(AliceId), maxPeers: 1})
github richardschneider / ipfs-encryption / test / keychain.spec.js View on Github external
before(function (done) {
        const encoded = Buffer.from(alicePrivKey, 'base64')
        PeerId.createFromPrivKey(encoded, (err, id) => {
          alice = id
          done()
        })
      })
github libp2p / js-libp2p-keychain / test / keychain.spec.js View on Github external
before(function (done) {
        const encoded = Buffer.from(alicePrivKey, 'base64')
        PeerId.createFromPrivKey(encoded, (err, id) => {
          expect(err).to.not.exist()
          alice = id
          done()
        })
      })
github ipfs / js-libp2p-ipfs-browser / test / websockets-only.js View on Github external
before((done) => {
    const ma = '/ip4/127.0.0.1/tcp/9200/ws/ipfs/' + rawPeer.id

    PeerId.createFromPrivKey(rawPeer.privKey, (err, id) => {
      if (err) {
        return done(err)
      }

      peerB = new PeerInfo(id)
      peerB.multiaddrs.add(ma)
      done()
    })
  })
github libp2p / js-iprs-record / test / validator.spec.js View on Github external
const makeRecord = (key, k, callback) => {
  PeerId.createFromPrivKey(key.bytes, (err, id) => {
    if (err) {
      return callback(err)
    }
    let rec
    try {
      rec = new Record(k, crypto.randomBytes(10), id)
    } catch (err) {
      return callback(err)
    }
    callback(null, rec)
  })
}
github validitylabs / hopr / src / getPeerInfo.js View on Github external
new Promise(async (resolve, reject) => {
                let serializedKeyPair
                try {
                    serializedKeyPair = await db.get('key-pair')

                    resolve(deserializeKeyPair(serializedKeyPair))
                } catch (err) {
                    if (!err.notFound) return reject(err)

                    const key = await generateKeyPair('secp256k1', 256)
                    const peerId = await PeerId.createFromPrivKey(key.bytes)

                    const serializedKeyPair = await serializeKeyPair(peerId)
                    console.log(serializedKeyPair)
                    await db.put('key-pair', serializedKeyPair)

                    resolve(peerId)
                }
            })
github libp2p / js-libp2p-floodsub / examples / pub-sub-1-topic / publisher.js View on Github external
function bootNode (next) {
  PeerId.createFromPrivKey(privateKey, (err, idPublisher) => {
    if (err) {
      throw err
    }
    const peerPublisher = new PeerInfo(idPublisher)
    peerPublisher.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/12345'))
    nodePublisher = new Node(peerPublisher)
    nodePublisher.start((err) => {
      console.log('Publisher listening on:')

      peerPublisher.multiaddrs.forEach((ma) => {
        console.log(ma.toString() + '/ipfs/' + idPublisher.toB58String())
      })
      next(err)
    })
  })
}
github ipfs / js-ipfs / src / core / components / pre-start.js View on Github external
(config, cb) => {
        const privKey = config.Identity.PrivKey

        peerId.createFromPrivKey(privKey, (err, id) => {
          cb(err, config, id)
        })
      },
      (config, id, cb) => {
github ethereumjs / ethereumjs-client / lib / net / server / libp2pserver.js View on Github external
return new Promise((resolve, reject) => {
      const handler = (err, peerInfo) => {
        if (err) {
          return reject(err)
        }
        this.multiaddrs.forEach(ma => peerInfo.multiaddrs.add(ma))
        resolve(peerInfo)
      }
      if (this.key) {
        PeerId.createFromPrivKey(this.key, (err, id) => {
          if (err) {
            return reject(err)
          }
          PeerInfo.create(id, handler)
        })
      } else {
        PeerInfo.create(handler)
      }
    })
  }