Skip to content

Commit 6ae05b7

Browse files
Ho Nguyen PhamHo Nguyen Pham
authored andcommitted
add functions for type
1 parent ad8ea6e commit 6ae05b7

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@auxo-dev/dkg-libs",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "",
55
"author": "",
66
"license": "Apache-2.0",
@@ -51,6 +51,6 @@
5151
},
5252
"dependencies": {
5353
"big-integer": "^1.6.51",
54-
"o1js": "^0.13.1"
54+
"o1js": "0.13.*"
5555
}
5656
}

src/dkg/Committee.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Group, PrivateKey, PublicKey, Scalar, Struct } from 'o1js';
1+
import {
2+
Field,
3+
Group,
4+
Poseidon,
5+
PrivateKey,
6+
PublicKey,
7+
Scalar,
8+
Struct,
9+
} from 'o1js';
210
import * as ElgamalECC from '../utils/Elgamal.js';
311
import { DynamicArray } from '../utils/DynamicArray.js';
412
import { CustomScalar } from '../utils/CustomScalar.js';
@@ -35,16 +43,40 @@ type Round2Data = {
3543

3644
class Round1Contribution extends Struct({
3745
C: GroupDynamicArray,
38-
}) {}
46+
}) {
47+
toFields(): Field[] {
48+
return this.C.toFields();
49+
}
50+
51+
hash(): Field {
52+
return Poseidon.hash(this.toFields());
53+
}
54+
}
3955

4056
class Round2Contribution extends Struct({
4157
c: ScalarDynamicArray,
4258
U: GroupDynamicArray,
43-
}) {}
59+
}) {
60+
toFields(): Field[] {
61+
return this.c.toFields().concat(this.U.toFields());
62+
}
63+
64+
hash(): Field {
65+
return Poseidon.hash(this.toFields());
66+
}
67+
}
4468

4569
class TallyContribution extends Struct({
4670
D: GroupDynamicArray,
47-
}) {}
71+
}) {
72+
toFields(): Field[] {
73+
return this.D.toFields();
74+
}
75+
76+
hash(): Field {
77+
return Poseidon.hash(this.toFields());
78+
}
79+
}
4880

4981
function calculatePublicKey(
5082
round1Contributions: Round1Contribution[]
@@ -80,7 +112,7 @@ function generateRandomPolynomial(T: number, N: number): SecretPolynomial {
80112

81113
function getRound1Contribution(secret: SecretPolynomial): Round1Contribution {
82114
let provableC = GroupDynamicArray.from(secret.C);
83-
return { C: provableC };
115+
return new Round1Contribution({ C: provableC });
84116
}
85117

86118
function getRound2Contribution(
@@ -108,7 +140,7 @@ function getRound2Contribution(
108140
c.map((e) => CustomScalar.fromScalar(e))
109141
);
110142
let provableU = GroupDynamicArray.from(U);
111-
return { c: provablec, U: provableU };
143+
return new Round2Contribution({ c: provablec, U: provableU });
112144
}
113145

114146
function getTallyContribution(
@@ -135,7 +167,7 @@ function getTallyContribution(
135167
for (let i = 0; i < R.length; i++) {
136168
D[i] = R[i].scale(ski);
137169
}
138-
return { D: GroupDynamicArray.from(D) };
170+
return new TallyContribution({ D: GroupDynamicArray.from(D) });
139171
}
140172

141173
function getLagrangeCoefficient(listIndex: number[]): Scalar[] {

0 commit comments

Comments
 (0)