From 4b616772cc8ebe80988135fae66a5f930698e825 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Tue, 11 Mar 2025 13:58:02 +0100 Subject: [PATCH] display pubkey in PEM format instead of hex for peers --- src/public/rooms.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/public/rooms.js b/src/public/rooms.js index e20da6e..1e82bd4 100644 --- a/src/public/rooms.js +++ b/src/public/rooms.js @@ -25,7 +25,7 @@ function render_room(roomId, pubkey) { // public key textarea const pubKeyText = document.createElement('textarea'); - pubKeyText.value = pubkey; + pubKeyText.value = hexToPem(pubkey); pubKeyText.readOnly = true; roomDiv.appendChild(pubKeyText); @@ -117,4 +117,12 @@ async function request_rooms() { return rooms; } +function hexToPem(hexString) { + const byteArray = new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); + let base64 = btoa(String.fromCharCode.apply(null, byteArray)); + const base64Chunks = base64.match(/.{1,64}/g) || []; + return `-----BEGIN PUBLIC KEY-----\n${base64Chunks.join('\n')}\n-----END PUBLIC KEY-----`; +} + + export { render_room, render_rooms_wrapper };