From 3f940f6e98fd5d29dd8d67385ff79723a680e867 Mon Sep 17 00:00:00 2001 From: Josh Long Date: Tue, 3 Oct 2023 12:01:37 -0400 Subject: [PATCH] move Blob import to global scope of package --- packages/crypto/src/lib/crypto.ts | 33 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/crypto/src/lib/crypto.ts b/packages/crypto/src/lib/crypto.ts index a9f6243e15..010b520386 100644 --- a/packages/crypto/src/lib/crypto.ts +++ b/packages/crypto/src/lib/crypto.ts @@ -60,6 +60,18 @@ if (!globalThis.wasmECDSA) { } }); } + +if (isNode()) { + try { + let { Blob } = import('node:buffer').then((module) => { + globalThis.Blob = module.Blob; + }); + } catch (e) { + log( + 'Warn: could not resolve Blob from node api set, perhaps polyfil a Blob implementation of your choice' + ); + } +} /** ---------- Exports ---------- */ /** @@ -101,20 +113,13 @@ export const encryptWithSymmetricKey = async ( symmKey, data ); - if (isNode()) { - let { Blob } = await import("node:buffer"); - const encryptedZipBlob = new Blob([iv, new Uint8Array(encryptedZipData)], { - type: 'application/octet-stream', - }); - - return encryptedZipBlob; - } else { - const encryptedZipBlob = new Blob([iv, new Uint8Array(encryptedZipData)], { - type: 'application/octet-stream', - }); - - return encryptedZipBlob; - } + + let { Blob } = await import('node:buffer'); + const encryptedZipBlob = new Blob([iv, new Uint8Array(encryptedZipData)], { + type: 'application/octet-stream', + }); + + return encryptedZipBlob; }; /**