How to use the peer-id.createFromB58String 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 validitylabs / hopr / src / network / natTraversal / base / index.js View on Github external
.on('connect', async () => {
                        // console.log('[initiator] connected')

                        const peerInfo = await PeerInfo.create(await PeerId.createFromB58String(multiaddr.getPeerId()))

                        peerInfo.multiaddrs.add(multiaddr)
                        peerInfo.connect(multiaddr)

                        conn.setPeerInfo(peerInfo)
                        resolve(conn)
                    })
github IDEO-coLAB / nomad / src / shim-node.js View on Github external
.then((storedPeerInfo) => {
      if (!storedPeerInfo) {
        log.info(`${MODULE_NAME}: GET ${peerId} (No info found)`)
        return null
      }

      log.info(`${MODULE_NAME}: GET ${peerId}`)

      // const peerIdObj = new PeerId(new Buffer(storedPeerInfo.id))
      // const peerInfo = new PeerInfo(peerIdObj)
      const peerInfo = new PeerInfo(PeerId.createFromB58String(storedPeerInfo.id))
      // add multiaddrs to the peer
      // storedPeerInfo.multiaddrs.forEach((mAddr) => {
      //   console.log('madr:', mAddr)
      //   peerInfo.multiaddr.add(mAddr)
      // })
      // peerInfo.multiaddr.add('/ip4/10.2.2.164/tcp/4002')
      // peerInfo.multiaddr.add('/ip4/10.2.2.164/tcp/4002')

      console.log(storedPeerInfo.multiaddrs[1])
      console.log('/ip4/10.2.2.164/tcp/4002')
      console.log('/ip4/10.2.2.164/tcp/4002' === storedPeerInfo.multiaddrs[1])

      // peerInfo.multiaddr.add(storedPeerInfo.multiaddrs[0])
      peerInfo.multiaddr.add(storedPeerInfo.multiaddrs[1])

      console.log('GOT FROM SHIM SERVER:', storedPeerInfo)
github validitylabs / hopr / hopr.js View on Github external
async function checkPeerIdInput(query) {
    let peerId

    try {
        // Throws an error if the Id is invalid
        Multihash.decode(bs58.decode(query))

        peerId = await addPubKey(PeerId.createFromB58String(query))
    } catch (err) {
        throw Error(chalk.red(`Invalid peerId. ${err.message}`))
    }
    return peerId
}
github libp2p / js-libp2p / test / circuit / dialer.spec.js View on Github external
beforeEach(() => {
      dialer.swarm = {
        _peerInfo: peer
      }
      dialer.utils = utilsFactory({})
      dialer.relayConns = new Map()
      dialer._negotiateRelay.callThrough()
      dialer._dialRelayHelper.callThrough()
      peer = new PeerInfo(PeerId.createFromB58String('QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE'))
      p = pair()
      conn = new Connection(p[1])
    })
github libp2p / js-libp2p-webrtc-star / src / webrtc-star / index.js View on Github external
function peerDiscovered (maStr) {
    log('Peer Discovered:', maStr)
    const id = peerId.createFromB58String(maStr.split('/')[8])
    const peer = new PeerInfo(id)
    peer.multiaddr.add(multiaddr(maStr))
    this.discovery.emit('peer', peer)
  }
}
github pathephone / pathephone-desktop / app / api / ipfs / src / swarm / peers.js View on Github external
callback(null, result.Peers.map((p) => {
          const res = {
            addr: multiaddr(p.Addr),
            peer: PeerId.createFromB58String(p.Peer),
            muxer: p.Muxer
          }

          if (p.Latency) {
            res.latency = p.Latency
          }

          if (p.Streams) {
            res.streams = p.Streams
          }

          return res
        }))
      }
github validitylabs / hopr / src / network / crawl.js View on Github external
            (cb) => node.peerRouting.findPeer(PeerId.createFromB58String(peerId), cb),
            (peerInfo, cb) => node.dialProtocol(peerInfo, PROTOCOL_CRAWLING, cb),
github holochain / n3h / packages / n3h-mod-message-libp2p / lib / libp2p-bundle.js View on Github external
async _fetchPeer (peerId) {
    const pr = this._node.peerRouting
    const lookFor = PeerId.createFromB58String(peerId)
    const start = Date.now()
    let peer = null
    let waitTime = 1
    while (!peer && Date.now() - start < 5000) {
      try {
        if (this._peerCache.has(peerId)) {
          return this._peerCache.get(peerId)
        }
        peer = await $p(pr.findPeer.bind(pr, lookFor))
      } catch (e) {
        peer = null
        await $sleep(waitTime)
        waitTime *= 2
        if (waitTime > 200) {
          waitTime = 200
        }
github ipfs / js-ipfs-http-client / src / swarm / peers.js View on Github external
return (res.Peers || []).map(peer => {
      const info = {}
      try {
        info.addr = multiaddr(peer.Addr)
        info.peer = PeerId.createFromB58String(peer.Peer)
      } catch (error) {
        info.error = error
        info.rawPeerInfo = peer
      }
      if (peer.Muxer) {
        info.muxer = peer.Muxer
      }
      if (peer.Latency) {
        info.latency = peer.Latency
      }
      if (peer.Streams) {
        info.streams = peer.Streams
      }
      if (peer.Direction != null) {
        info.direction = peer.Direction
      }
github holochain / n3h / hc-p2p-libp2p / lib / index.js View on Github external
async _fetchPeer (peerId) {
    if (this._peerCache.has(peerId)) {
      return this._peerCache.get(peerId)
    }
    const pr = this._p2p.peerRouting
    const start = Date.now()
    let peer = null
    while (Date.now() - start < 5000) {
      try {
        peer = await $p(pr.findPeer.bind(
          pr, PeerId.createFromB58String(peerId)))
      } catch (e) {
        peer = null
        await _sleep(100)
      }
    }
    if (!peer) {
      throw new Error('could not find peer')
    }
    if (peer.id.toB58String() !== peerId) {
      throw new Error('wtf')
    }
    this._peerCache.set(peerId, peer)
    return peer
  }