UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

28 lines 1.33 kB
import { GRAFFITI_SIZE } from "../constants/index.js"; /** * Parses a graffiti UTF8 string and returns a 32 bytes buffer right padded with zeros */ export function toGraffitiBytes(graffiti) { return Buffer.concat([Buffer.from(graffiti, "utf8"), Buffer.alloc(GRAFFITI_SIZE, 0)], GRAFFITI_SIZE); } /** * Converts a graffiti from 32 bytes buffer back to a UTF-8 string */ export function fromGraffitiBytes(graffiti) { return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength) .toString("utf8") .replaceAll("\u0000", ""); } export function getDefaultGraffiti(consensusClientVersion, executionClientVersion, opts) { if (opts.private) { return ""; } if (executionClientVersion != null) { const { code: executionCode, commit: executionCommit } = executionClientVersion; // Follow the 2-byte commit format in https://github.com/ethereum/execution-apis/pull/517#issuecomment-1918512560 return `${executionCode}${executionCommit.slice(0, 4)}${consensusClientVersion.code}${consensusClientVersion.commit.slice(0, 4)}`; } // No EL client info available. We still want to include CL info albeit not spec compliant return `${consensusClientVersion.code}${consensusClientVersion.commit.slice(0, 4)}`; } //# sourceMappingURL=graffiti.js.map