Skip to content

Commit

Permalink
move Blob import to global scope of package
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Long committed Oct 3, 2023
1 parent 9007be1 commit 3f940f6
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions packages/crypto/src/lib/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------- */

/**
Expand Down Expand Up @@ -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;
};

/**
Expand Down

0 comments on commit 3f940f6

Please sign in to comment.