From 7d986da7c3d936f3ce881e4222f2ab5a914fb14a Mon Sep 17 00:00:00 2001 From: Pawan Paudel Date: Wed, 24 Apr 2024 22:32:07 +0545 Subject: [PATCH] fix: Make crypto key check work in different node versions --- src/lib/privateRepo.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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,