Skip to content

Commit

Permalink
fix: Make crypto key check work in different node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpaudel93 committed Apr 24, 2024
1 parent 4483050 commit 7d986da
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/privateRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 7d986da

Please sign in to comment.