@@ -2,6 +2,7 @@ import { hexToBytes } from './util.js'
22import { loadWasmModule } from './loader.cjs'
33import kzgWasm from './kzg.js'
44import mainnetTrustedSetup from './trustedSetup.js'
5+
56export type TrustedSetup = {
67 g1_monomial : string
78 g1_lagrange : string
@@ -28,7 +29,7 @@ const BYTES_PER_CELL = 2048
2829 *
2930 * @returns object - the KZG methods required for all 4844 related operations
3031 */
31- export const loadKZG = async ( trustedSetup : TrustedSetup = mainnetTrustedSetup ) => {
32+ export const loadKZG = async ( trustedSetup : TrustedSetup = mainnetTrustedSetup , precompute : number = 8 ) => {
3233 // In Node.js environment, preload the WASM binary to avoid path resolution issues
3334 let wasmBinary = await loadWasmModule ( ) ;
3435
@@ -84,7 +85,7 @@ export const loadKZG = async (trustedSetup: TrustedSetup = mainnetTrustedSetup)
8485 return '0x' + result ;
8586 }
8687
87- const blobToKzgCommitment = blobToKZGCommitment // Alias with different casing for ethereumjs compatibility
88+
8889
8990 /**
9091 *
@@ -100,7 +101,7 @@ export const loadKZG = async (trustedSetup: TrustedSetup = mainnetTrustedSetup)
100101 return '0x' + result ;
101102 }
102103
103- const computeBlobProof = computeBlobKZGProof // Alias with different casing for ethereumjs compatibility
104+
104105 /**
105106 *
106107 * @param blobs - an array of blobs
@@ -292,10 +293,44 @@ export const loadKZG = async (trustedSetup: TrustedSetup = mainnetTrustedSetup)
292293 return res === 'true'
293294 }
294295
296+ const loadResult = loadTrustedSetup ( trustedSetup , precompute ) ;
297+ if ( loadResult !== 0 ) {
298+ throw new Error ( `Failed to load trusted setup, error code: ${ loadResult } ` ) ;
299+ }
300+
301+
302+ // ALIASING
303+ const computeBlobProof = computeBlobKZGProof // Alias with different casing for ethereumjs compatibility
304+ const blobToKzgCommitment = blobToKZGCommitment // Alias with different casing for ethereumjs compatibility
305+ const verifyProof = verifyKZGProof // Alias with different casing for ethereumjs compatibility
306+
307+ const verifyCellKzgProofBatch = ( commitments : string [ ] , cellIndices : number [ ] , cells : string [ ] , proofs : string [ ] ) => {
308+ return verifyCellKZGProofBatch ( commitments , cellIndices , cells , proofs , cells . length )
309+ }
310+
311+ const recoverCellsAndProofs = ( indices : number [ ] , cells : string [ ] ) : [ string [ ] , string [ ] ] => {
312+ const result = recoverCellsFromKZGProofs ( indices , cells , cells . length ) ;
313+ return [ result . cells , result . proofs ] ;
314+ }
315+
316+ const computeCells = ( blob : string ) : string [ ] => {
317+ const result = computeCellsAndKZGProofs ( blob ) ;
318+ return result . cells ;
319+ }
320+
321+ const computeCellsAndProofs = ( blob : string ) : [ string [ ] , string [ ] ] => {
322+ const result = computeCellsAndKZGProofs ( blob ) ;
323+ return [ result . cells , result . proofs ] ;
324+ }
325+
326+ const verifyBlobProofBatch = verifyBlobKZGProofBatch
295327
296328 return {
297329 loadTrustedSetup, freeTrustedSetup, blobToKZGCommitment, computeBlobKZGProof, verifyBlobKZGProofBatch, verifyKZGProof, verifyBlobKZGProof,
298- computeCellsAndKZGProofs, recoverCellsFromKZGProofs, verifyCellKZGProof, verifyCellKZGProofBatch, blobToKzgCommitment, computeBlobProof
330+ computeCellsAndKZGProofs, recoverCellsFromKZGProofs, verifyCellKZGProof, verifyCellKZGProofBatch,
331+ // ALIASED/KZGJS COMPATIBILITY METHODS
332+ verifyCellKzgProofBatch, recoverCellsAndProofs, computeCells, computeCellsAndProofs, verifyBlobProofBatch,
333+ computeBlobProof, blobToKzgCommitment, verifyProof
299334 }
300335}
301336
0 commit comments