@axiom-crypto/halo2-wasm
Version:
Halo2 wasm bindings
138 lines (137 loc) • 8.43 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CircuitScaffold = exports.getHalo2LibWasm = exports.getHalo2Wasm = exports.Secp256k1AffinePoint = exports.JsCircuitValue256 = exports.JsCircuitSecp256k1Affine = exports.JsCircuitBn254G2Affine = exports.JsCircuitBn254G1Affine = exports.JsCircuitBn254Fq2 = exports.Bn254G2AffinePoint = exports.Bn254G1AffinePoint = exports.Bn254FqPoint = exports.getKzgParams = exports.Halo2LibWasm = exports.Halo2Wasm = exports.DEFAULT_CIRCUIT_CONFIG = void 0;
var halo2_wasm_1 = require("./halo2_wasm");
Object.defineProperty(exports, "Halo2Wasm", { enumerable: true, get: function () { return halo2_wasm_1.Halo2Wasm; } });
Object.defineProperty(exports, "Halo2LibWasm", { enumerable: true, get: function () { return halo2_wasm_1.Halo2LibWasm; } });
Object.defineProperty(exports, "Bn254FqPoint", { enumerable: true, get: function () { return halo2_wasm_1.Bn254FqPoint; } });
Object.defineProperty(exports, "Bn254G1AffinePoint", { enumerable: true, get: function () { return halo2_wasm_1.Bn254G1AffinePoint; } });
Object.defineProperty(exports, "Bn254G2AffinePoint", { enumerable: true, get: function () { return halo2_wasm_1.Bn254G2AffinePoint; } });
Object.defineProperty(exports, "JsCircuitBn254Fq2", { enumerable: true, get: function () { return halo2_wasm_1.JsCircuitBn254Fq2; } });
Object.defineProperty(exports, "JsCircuitBn254G1Affine", { enumerable: true, get: function () { return halo2_wasm_1.JsCircuitBn254G1Affine; } });
Object.defineProperty(exports, "JsCircuitBn254G2Affine", { enumerable: true, get: function () { return halo2_wasm_1.JsCircuitBn254G2Affine; } });
Object.defineProperty(exports, "JsCircuitSecp256k1Affine", { enumerable: true, get: function () { return halo2_wasm_1.JsCircuitSecp256k1Affine; } });
Object.defineProperty(exports, "JsCircuitValue256", { enumerable: true, get: function () { return halo2_wasm_1.JsCircuitValue256; } });
Object.defineProperty(exports, "Secp256k1AffinePoint", { enumerable: true, get: function () { return halo2_wasm_1.Secp256k1AffinePoint; } });
var kzg_1 = require("./kzg");
Object.defineProperty(exports, "getKzgParams", { enumerable: true, get: function () { return kzg_1.getKzgParams; } });
var shared_1 = require("../shared");
Object.defineProperty(exports, "DEFAULT_CIRCUIT_CONFIG", { enumerable: true, get: function () { return shared_1.DEFAULT_CIRCUIT_CONFIG; } });
var scaffold_1 = require("../shared/scaffold");
var getHalo2Wasm = function (numThreads) { return __awaiter(void 0, void 0, void 0, function () {
var halo2wasm;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, halo2_wasm_1.default)()];
case 1:
_a.sent();
(0, halo2_wasm_1.initPanicHook)();
if (!(numThreads !== 0)) return [3 /*break*/, 3];
return [4 /*yield*/, (0, halo2_wasm_1.initThreadPool)(numThreads)];
case 2:
_a.sent();
_a.label = 3;
case 3:
halo2wasm = new halo2_wasm_1.Halo2Wasm();
return [2 /*return*/, halo2wasm];
}
});
}); };
exports.getHalo2Wasm = getHalo2Wasm;
var getHalo2LibWasm = function (halo2wasm) {
var halo2libwasm = new halo2_wasm_1.Halo2LibWasm(halo2wasm);
return halo2libwasm;
};
exports.getHalo2LibWasm = getHalo2LibWasm;
var CircuitScaffold = /** @class */ (function (_super) {
__extends(CircuitScaffold, _super);
function CircuitScaffold(options) {
var _a, _b;
var _this = _super.call(this) || this;
_this.config = (_a = options === null || options === void 0 ? void 0 : options.config) !== null && _a !== void 0 ? _a : __assign({}, shared_1.DEFAULT_CIRCUIT_CONFIG);
_this.shouldTime = (_b = options === null || options === void 0 ? void 0 : options.shouldTime) !== null && _b !== void 0 ? _b : false;
_this.loadedVk = false;
_this.setContext({ getKzgParams: kzg_1.getKzgParams });
return _this;
}
CircuitScaffold.prototype.setup = function (numThreads) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this;
return [4 /*yield*/, (0, exports.getHalo2Wasm)(numThreads)];
case 1:
_a.halo2wasm = _b.sent();
this.halo2wasm.config(this.config);
return [2 /*return*/];
}
});
});
};
return CircuitScaffold;
}(scaffold_1.BaseCircuitScaffold));
exports.CircuitScaffold = CircuitScaffold;