JSPM

@lodestar/reqresp

1.28.0-dev.3c466f1f65
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2486
  • Score
    100M100P100Q123544F
  • License Apache-2.0

A Typescript implementation of the Ethereum Consensus Req/Resp protocol

Package Exports

    Readme

    Lodestar Eth Consensus Req/Resp Protocol

    Discord ETH Beacon APIs Spec v2.5.0 ES Version Node Version

    This package is part of ChainSafe's Lodestar project

    Typescript implementation of the Ethereum Consensus Req/Resp protocol

    Usage

    import {Libp2p} from "libp2p";
    import {ssz} from "@lodestar/types";
    import {ReqResp, ContextBytesType, Protocol, Encoding} from "@lodestar/reqresp";
    import {ForkName} from "@lodestar/params";
    import {Logger} from "@lodestar/utils";
    
    async function getReqResp(libp2p: Libp2p, logger: Logger): Promise<void> {
      const reqResp = new ReqResp({libp2p, logger, metricsRegister: null});
    
      // Register a PONG handler to respond with caller's Ping request
      const pingProtocol: Protocol = {
        method: "ping",
        version: 1,
        encoding: Encoding.SSZ_SNAPPY,
        contextBytes: {type: ContextBytesType.Empty},
        requestSizes: ssz.phase0.Ping,
        responseSizes: () => ssz.phase0.Ping,
        handler: async function* (req) {
          yield {
            data: req.data,
            fork: ForkName.phase0,
          };
        },
      };
    
      reqResp.registerProtocol(pingProtocol);
    }

    Prerequisites

    What you need

    You will need to go over the specification.

    Getting started

    Contributors

    Read our contributors document, submit an issue or talk to us on our discord!

    License

    Apache-2.0 ChainSafe Systems