diff --git a/changelogs/unreleased/1264-dark64 b/changelogs/unreleased/1264-dark64 new file mode 100644 index 00000000..c9d64e90 --- /dev/null +++ b/changelogs/unreleased/1264-dark64 @@ -0,0 +1 @@ +Optimize `zokrates-js` library size \ No newline at end of file diff --git a/zokrates_js/patch.js b/zokrates_js/patch.js index 4e33e752..4f4c19aa 100644 --- a/zokrates_js/patch.js +++ b/zokrates_js/patch.js @@ -18,17 +18,17 @@ import pako from "pako"; let bytes; - if (typeof atob === 'function') { + if (typeof Buffer === "function") { + bytes = Buffer.from(encoded, "base64"); + } else if (typeof atob === "function") { const binary = atob(encoded); bytes = new Uint8Array(binary.length); - + for (let i = 0; i < binary.length; i++) { bytes[i] = binary.charCodeAt(i); - } - } else if (typeof Buffer === 'function') { - bytes = Buffer.from(encoded, 'base64'); + } } else { - throw new Error('Unsupported platform'); + throw new Error("Unsupported platform"); } const imports = getImports();