forked from Mirrors/keyoxide-web
Fix crypto fallback
This commit is contained in:
parent
3b227d1ba2
commit
e6f4796399
1 changed files with 4 additions and 6 deletions
|
@ -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 * as openpgp from 'openpgp'
|
||||||
import QRCode from 'qrcode'
|
import QRCode from 'qrcode'
|
||||||
let _crypto = (typeof window === 'undefined') ? null : crypto
|
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
|
// Compute local part of Web Key Directory URL
|
||||||
export async function computeWKDLocalPart(localPart) {
|
export async function computeWKDLocalPart(localPart) {
|
||||||
|
if (!_crypto) {
|
||||||
|
_crypto = (await import('crypto')).webcrypto
|
||||||
|
}
|
||||||
|
|
||||||
const localPartEncoded = new TextEncoder().encode(localPart.toLowerCase());
|
const localPartEncoded = new TextEncoder().encode(localPart.toLowerCase());
|
||||||
const localPartHashed = new Uint8Array(await _crypto.subtle.digest('SHA-1', localPartEncoded));
|
const localPartHashed = new Uint8Array(await _crypto.subtle.digest('SHA-1', localPartEncoded));
|
||||||
return encodeZBase32(localPartHashed);
|
return encodeZBase32(localPartHashed);
|
||||||
|
|
Loading…
Reference in a new issue