mirror of
https://github.com/CryptKeeperZK/ffjavascript.git
synced 2026-05-03 03:00:11 -04:00
fix: Convert global & window references to globalThis
This commit is contained in:
@@ -2,11 +2,11 @@ import wasmcurves from "wasmcurves";
|
||||
import buildEngine from "./engine.js";
|
||||
import * as Scalar from "./scalar.js";
|
||||
|
||||
global.curve_bls12381 = null;
|
||||
globalThis.curve_bls12381 = null;
|
||||
|
||||
export default async function buildBls12381(singleThread) {
|
||||
|
||||
if ((!singleThread)&&(global.curve_bls12381)) return global.curve_bls12381;
|
||||
if ((!singleThread)&&(globalThis.curve_bls12381)) return globalThis.curve_bls12381;
|
||||
const params = {
|
||||
name: "bls12381",
|
||||
wasm: wasmcurves.bls12381_wasm,
|
||||
@@ -22,7 +22,7 @@ export default async function buildBls12381(singleThread) {
|
||||
const curve = await buildEngine(params);
|
||||
curve.terminate = async function() {
|
||||
if (!params.singleThread) {
|
||||
global.curve_bls12381 = null;
|
||||
globalThis.curve_bls12381 = null;
|
||||
await this.tm.terminate();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,11 +2,11 @@ import wasmcurves from "wasmcurves";
|
||||
import buildEngine from "./engine.js";
|
||||
import * as Scalar from "./scalar.js";
|
||||
|
||||
global.curve_bn128 = null;
|
||||
globalThis.curve_bn128 = null;
|
||||
|
||||
export default async function buildBn128(singleThread) {
|
||||
|
||||
if ((!singleThread)&&(global.curve_bn128)) return global.curve_bn128;
|
||||
if ((!singleThread)&&(globalThis.curve_bn128)) return globalThis.curve_bn128;
|
||||
const params = {
|
||||
name: "bn128",
|
||||
wasm: wasmcurves.bn128_wasm,
|
||||
@@ -21,13 +21,13 @@ export default async function buildBn128(singleThread) {
|
||||
const curve = await buildEngine(params);
|
||||
curve.terminate = async function() {
|
||||
if (!params.singleThread) {
|
||||
global.curve_bn128 = null;
|
||||
globalThis.curve_bn128 = null;
|
||||
await this.tm.terminate();
|
||||
}
|
||||
};
|
||||
|
||||
if (!singleThread) {
|
||||
global.curve_bn128 = curve;
|
||||
globalThis.curve_bn128 = curve;
|
||||
}
|
||||
|
||||
return curve;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
/* global window */
|
||||
import ChaCha from "./chacha.js";
|
||||
import crypto from "crypto";
|
||||
|
||||
export function getRandomBytes(n) {
|
||||
let array = new Uint8Array(n);
|
||||
if (typeof window !== "undefined") { // Browser
|
||||
if (typeof window.crypto !== "undefined") { // Supported
|
||||
window.crypto.getRandomValues(array);
|
||||
if (process.browser) { // Browser
|
||||
if (typeof globalThis.crypto !== "undefined") { // Supported
|
||||
globalThis.crypto.getRandomValues(array);
|
||||
} else { // fallback
|
||||
for (let i=0; i<n; i++) {
|
||||
array[i] = (Math.random()*4294967296)>>>0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* global window, navigator, Blob, Worker, WebAssembly */
|
||||
/* global navigator, WebAssembly */
|
||||
/*
|
||||
Copyright 2019 0KIMS association.
|
||||
|
||||
@@ -41,7 +41,7 @@ function sleep(ms) {
|
||||
|
||||
function base64ToArrayBuffer(base64) {
|
||||
if (process.browser) {
|
||||
var binary_string = window.atob(base64);
|
||||
var binary_string = globalThis.atob(base64);
|
||||
var len = binary_string.length;
|
||||
var bytes = new Uint8Array(len);
|
||||
for (var i = 0; i < len; i++) {
|
||||
@@ -55,7 +55,7 @@ function base64ToArrayBuffer(base64) {
|
||||
|
||||
function stringToBase64(str) {
|
||||
if (process.browser) {
|
||||
return window.btoa(str);
|
||||
return globalThis.btoa(str);
|
||||
} else {
|
||||
return Buffer.from(str).toString("base64");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user