How to use the peer-id.createFromJSON 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 libp2p / js-libp2p / test / dialing / direct.js View on Github external
before('create nodes', async () => {
    const [peerId1, peerId2] = await Promise.all([
      createPeerId(PeerIds.shift()),
      createPeerId(PeerIds.shift())
    ])

    const peerInfo1 = new PeerInfo(peerId1)
    peerInfo1.multiaddrs.add('/ip4/0.0.0.0/tcp/8080')
    // peerInfo1.multiaddrs.add('/ip4/0.0.0.0/tcp/0/ws')
    const peerInfo2 = new PeerInfo(peerId2)
    peerInfo2.multiaddrs.add('/ip4/0.0.0.0/tcp/10000')
    // peerInfo2.multiaddrs.add('/ip4/0.0.0.0/tcp/0/ws')

    libp2p = new Libp2p({ peerInfo: peerInfo1, config: { peerDiscovery: { autoDial: false } } })
    remoteLibp2p = new Libp2p({ peerInfo: peerInfo2, config: { peerDiscovery: { autoDial: false } } })
  })
github libp2p / js-libp2p-switch / test / get-peer-info.spec.js View on Github external
it('should add a peerInfo to the book', (done) => {
    PeerId.createFromJSON(TestPeerInfos[1].id, (err, id) => {
      const peerInfo = new PeerInfo(id)
      expect(peerBook.has(peerInfo.id.toB58String())).to.eql(false)

      expect(getPeerInfo(peerInfo, peerBook)).to.exist()
      expect(peerBook.has(peerInfo.id.toB58String())).to.eql(true)
      done(err)
    })
  })
github libp2p / js-libp2p / test / circuit / dialer.spec.js View on Github external
before((done) => {
      PeerId.createFromJSON(nodes.node4, (_, peerId) => {
        PeerInfo.create(peerId, (err, peerInfo) => {
          peer = peerInfo
          peer.multiaddrs.add('/p2p-circuit/ipfs/QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE')
          done(err)
        })
      })
    })
github libp2p / js-libp2p / test / dialing / direct.node.js View on Github external
before(async () => {
      const [peerId, remotePeerId] = await Promise.all([
        PeerId.createFromJSON(Peers[0]),
        PeerId.createFromJSON(Peers[1])
      ])

      peerInfo = new PeerInfo(peerId)
      remotePeerInfo = new PeerInfo(remotePeerId)

      remoteLibp2p = new Libp2p({
        peerInfo: remotePeerInfo,
        modules: {
          transport: [Transport],
          streamMuxer: [Muxer],
          connEncryption: [Crypto]
        }
      })
      remoteLibp2p.handle('/echo/1.0.0', ({ stream }) => pipe(stream, stream))
github libp2p / js-libp2p / test / circuit / stop.spec.js View on Github external
        (cb) => PeerId.createFromJSON(nodes.node4, cb),
        (peerId, cb) => PeerInfo.create(peerId, cb),
github libp2p / js-libp2p / test / transports / transport-manager.spec.js View on Github external
before(async () => {
    const peerId = await PeerId.createFromJSON(Peers[0])
    peerInfo = new PeerInfo(peerId)
  })
github libp2p / js-libp2p / test / identify / index.spec.js View on Github external
before(async () => {
    [localPeer, remotePeer] = (await Promise.all([
      PeerId.createFromJSON(Peers[0]),
      PeerId.createFromJSON(Peers[1])
    ])).map(id => new PeerInfo(id))
  })
github daviddias / js-ethereum-libp2p / examples / blocks-sync / node-1.js View on Github external
const ethereum = require('../../src')
const idJson = require('./id-1')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr')

const Block = require('ethereumjs-block')
const async = require('async')
const thousand = require('./../../test/data/real-chain/first-1000-blocks.json')

const id = PeerId.createFromJSON(idJson)
const info = new PeerInfo(id)
const ma = multiaddr('/ip4/127.0.0.1/tcp/12345')
info.multiaddr.add(ma)

const node = new ethereum.Node()

node.start(info, (err) => {
  if (err) {
    throw err
  }

  console.log('🎧 Listening on:')
  node.libp2p.peerInfo.multiaddrs.forEach((ma) => {
    console.log(ma.toString() + '/ipfs/' + id.toB58String())
  })
github daviddias / js-ethereum-libp2p / examples / run-through-blockchain / example.js View on Github external
const ethereum = require('../../src')
const idJson = require('./../broadcast-blocks/id-1')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr')
const Account = require('ethereumjs-account')
const Block = require('ethereumjs-block')
const async = require('async')
const thousand = require('./../../test/data/real-chain/first-1000-blocks.json')

const id = PeerId.createFromJSON(idJson)
const info = new PeerInfo(id)
const ma = multiaddr('/ip4/127.0.0.1/tcp/12345')
info.multiaddr.add(ma)

const node = new ethereum.Node()

node.start(info, (err) => {
  if (err) {
    throw err
  }

  console.log('🎧 Listening on:')
  node.libp2p.peerInfo.multiaddrs.forEach((ma) => {
    console.log(ma.toString() + '/ipfs/' + id.toB58String())
  })
github daviddias / js-ethereum-libp2p / examples / webui / src / app / actions / buttons.js View on Github external
function relayInfo () {
  const relayId = PeerId.createFromJSON(relayPeerIdJson)
  const relayma = multiaddr('/ip4/127.0.0.1/tcp/33333/ws')
  const relayInfo = new PeerInfo(relayId)
  relayInfo.multiaddr.add(relayma)

  return relayInfo
}