How to use the peer-id.createFromCID 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 / src / circuit / index.js View on Github external
async dial (ma, options) {
    // Check the multiaddr to see if it contains a relay and a destination peer
    const addrs = ma.toString().split('/p2p-circuit')
    const relayAddr = multiaddr(addrs[0])
    const destinationAddr = multiaddr(addrs[addrs.length - 1])
    const relayPeer = PeerId.createFromCID(relayAddr.getPeerId())
    const destinationPeer = PeerId.createFromCID(destinationAddr.getPeerId())

    let disconnectOnFailure = false
    let relayConnection = this._registrar.getConnection(new PeerInfo(relayPeer))
    if (!relayConnection) {
      relayConnection = await this._dialer.connectToMultiaddr(relayAddr, options)
      disconnectOnFailure = true
    }

    try {
      const virtualConnection = await hop({
        connection: relayConnection,
        circuit: this,
        request: {
          type: CircuitPB.Type.HOP,
          srcPeer: {
            id: this.peerInfo.id.toBytes(),
github libp2p / js-libp2p / src / circuit / index.js View on Github external
async dial (ma, options) {
    // Check the multiaddr to see if it contains a relay and a destination peer
    const addrs = ma.toString().split('/p2p-circuit')
    const relayAddr = multiaddr(addrs[0])
    const destinationAddr = multiaddr(addrs[addrs.length - 1])
    const relayPeer = PeerId.createFromCID(relayAddr.getPeerId())
    const destinationPeer = PeerId.createFromCID(destinationAddr.getPeerId())

    let disconnectOnFailure = false
    let relayConnection = this._registrar.getConnection(new PeerInfo(relayPeer))
    if (!relayConnection) {
      relayConnection = await this._dialer.connectToMultiaddr(relayAddr, options)
      disconnectOnFailure = true
    }

    try {
      const virtualConnection = await hop({
        connection: relayConnection,
        circuit: this,
        request: {
          type: CircuitPB.Type.HOP,
          srcPeer: {