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' ;
2
10
import * as ElgamalECC from '../utils/Elgamal.js' ;
3
11
import { DynamicArray } from '../utils/DynamicArray.js' ;
4
12
import { CustomScalar } from '../utils/CustomScalar.js' ;
@@ -35,16 +43,40 @@ type Round2Data = {
35
43
36
44
class Round1Contribution extends Struct ( {
37
45
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
+ }
39
55
40
56
class Round2Contribution extends Struct ( {
41
57
c : ScalarDynamicArray ,
42
58
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
+ }
44
68
45
69
class TallyContribution extends Struct ( {
46
70
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
+ }
48
80
49
81
function calculatePublicKey (
50
82
round1Contributions : Round1Contribution [ ]
@@ -80,7 +112,7 @@ function generateRandomPolynomial(T: number, N: number): SecretPolynomial {
80
112
81
113
function getRound1Contribution ( secret : SecretPolynomial ) : Round1Contribution {
82
114
let provableC = GroupDynamicArray . from ( secret . C ) ;
83
- return { C : provableC } ;
115
+ return new Round1Contribution ( { C : provableC } ) ;
84
116
}
85
117
86
118
function getRound2Contribution (
@@ -108,7 +140,7 @@ function getRound2Contribution(
108
140
c . map ( ( e ) => CustomScalar . fromScalar ( e ) )
109
141
) ;
110
142
let provableU = GroupDynamicArray . from ( U ) ;
111
- return { c : provablec , U : provableU } ;
143
+ return new Round2Contribution ( { c : provablec , U : provableU } ) ;
112
144
}
113
145
114
146
function getTallyContribution (
@@ -135,7 +167,7 @@ function getTallyContribution(
135
167
for ( let i = 0 ; i < R . length ; i ++ ) {
136
168
D [ i ] = R [ i ] . scale ( ski ) ;
137
169
}
138
- return { D : GroupDynamicArray . from ( D ) } ;
170
+ return new TallyContribution ( { D : GroupDynamicArray . from ( D ) } ) ;
139
171
}
140
172
141
173
function getLagrangeCoefficient ( listIndex : number [ ] ) : Scalar [ ] {
0 commit comments