Fix crypto fallback

This commit is contained in:
Yarmo Mackenbach 2022-03-03 15:48:32 +01:00
parent 3b227d1ba2
commit e6f4796399
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1

View file

@ -30,15 +30,13 @@ more information on this, and how to apply and follow the GNU AGPL, see <https:/
import * as openpgp from 'openpgp'
import QRCode from 'qrcode'
let _crypto = (typeof window === 'undefined') ? null : crypto
if (!_crypto) {
_crypto = import('crypto').then((crypto) => {
return crypto.webcrypto
})
// import { webcrypto as crypto } from 'crypto'
}
// Compute local part of Web Key Directory URL
export async function computeWKDLocalPart(localPart) {
if (!_crypto) {
_crypto = (await import('crypto')).webcrypto
}
const localPartEncoded = new TextEncoder().encode(localPart.toLowerCase());
const localPartHashed = new Uint8Array(await _crypto.subtle.digest('SHA-1', localPartEncoded));
return encodeZBase32(localPartHashed);