-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.test.ts
More file actions
46 lines (34 loc) · 1.33 KB
/
lib.test.ts
File metadata and controls
46 lines (34 loc) · 1.33 KB
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
42
43
44
45
46
import { beforeAll, describe, expect, it } from 'vitest';
import { BoundedVec, Prover, Str, U8, toJSON } from '@zkpersona/noir-helpers';
import circuit from '../target/hmac_sha256_example.json' assert {
type: 'json',
};
import type { CompiledCircuit } from '@noir-lang/noir_js';
const keyBytes = new Str('secret').asBytes();
const key = new BoundedVec(keyBytes.length, () => new U8(0));
key.extendFromArray(keyBytes);
const messageBytes = new Str('hello_world').asBytes();
const message = new BoundedVec(messageBytes.length, () => new U8(0));
message.extendFromArray(messageBytes);
const inputs = {
key,
message,
};
describe('Circuit Proof Verification', () => {
let prover: Prover;
beforeAll(() => {
prover = new Prover(circuit as CompiledCircuit, { type: 'all' });
});
it('should prove using honk backend', async () => {
const parsedInputs = toJSON(inputs);
const proof = await prover.fullProve(parsedInputs, { type: 'honk' });
const isVerified = await prover.verify(proof, { type: 'honk' });
expect(isVerified).toBe(true);
});
it('should prove using plonk backend', async () => {
const parsedInputs = toJSON(inputs);
const proof = await prover.fullProve(parsedInputs, { type: 'plonk' });
const isVerified = await prover.verify(proof, { type: 'plonk' });
expect(isVerified).toBe(true);
});
});