display pubkey in PEM format instead of hex for peers

This commit is contained in:
Sam Hadow 2025-03-11 13:58:02 +01:00
parent cfebb76398
commit 4b616772cc

View File

@ -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 };