2023-03-30 00:32:06 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
export type Bytes32 = Uint8Array; // 32 bytes
|
|
|
|
export type Bytes48 = Uint8Array; // 48 bytes
|
2023-04-07 13:06:13 +00:00
|
|
|
export type KZGProof = Uint8Array; // 48 bytes
|
|
|
|
export type KZGCommitment = Uint8Array; // 48 bytes
|
2023-03-30 00:32:06 +00:00
|
|
|
export type Blob = Uint8Array; // 4096 * 32 bytes
|
|
|
|
export type ProofResult = [KZGProof, Bytes32];
|
|
|
|
export interface TrustedSetupJson {
|
|
|
|
setup_G1: string[];
|
|
|
|
setup_G2: string[];
|
|
|
|
setup_G1_lagrange: string[];
|
|
|
|
roots_of_unity: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export const BYTES_PER_BLOB: number;
|
|
|
|
export const BYTES_PER_COMMITMENT: number;
|
|
|
|
export const BYTES_PER_FIELD_ELEMENT: number;
|
|
|
|
export const BYTES_PER_PROOF: number;
|
|
|
|
export const FIELD_ELEMENTS_PER_BLOB: number;
|
|
|
|
|
|
|
|
/**
|
2024-04-30 16:38:48 +00:00
|
|
|
* Initialize the library with a trusted setup file.
|
2023-03-30 00:32:06 +00:00
|
|
|
*
|
2024-04-30 16:38:48 +00:00
|
|
|
* Can pass either a .txt or a .json file with setup configuration. Converts
|
|
|
|
* JSON formatted trusted setup into the native format that the base library
|
|
|
|
* requires. The created file will be in the same as the origin file but with a
|
|
|
|
* ".txt" extension.
|
|
|
|
*
|
|
|
|
* Uses user provided location first. If one is not provided then defaults to
|
|
|
|
* the official Ethereum mainnet setup from the KZG ceremony. Should only be
|
|
|
|
* used for cases where the Ethereum official mainnet KZG setup is acceptable.
|
|
|
|
*
|
|
|
|
* @param {string | undefined} filePath
|
|
|
|
* @default - If no string is passed the default trusted setup from the Ethereum KZG ceremony is used
|
2023-03-30 00:32:06 +00:00
|
|
|
*
|
|
|
|
* @throws {TypeError} - Non-String input
|
|
|
|
* @throws {Error} - For all other errors. See error message for more info
|
|
|
|
*/
|
2024-04-30 16:38:48 +00:00
|
|
|
export function loadTrustedSetup(filePath?: string): void;
|
2023-03-30 00:32:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a blob to a KZG commitment.
|
|
|
|
*
|
|
|
|
* @param {Blob} blob - The blob representing the polynomial to be committed to
|
|
|
|
*
|
|
|
|
* @return {KZGCommitment} - The resulting commitment
|
|
|
|
*
|
|
|
|
* @throws {TypeError} - For invalid arguments or failure of the native library
|
|
|
|
*/
|
|
|
|
export function blobToKzgCommitment(blob: Blob): KZGCommitment;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute KZG proof for polynomial in Lagrange form at position z.
|
|
|
|
*
|
|
|
|
* @param {Blob} blob - The blob (polynomial) to generate a proof for
|
|
|
|
* @param {Bytes32} zBytes - The generator z-value for the evaluation points
|
|
|
|
*
|
|
|
|
* @return {ProofResult} - Tuple containing the resulting proof and evaluation
|
|
|
|
* of the polynomial at the evaluation point z
|
|
|
|
*
|
|
|
|
* @throws {TypeError} - For invalid arguments or failure of the native library
|
|
|
|
*/
|
|
|
|
export function computeKzgProof(blob: Blob, zBytes: Bytes32): ProofResult;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a blob, return the KZG proof that is used to verify it against the
|
|
|
|
* commitment.
|
|
|
|
*
|
|
|
|
* @param {Blob} blob - The blob (polynomial) to generate a proof for
|
|
|
|
* @param {Bytes48} commitmentBytes - Commitment to verify
|
|
|
|
*
|
|
|
|
* @return {KZGProof} - The resulting proof
|
|
|
|
*
|
|
|
|
* @throws {TypeError} - For invalid arguments or failure of the native library
|
|
|
|
*/
|
2023-03-31 08:46:54 +00:00
|
|
|
export function computeBlobKzgProof(blob: Blob, commitmentBytes: Bytes48): KZGProof;
|
2023-03-30 00:32:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify a KZG poof claiming that `p(z) == y`.
|
|
|
|
*
|
|
|
|
* @param {Bytes48} commitmentBytes - The serialized commitment corresponding to polynomial p(x)
|
|
|
|
* @param {Bytes32} zBytes - The serialized evaluation point
|
|
|
|
* @param {Bytes32} yBytes - The serialized claimed evaluation result
|
|
|
|
* @param {Bytes48} proofBytes - The serialized KZG proof
|
|
|
|
*
|
|
|
|
* @return {boolean} - true/false depending on proof validity
|
|
|
|
*
|
|
|
|
* @throws {TypeError} - For invalid arguments or failure of the native library
|
|
|
|
*/
|
2024-02-22 17:55:22 +00:00
|
|
|
export function verifyKzgProof(
|
|
|
|
commitmentBytes: Bytes48,
|
|
|
|
zBytes: Bytes32,
|
|
|
|
yBytes: Bytes32,
|
|
|
|
proofBytes: Bytes48
|
|
|
|
): boolean;
|
2023-03-30 00:32:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a blob and its proof, verify that it corresponds to the provided
|
|
|
|
* commitment.
|
|
|
|
*
|
|
|
|
* @param {Blob} blob - The serialized blob to verify
|
|
|
|
* @param {Bytes48} commitmentBytes - The serialized commitment to verify
|
|
|
|
* @param {Bytes48} proofBytes - The serialized KZG proof for verification
|
|
|
|
*
|
|
|
|
* @return {boolean} - true/false depending on proof validity
|
|
|
|
*
|
|
|
|
* @throws {TypeError} - For invalid arguments or failure of the native library
|
|
|
|
*/
|
2024-02-22 17:55:22 +00:00
|
|
|
export function verifyBlobKzgProof(blob: Blob, commitmentBytes: Bytes48, proofBytes: Bytes48): boolean;
|
2023-03-30 00:32:06 +00:00
|
|
|
|
|
|
|
/**
|
2024-02-22 17:55:22 +00:00
|
|
|
* Given an array of blobs and their proofs, verify that they correspond to their
|
2023-03-30 00:32:06 +00:00
|
|
|
* provided commitment.
|
|
|
|
*
|
|
|
|
* Note: blobs[0] relates to commitmentBytes[0] and proofBytes[0]
|
|
|
|
*
|
|
|
|
* @param {Blob} blobs - An array of serialized blobs to verify
|
2024-02-22 17:55:22 +00:00
|
|
|
* @param {Bytes48} commitmentsBytes - An array of serialized commitments to verify
|
|
|
|
* @param {Bytes48} proofsBytes - An array of serialized KZG proofs for verification
|
2023-03-30 00:32:06 +00:00
|
|
|
*
|
|
|
|
* @return {boolean} - true/false depending on batch validity
|
|
|
|
*
|
|
|
|
* @throws {TypeError} - For invalid arguments or failure of the native library
|
|
|
|
*/
|
2024-02-22 17:55:22 +00:00
|
|
|
export function verifyBlobKzgProofBatch(blobs: Blob[], commitmentsBytes: Bytes48[], proofsBytes: Bytes48[]): boolean;
|