import Protector from "libp2p/src/pnet" ; import PeerId from "peer-id" ; import type { Options } from "libp2p" ; import { Buffer } from "buffer" ; import Libp2p from "libp2p" ; import merge from "deepmerge" ; import { defaults } from "./node" ; export { Options as Libp2pOptions } ; export { MemoryDatastore } from "interface-datastore" ; export { Buffer } from "buffer" ; export const setupLibP2PHost = async ( peerId ? , secret ? , listen = [ "/ip4/0.0.0.0/tcp/4005" , "/ip4/127.0.0.1/tcp/4006/ws" ] , opts ? ) : Promise < Libp2p > => { const options = merge ( { addresses : { listen } , ... opts , } , defaults ) ; if ( secret ) { if ( ! options . modules ) { options . modules = { } ; } options . modules . connProtector = new Protector ( Buffer . from ( secret ) ) ; } if ( peerId ) { options . peerId = peerId ; } return Libp2p . create ( options ) ; } ;