45 lines
1.6 KiB
JavaScript
Raw Normal View History

'use strict';
/**
* The public interface of this module exposes the functions as specified by
* https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md#kzg
*/
const kzg = require("./kzg.node");
const FIELD_ELEMENTS_PER_BLOB = kzg.FIELD_ELEMENTS_PER_BLOB;
2022-11-04 12:06:06 -07:00
const BYTES_PER_FIELD_ELEMENT = kzg.BYTES_PER_FIELD_ELEMENT;
// Stored as internal state
let setupHandle;
2022-11-04 13:29:52 -07:00
function requireSetupHandle() {
if (!setupHandle) {
throw new Error("You must call loadTrustedSetup to initialize KZG.");
}
return setupHandle;
}
function loadTrustedSetup(filePath) {
if (setupHandle) {
throw new Error("Call freeTrustedSetup before loading a new trusted setup.");
}
setupHandle = kzg.loadTrustedSetup(filePath);
}
function freeTrustedSetup() {
2022-11-04 13:29:52 -07:00
kzg.freeTrustedSetup(requireSetupHandle());
setupHandle = undefined;
}
function blobToKzgCommitment(blob) {
2022-11-04 13:29:52 -07:00
return kzg.blobToKzgCommitment(blob, requireSetupHandle());
}
function computeAggregateKzgProof(blobs) {
2022-11-04 13:29:52 -07:00
return kzg.computeAggregateKzgProof(blobs, requireSetupHandle());
}
function verifyAggregateKzgProof(blobs, expectedKzgCommitments, kzgAggregatedProof) {
2022-11-04 13:29:52 -07:00
return kzg.verifyAggregateKzgProof(blobs, expectedKzgCommitments, kzgAggregatedProof, requireSetupHandle());
}
2022-11-04 12:06:06 -07:00
exports.BYTES_PER_FIELD_ELEMENT = BYTES_PER_FIELD_ELEMENT;
exports.FIELD_ELEMENTS_PER_BLOB = FIELD_ELEMENTS_PER_BLOB;
exports.blobToKzgCommitment = blobToKzgCommitment;
exports.computeAggregateKzgProof = computeAggregateKzgProof;
exports.freeTrustedSetup = freeTrustedSetup;
exports.loadTrustedSetup = loadTrustedSetup;
exports.verifyAggregateKzgProof = verifyAggregateKzgProof;