How to use the peer-id.createFromHexString 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-connection-manager / test / utils / mocks.js View on Github external
exports.mockLibp2pNode = () => {
  const peerInfo = new PeerInfo(PeerId.createFromHexString('122019318b6e5e0cf93a2314bf01269a2cc23cd3dcd452d742cdb9379d8646f6e4a9'))

  return Object.assign(new EventEmitter(), {
    peerInfo: peerInfo,
    handle () {},
    unhandle () {},
    contentRouting: {
      provide: (cid, callback) => callback(),
      findProviders: (cid, timeout, callback) => callback(null, [])
    },
    on () {},
    dial (peer, protocol, callback) {
      setImmediate(() => callback())
    },
    swarm: {
      muxedConns: {},
      setMaxListeners () {}
github ChainSafe / lodestar / packages / lodestar / src / cli / commands / dev.ts View on Github external
end = parseInt(parts[1]);
        } else {
          end = parseInt(options.validators);
        }
        for (let i = start; i < end; i++) {
          const validatorPath = `./validators/validator-db-${i}`;
          if(fs.existsSync(validatorPath)) {
            rmDir(validatorPath);
          }
        }
      }
    }

    let peerId;
    if (options["peerId"]) {
      peerId = PeerId.createFromHexString(options["peerId"]);
    } else if (options["peerIdFile"]) {
      peerId = loadPeerId(options["peerId"]);
    } else {
      peerId = createPeerId();
    }
    const libp2p = await createNodeJsLibp2p(peerId, conf.network);
    const config = options.preset === "minimal" ? minimalConfig : mainnetConfig;
    const tree = ProgressiveMerkleTree.empty(DEPOSIT_CONTRACT_TREE_DEPTH, new MerkleTreeSerialization(config));
    let state: BeaconState;
    if (options.genesisState) {
      state = quickStartOptionToState(config, tree, options.genesisState);
    } else if (options.genesisTime && options.validatorCount) {
      logger.info(`Starting node with genesisTime ${new Date(parseInt(options.genesisTime)*1000)} and \
       ${options.validatorCount} validators.`);
      state = quickStartState(config, tree, parseInt(options.genesisTime), parseInt(options.validatorCount));
    } else {