Skip to content

Commit 00f3b41

Browse files
committed
Add tests for CommitteeMember
1 parent fde4218 commit 00f3b41

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

src/CommitteeMember.test.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,80 @@
1-
import { CommitteeMember } from './CommitteeMember';
1+
import { Field, Group, PrivateKey, PublicKey } from 'o1js';
2+
import {
3+
CommitteeMember,
4+
Round1Contribution,
5+
Round2Contribution,
6+
SecretPolynomial,
7+
getMerkleWitnessType,
8+
} from './CommitteeMember';
9+
import { emptyWitness } from 'o1js/dist/node/lib/proof_system';
210

311
describe('CommitteeMember', () => {
4-
let committeeMember: CommitteeMember;
5-
it('1', async () => {
12+
let T = 3;
13+
let N = 5;
14+
let keyId = Field(0);
15+
let committees: {
16+
privateKey: PrivateKey;
17+
committeeMember: CommitteeMember;
18+
secretPolynomial: SecretPolynomial;
19+
round1Contribution: Round1Contribution | any;
20+
round2Contribution: Round2Contribution | any;
21+
}[] = [];
22+
let round1Contributions: Round1Contribution[] = [];
23+
let publicKey: PublicKey;
24+
let w = {
25+
isLeft: false,
26+
sibling: Field(0),
27+
};
28+
let dummyWitness = Array.from(Array(10).keys()).map(() => w);
29+
beforeAll(async () => {
30+
for (let i = 0; i < N; i++) {
31+
let privateKey = PrivateKey.random();
32+
let committeeMember = new CommitteeMember({
33+
publicKey: privateKey.toPublicKey(),
34+
index: i + 1,
35+
T: T,
36+
N: N,
37+
witness: new (getMerkleWitnessType(10))(dummyWitness),
38+
});
39+
let secretPolynomial = committeeMember.getRandomPolynomial();
40+
let round1Contribution = committeeMember.getRound1Contribution(
41+
secretPolynomial,
42+
keyId
43+
);
44+
round1Contributions.push(round1Contribution);
45+
committees.push({
46+
privateKey: privateKey,
47+
committeeMember: committeeMember,
48+
secretPolynomial: secretPolynomial,
49+
round1Contribution: round1Contribution,
50+
round2Contribution: null,
51+
});
52+
}
53+
54+
publicKey = CommitteeMember.getPublicKey(round1Contributions);
55+
console.log(publicKey.x.toBigInt());
56+
console.log(publicKey.toJSON());
57+
});
58+
it('Test Key Generation', async () => {
659
let m = 1;
60+
// for (let i = 0; i < N; i++) {
61+
// let senderIndex = i + 1;
62+
// let publicKeys: Group[] = [];
63+
// for (let j = 0; j < N; j++) {
64+
// let recipientIndex = j + 1;
65+
// if (senderIndex != recipientIndex) {
66+
// publicKeys.push(
67+
// committees[j].privateKey.toPublicKey().toGroup()
68+
// );
69+
// }
70+
// }
71+
// let round2Contribution = committees[
72+
// i
73+
// ].committeeMember.getRound2Contribution(
74+
// committees[i].secretPolynomial,
75+
// publicKeys,
76+
// keyId
77+
// );
78+
// }
779
});
880
});

src/CommitteeMember.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ROUND_1_CONTRIBUTION_DEPTH = 10;
1919
const ROUND_2_CONTRIBUTION_DEPTH = 10;
2020
const TALLY_CONTRIBUTION_DEPTH = 10;
2121

22-
function getMerkleWitnessType(depth: number) {
22+
export function getMerkleWitnessType(depth: number) {
2323
return MerkleWitness(depth);
2424
}
2525

@@ -114,7 +114,7 @@ export class CommitteeMember extends Struct({
114114
let C = new Array<Group>(this.T);
115115
for (let i = 0; i < this.T; i++) {
116116
a[i] = Field.random();
117-
C[i] = Group.generator.scale(Scalar.fromFields([a[i]]));
117+
C[i] = Group.generator.scale(Scalar.fromBits(a[i].toBits(255)));
118118
}
119119
let f = new Array<Field>(this.N);
120120
for (let i = 0; i < this.N; i++) {

0 commit comments

Comments
 (0)