function arrayBufferToBase64(buffer) {
const bytes = new Uint8Array(buffer)
return btoa(String.fromCharCode(...bytes))
}
async function exportPublicKeyInPemFormat(key) {
const exported = await crypto.subtle.exportKey('spki', key)
const pem = `-----BEGIN PUBLIC KEY-----\n${arrayBufferToBase64(exported)}\n-----END PUBLIC KEY-----`
return pem
}