import PeerId from "peer-id" ; import { Json } from "@chainsafe/ssz" ; import { writeFile , readFile } from "../util" ; export async function createPeerId ( ) { return await PeerId . create ( { keyType : "secp256k1" } ) ; } export function writePeerId ( filepath , peerId ) { writeFile ( filepath , ( peerId . toJSON ( ) as unknown ) as Json ) ; } export async function readPeerId ( filepath ) { return await PeerId . createFromJSON ( readFile ( filepath ) ) ; } export async function initPeerId ( filepath ) { writePeerId ( filepath , await createPeerId ( ) ) ; }