diff --git a/cli/package.json b/cli/package.json index b63e7b0..0219f35 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "@axiom-crypto/halo2-wasm-cli", - "version": "0.1.6-rc.0", + "version": "0.1.7-alpha.0", "description": "Halo2 Javascript library", "main": "index.js", "scripts": { @@ -18,8 +18,8 @@ "author": "Intrinsic Technologies", "license": "ISC", "dependencies": { - "@axiom-crypto/halo2-lib-js": "0.2.14-rc.0", - "@axiom-crypto/halo2-wasm": "0.2.11-rc.1", + "@axiom-crypto/halo2-lib-js": "0.2.15-alpha.0", + "@axiom-crypto/halo2-wasm": "0.2.12-alpha.0", "commander": "^11.1.0", "typescript": "^5.2.2" }, diff --git a/halo2-lib-js/package.json b/halo2-lib-js/package.json index e163fc8..ce2a0b0 100644 --- a/halo2-lib-js/package.json +++ b/halo2-lib-js/package.json @@ -1,13 +1,13 @@ { "name": "@axiom-crypto/halo2-lib-js", - "version": "0.2.14-rc.0", + "version": "0.2.15-alpha.0", "description": "Halo2 Javascript library", "main": "index.js", "scripts": { "build": "rm -rf ./dist && tsc && node ./scripts/postTsc.js && pnpm build:docs", "build:docs": "./node_modules/.bin/dts-bundle-generator ./dist/halo2lib/functions.d.ts -o src/shared/build.d.ts && node ./scripts/convertDTs.js && rm -rf ./src/shared/build.d.ts", "test:vk": "./tests/test_vk.sh", - "test:constant": "./tests/test_constant.sh" + "test:constant": "./tests/test_constant.sh" }, "keywords": [ "axiom", @@ -32,7 +32,7 @@ "typescript": "^5.2.2" }, "dependencies": { - "@axiom-crypto/halo2-wasm": "0.2.11-rc.1", + "@axiom-crypto/halo2-wasm": "0.2.12-alpha.0", "ethers": "^6.8.0", "prettier": "1.18.2" }, diff --git a/halo2-wasm/js/kzg/index.ts b/halo2-wasm/js/kzg/index.ts index e578888..53c947d 100644 --- a/halo2-wasm/js/kzg/index.ts +++ b/halo2-wasm/js/kzg/index.ts @@ -1,28 +1,36 @@ +import * as os from "os"; +import * as path from "path"; +import * as fs from "fs"; + function fetchAndConvertToUint8Array(url: string): Promise { return new Promise((resolve, reject) => { // Check if running in Node.js environment - if (typeof process !== 'undefined' && process.versions && process.versions.node) { - const https = require('https'); + if ( + typeof process !== "undefined" && + process.versions && + process.versions.node + ) { + const https = require("https"); https.get(url, (res: any) => { let chunks: any[] = []; - res.on('data', (chunk: any) => chunks.push(chunk)); - res.on('end', () => { + res.on("data", (chunk: any) => chunks.push(chunk)); + res.on("end", () => { let binaryData = Buffer.concat(chunks); resolve(new Uint8Array(binaryData)); }); - res.on('error', reject); + res.on("error", reject); }); } // Check if running in browser or web worker environment - else if (typeof window !== 'undefined' || typeof self !== 'undefined') { + else if (typeof window !== "undefined" || typeof self !== "undefined") { fetch(url) - .then(response => response.arrayBuffer()) - .then(buffer => { + .then((response) => response.arrayBuffer()) + .then((buffer) => { resolve(new Uint8Array(buffer)); }) .catch(reject); } else { - reject(new Error('Environment not supported')); + reject(new Error("Environment not supported")); } }); } @@ -34,11 +42,33 @@ const convertBase64ToUint8Arr = (b64str: string) => { buf[i] = ch.charCodeAt(0); }); return buf; -} +}; export const getKzgParams = async (k: number): Promise => { + const home = os.homedir(); + const axiomSrsPath = path.join( + home, + ".axiom", + "srs", + "challenge_0085", + `kzg_bn254_${k}.srs` + ); + const exists = fs.existsSync(axiomSrsPath); + if (exists) { + const buffer = fs.readFileSync(axiomSrsPath); + return new Uint8Array(buffer); + } + const folderPath = path.dirname(axiomSrsPath); + if (!fs.existsSync(folderPath)) { + fs.mkdirSync(folderPath, { recursive: true }); + } if (k < 6 || k > 19) { throw new Error(`k=${k} is not supported`); } - return fetchAndConvertToUint8Array(`https://axiom-crypto.s3.amazonaws.com/challenge_0085/kzg_bn254_${k}.srs`); -}; \ No newline at end of file + const srs = await fetchAndConvertToUint8Array( + `https://axiom-crypto.s3.amazonaws.com/challenge_0085/kzg_bn254_${k}.srs` + ); + fs.writeFileSync(axiomSrsPath, srs); + + return srs; +}; diff --git a/halo2-wasm/package.json b/halo2-wasm/package.json index 476cd68..6c89608 100644 --- a/halo2-wasm/package.json +++ b/halo2-wasm/package.json @@ -1,7 +1,7 @@ { "name": "@axiom-crypto/halo2-wasm", "description": "Halo2 wasm bindings", - "version": "0.2.11-rc.1", + "version": "0.2.12-alpha.0", "main": "index.js", "types": "index.d.ts", "scripts": {