@@ -8,7 +8,68 @@ import { getBlobs } from '../src/blobs.ts'
8
8
9
9
import type { KZG } from '../src/kzg.ts'
10
10
11
+ import * as ckzg from 'c-kzg'
12
+ import { bytesToHex , hexToBytes } from '../src/bytes.ts'
13
+
11
14
export const jsKZG = new microEthKZG ( trustedSetup )
15
+ const cKzg = {
16
+ blobToKzgCommitment : ( blob : string ) => {
17
+ const blobBytes = hexToBytes ( blob )
18
+ const commitmentBytes = ckzg . blobToKzgCommitment ( blobBytes )
19
+ return bytesToHex ( commitmentBytes )
20
+ } ,
21
+ computeBlobProof : ( blob : string , commitment : string ) => {
22
+ const blobBytes = hexToBytes ( blob )
23
+ const commitmentBytes = hexToBytes ( commitment )
24
+ const proofBytes = ckzg . computeBlobKzgProof ( blobBytes , commitmentBytes )
25
+ return bytesToHex ( proofBytes )
26
+ } ,
27
+ verifyProof : ( commitment : string , z : string , y : string , proof : string ) => {
28
+ const commitmentBytes = hexToBytes ( commitment )
29
+ const zBytes = hexToBytes ( z )
30
+ const yBytes = hexToBytes ( y )
31
+ const proofBytes = hexToBytes ( proof )
32
+ return ckzg . verifyKzgProof ( commitmentBytes , zBytes , yBytes , proofBytes )
33
+ } ,
34
+ verifyBlobProofBatch : ( blobs : string [ ] , commitments : string [ ] , proofs : string [ ] ) => {
35
+ const blobsBytes = blobs . map ( ( blb ) => hexToBytes ( blb ) )
36
+ const commitmentsBytes = commitments . map ( ( cmt ) => hexToBytes ( cmt ) )
37
+ const proofsBytes = proofs . map ( ( prf ) => hexToBytes ( prf ) )
38
+ return ckzg . verifyBlobKzgProofBatch ( blobsBytes , commitmentsBytes , proofsBytes )
39
+ } ,
40
+ computeCells : ( blob : string ) => {
41
+ const blobBytes = hexToBytes ( blob )
42
+ const cellsBytes = ckzg . computeCells ( blobBytes )
43
+ return cellsBytes . map ( ( cellBytes ) => bytesToHex ( cellBytes ) )
44
+ } ,
45
+ computeCellsAndProofs : ( blob : string ) => {
46
+ const blobBytes = hexToBytes ( blob )
47
+ const [ cellsBytes , proofsBytes ] = ckzg . computeCellsAndKzgProofs ( blobBytes )
48
+ return [
49
+ cellsBytes . map ( ( cellBytes ) => bytesToHex ( cellBytes ) ) ,
50
+ proofsBytes . map ( ( prfBytes ) => bytesToHex ( prfBytes ) ) ,
51
+ ] as [ string [ ] , string [ ] ]
52
+ } ,
53
+ recoverCellsAndProofs : ( indices : number [ ] , cells : string [ ] ) => {
54
+ const cellsBytes = cells . map ( ( cell ) => hexToBytes ( cell ) )
55
+ const [ allCellsBytes , allProofsBytes ] = ckzg . recoverCellsAndKzgProofs ( indices , cellsBytes )
56
+ return [
57
+ allCellsBytes . map ( ( cellBytes ) => bytesToHex ( cellBytes ) ) ,
58
+ allProofsBytes . map ( ( prfBytes ) => bytesToHex ( prfBytes ) ) ,
59
+ ] as [ string [ ] , string [ ] ]
60
+ } ,
61
+ verifyCellKzgProofBatch : (
62
+ commitments : string [ ] ,
63
+ indices : number [ ] ,
64
+ cells : string [ ] ,
65
+ proofs : string [ ] ,
66
+ ) => {
67
+ const commitmentsBytes = commitments . map ( ( commit ) => hexToBytes ( commit ) )
68
+ const cellsBytes = cells . map ( ( cell ) => hexToBytes ( cell ) )
69
+ const proofsBytes = proofs . map ( ( prf ) => hexToBytes ( prf ) )
70
+ return ckzg . verifyCellKzgProofBatch ( commitmentsBytes , indices , cellsBytes , proofsBytes )
71
+ } ,
72
+ }
12
73
13
74
describe ( 'KZG API tests' , ( ) => {
14
75
let wasm : Awaited < ReturnType < typeof loadKZG > >
@@ -43,6 +104,9 @@ describe('KZG API tests', () => {
43
104
const commit = wasmKZG . blobToKzgCommitment ( blob )
44
105
const proof = wasmKZG . computeBlobProof ( blob , commit )
45
106
107
+ console . log ( jsKZG . blobToKzgCommitment ( blob ) . toLowerCase ( ) )
108
+ console . log ( cKzg . blobToKzgCommitment ( blob ) . toLowerCase ( ) )
109
+
46
110
assert . equal (
47
111
wasmKZG . blobToKzgCommitment ( blob ) . toLowerCase ( ) ,
48
112
jsKZG . blobToKzgCommitment ( blob ) . toLowerCase ( ) ,
0 commit comments