2022-11-02 22:50:04 +00:00
|
|
|
import {
|
|
|
|
loadTrustedSetup,
|
|
|
|
freeTrustedSetup,
|
|
|
|
verifyKzgProof,
|
2022-11-03 00:17:17 +00:00
|
|
|
blobToKzgCommitment,
|
2022-11-02 22:50:04 +00:00
|
|
|
ReturnValue,
|
|
|
|
SetupHandle,
|
2022-11-03 00:17:17 +00:00
|
|
|
Blob,
|
|
|
|
BLOB_SIZE,
|
|
|
|
NUMBER_OF_FIELDS,
|
2022-11-02 22:50:04 +00:00
|
|
|
} from './kzg';
|
2022-11-02 20:45:29 +00:00
|
|
|
|
2022-11-03 00:17:17 +00:00
|
|
|
import { randomBytes } from 'crypto';
|
|
|
|
|
|
|
|
function generateRandomBlob(): Blob {
|
|
|
|
return new Uint8Array(randomBytes(NUMBER_OF_FIELDS * BLOB_SIZE));
|
|
|
|
}
|
|
|
|
|
2022-11-02 20:45:29 +00:00
|
|
|
describe('C-KZG', () => {
|
2022-11-02 22:50:04 +00:00
|
|
|
let setupHandle: SetupHandle;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
setupHandle = loadTrustedSetup('../../src/trusted_setup.txt');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setup', () => {
|
2022-11-02 20:45:29 +00:00
|
|
|
it('can both load and free', () => {
|
2022-11-02 22:50:04 +00:00
|
|
|
expect(freeTrustedSetup(setupHandle)).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('computing a KZG commitment from a blob', () => {
|
2022-11-03 00:17:17 +00:00
|
|
|
it.only('returns data with the correct length', () => {
|
|
|
|
const blob = generateRandomBlob();
|
|
|
|
const commitment = blobToKzgCommitment(blob, setupHandle);
|
|
|
|
expect(commitment.length).toBe(48);
|
2022-11-02 22:50:04 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('verifying a KZG proof', () => {
|
2022-11-03 00:17:17 +00:00
|
|
|
it.skip('returns the expected value', () => {
|
2022-11-02 22:50:04 +00:00
|
|
|
const byteEncoder = new TextEncoder();
|
|
|
|
|
|
|
|
const commitment = byteEncoder.encode(
|
|
|
|
'b91c022acf7bd3b63be69a4c19b781ea7a3d5df1cd66ceb7dd0f399610f0ee04695dace82e04bfb83af2b17d7319f87f',
|
2022-11-02 20:45:29 +00:00
|
|
|
);
|
2022-11-02 22:50:04 +00:00
|
|
|
console.log({ commitment });
|
|
|
|
const x = byteEncoder.encode(
|
|
|
|
'0345f802a75a6c0d9cc5b8a1e71642b8fa80b0a78938edc6da1e591149578d1a',
|
|
|
|
);
|
|
|
|
const y = byteEncoder.encode(
|
|
|
|
'3b17cab634c3795d311380f3bc93ce8e768efc0e2b9e79496cfc8f351594b472',
|
|
|
|
);
|
|
|
|
const proof = byteEncoder.encode(
|
|
|
|
'a5ddd6da04c47a9cd4628beb8d55ebd2e930a64dfa29f876ebf393cfd6574d48a3ce96ac5a2af4a4f9ec9caa47d304d3',
|
|
|
|
);
|
|
|
|
|
|
|
|
const result = verifyKzgProof(commitment, y, x, proof, setupHandle);
|
|
|
|
console.log({ result });
|
|
|
|
expect(result).toBe(ReturnValue.OK);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('computing an aggregate KZG proof', () => {
|
|
|
|
it('returns the expected value', () => {
|
|
|
|
expect(true).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('verifying an aggregate KZG proof', () => {
|
|
|
|
it('returns the expected value', () => {
|
|
|
|
expect(true).toBe(false);
|
2022-11-02 20:45:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|