forked from ethereumjs/ethereumjs-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkzg.ts
41 lines (38 loc) · 1.16 KB
/
kzg.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Interface for an externally provided kzg library used when creating blob transactions
*/
export interface Kzg {
loadTrustedSetup(filePath?: string): void
blobToKzgCommitment(blob: Uint8Array): Uint8Array
computeBlobKzgProof(blob: Uint8Array, commitment: Uint8Array): Uint8Array
verifyKzgProof(
polynomialKzg: Uint8Array,
z: Uint8Array,
y: Uint8Array,
kzgProof: Uint8Array
): boolean
verifyBlobKzgProofBatch(
blobs: Uint8Array[],
expectedKzgCommitments: Uint8Array[],
kzgProofs: Uint8Array[]
): boolean
}
function kzgNotLoaded(): never {
throw Error('kzg library not loaded')
}
// eslint-disable-next-line import/no-mutable-exports
export let kzg: Kzg = {
loadTrustedSetup: kzgNotLoaded,
blobToKzgCommitment: kzgNotLoaded,
computeBlobKzgProof: kzgNotLoaded,
verifyKzgProof: kzgNotLoaded,
verifyBlobKzgProofBatch: kzgNotLoaded,
}
/**
* @param kzgLib a KZG implementation (defaults to c-kzg)
* @param trustedSetupPath the full path (e.g. "/home/linux/devnet4.txt") to a kzg trusted setup text file
*/
export function initKZG(kzgLib: Kzg, trustedSetupPath?: string) {
kzg = kzgLib
kzg.loadTrustedSetup(trustedSetupPath)
}