diff --git a/src/lib/privateRepo.ts b/src/lib/privateRepo.ts index 7342f41..0253911 100644 --- a/src/lib/privateRepo.ts +++ b/src/lib/privateRepo.ts @@ -11,6 +11,14 @@ type PrivateState = { const arweave = initArweave(); +function isCryptoKey(obj: any) { + try { + return obj instanceof CryptoKey; + } catch (e) { + return obj instanceof crypto.webcrypto.CryptoKey; + } +} + async function deriveAddress(publicKey: string) { const pubKeyBuf = arweave.utils.b64UrlToBuffer(publicKey); const sha512DigestBuf = await crypto.subtle.digest('SHA-512', pubKeyBuf); @@ -25,7 +33,7 @@ async function encryptDataWithExistingKey( ) { let key = aesKey; - if (!(aesKey instanceof crypto.webcrypto.CryptoKey)) { + if (!isCryptoKey(aesKey)) { key = await crypto.subtle.importKey( 'raw', aesKey,