From f8bd9a36855cf254deea68256d41bda2cfc62fe5 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 3 May 2021 11:00:07 +0200 Subject: [PATCH] Fix dynamic key loading --- static/scripts.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/static/scripts.js b/static/scripts.js index 1562ce1..ef5a3e5 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -109,18 +109,20 @@ const fetchProfileKey = async function() { const rawKeyData = await fetch(window.kx.key.url) let key, errorMsg - // try { - // key = (await openpgp.key.read(await rawKeyData.arrayBuffer())).keys[0] - // } catch(error) { - // errorMsg = error.message - // } - try { - key = (await openpgp.key.readArmored(await rawKeyData.text())).keys[0] - } catch (error) { + key = (await openpgp.key.read(new Uint8Array(await rawKeyData.clone().arrayBuffer()))).keys[0] + } catch(error) { errorMsg = error.message } + if (!key) { + try { + key = (await openpgp.key.readArmored(await rawKeyData.clone().text())).keys[0] + } catch (error) { + errorMsg = error.message + } + } + if (key) { window.kx.key.object = key return