From 745d852ce407167ace22c07fd0943d444a687539 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Thu, 19 Dec 2024 23:33:03 +0000 Subject: [PATCH 1/2] chore: remove trailing null bytes from printed graffiti --- packages/beacon-node/src/util/graffiti.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/src/util/graffiti.ts b/packages/beacon-node/src/util/graffiti.ts index fb5c30aca3d..b99843f3b03 100644 --- a/packages/beacon-node/src/util/graffiti.ts +++ b/packages/beacon-node/src/util/graffiti.ts @@ -12,7 +12,7 @@ export function toGraffitiBuffer(graffiti: string): Buffer { * Converts a graffiti from 32 bytes buffer back to a UTF-8 string */ export function fromGraffitiBuffer(graffiti: Uint8Array): string { - return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength).toString("utf8"); + return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength).toString("utf8").replace(/\0+$/, ""); } export function getDefaultGraffiti( From 5174c91468362440e05557c408f4f94c86f63871 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 20 Dec 2024 00:40:37 +0000 Subject: [PATCH 2/2] Use replaceAll instead of regex --- packages/beacon-node/src/util/graffiti.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/beacon-node/src/util/graffiti.ts b/packages/beacon-node/src/util/graffiti.ts index b99843f3b03..ff23145d729 100644 --- a/packages/beacon-node/src/util/graffiti.ts +++ b/packages/beacon-node/src/util/graffiti.ts @@ -12,7 +12,9 @@ export function toGraffitiBuffer(graffiti: string): Buffer { * Converts a graffiti from 32 bytes buffer back to a UTF-8 string */ export function fromGraffitiBuffer(graffiti: Uint8Array): string { - return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength).toString("utf8").replace(/\0+$/, ""); + return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength) + .toString("utf8") + .replaceAll("\u0000", ""); } export function getDefaultGraffiti(