c-kzg-4844/bindings/node.js/kzg.ts

60 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-11-02 20:45:29 +00:00
// @ts-expect-error
import bindings from 'bindings';
2022-11-03 19:57:46 +00:00
export const BLOB_SIZE = 4096;
export const NUMBER_OF_FIELDS = 32;
// Consider making this internal state of the native code
// so we don't have to pass it around in the application layer
export type SetupHandle = Object;
export enum ReturnValue {
/** Success! */
OK = 0,
/** The supplied data is invalid in some way */
BADARGS,
/** Internal error - this should never occur and may indicate a bug in the library */
ERROR,
/** Could not allocate memory */
MALLOC,
}
export type Point = Uint8Array;
export type KZGProof = Uint8Array;
export type KZGCommitment = Uint8Array;
2022-11-03 00:17:17 +00:00
export type Blob = Uint8Array;
export type Blobs = Blob[];
type KZG = {
loadTrustedSetup: (path: string) => SetupHandle;
2022-11-03 19:57:46 +00:00
freeTrustedSetup: (setupHandle: SetupHandle) => void;
2022-11-03 19:57:46 +00:00
2022-11-03 00:17:17 +00:00
blobToKzgCommitment: (blob: Blob, setupHandle: SetupHandle) => KZGCommitment;
2022-11-03 19:57:46 +00:00
verifyAggregateKzgProof: (blobs: Blobs) => ReturnValue;
2022-11-03 19:57:46 +00:00
computeAggregateKzgProof: (
blobs: Blobs,
setupHandle: SetupHandle,
) => KZGProof;
2022-11-03 19:57:46 +00:00
verifyKzgProof: (
commitment: KZGCommitment,
x: Point,
y: Point,
proof: KZGProof,
setupHandle: SetupHandle,
) => ReturnValue;
};
const kzg: KZG = bindings('kzg.node');
export const loadTrustedSetup = kzg.loadTrustedSetup;
export const freeTrustedSetup = kzg.freeTrustedSetup;
export const blobToKzgCommitment = kzg.blobToKzgCommitment;
export const verifyAggregateKzgProof = kzg.verifyAggregateKzgProof;
export const computeAggregateKzgProof = kzg.computeAggregateKzgProof;
export const verifyKzgProof = kzg.verifyKzgProof;
2022-11-02 20:45:29 +00:00
export default kzg;