Skip to content

Commit

Permalink
fix browser tests for ESM build
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Oct 26, 2023
1 parent 196c302 commit 72934d0
Show file tree
Hide file tree
Showing 7 changed files with 20,851 additions and 3,414 deletions.
2 changes: 1 addition & 1 deletion browser_tests/test/groth16.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}

await testBrowserBuilds(snarkjs);
const esmBuild = await import("/build/esm.js");
const esmBuild = await import("/build/browser.esm.js");
await testBrowserBuilds(esmBuild);
shutdown();
</script>
Expand Down
4 changes: 2 additions & 2 deletions build/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function askEntropy() {

function getRandomBytes(n) {
let array = new Uint8Array(n);
if (typeof globalThis.crypto !== "undefined") { // Supported
if (process.browser) { // Supported
globalThis.crypto.getRandomValues(array);
} else { // NodeJS
crypto__default["default"].randomFillSync(array);
Expand All @@ -290,7 +290,7 @@ function getRandomBytes(n) {
}

async function sha256digest(data) {
if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.subtle !== "undefined") { // Supported
if (process.browser) { // Supported
const buffer = await globalThis.crypto.subtle.digest("SHA-256", data.buffer);
return new Uint8Array(buffer);
} else { // NodeJS
Expand Down
4 changes: 2 additions & 2 deletions build/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function askEntropy() {

function getRandomBytes(n) {
let array = new Uint8Array(n);
if (typeof globalThis.crypto !== "undefined") { // Supported
if (process.browser) { // Supported
globalThis.crypto.getRandomValues(array);
} else { // NodeJS
crypto__default["default"].randomFillSync(array);
Expand All @@ -185,7 +185,7 @@ function getRandomBytes(n) {
}

async function sha256digest(data) {
if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.subtle !== "undefined") { // Supported
if (process.browser) { // Supported
const buffer = await globalThis.crypto.subtle.digest("SHA-256", data.buffer);
return new Uint8Array(buffer);
} else { // NodeJS
Expand Down
Loading

0 comments on commit 72934d0

Please sign in to comment.