-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsetup-param.ts
More file actions
229 lines (191 loc) · 9.07 KB
/
Copy pathsetup-param.ts
File metadata and controls
229 lines (191 loc) · 9.07 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import {
generateSetupParamForBBSPlusSignatureParametersG1,
generateSetupParamForBBSSignatureParameters,
generateSetupParamForPedersenCommitmentKeyG1,
generateSetupParamForBBSPlusPublicKeyG2,
generateSetupParamForVbAccumulatorParams,
generateSetupParamForVbAccumulatorPublicKey,
generateSetupParamForVbAccumulatorNonMemProvingKey,
generateSetupParamForSaverCommitmentGens,
generateSetupParamForSaverEncryptionGens,
generateSetupParamForVbAccumulatorMemProvingKey,
generateSetupParamForSaverEncryptionKey,
generateSetupParamForSaverProvingKey,
generateSetupParamForSaverVerifyingKey,
generateSetupParamForLegoProvingKey,
generateSetupParamForLegoVerifyingKey,
generateSetupParamForR1CS,
R1CS,
generateSetupParamForBytes,
generateSetupParamForFieldElemVec,
generateSetupParamForBppParams,
generateSetupParamForSmcParams,
generateSetupParamForSmcParamsKV,
generateSetupParamForSmcParamsKVAndSk,
generateSetupParamForBDDT16MacParameters
} from 'crypto-wasm-new';
import { BBSPlusPublicKeyG2, BBSPlusSignatureParamsG1 } from '../bbs-plus';
import {
SaverChunkedCommitmentKey,
SaverChunkedCommitmentKeyUncompressed,
SaverEncryptionGens,
SaverEncryptionGensUncompressed,
SaverEncryptionKey,
SaverEncryptionKeyUncompressed,
SaverProvingKey,
SaverVerifyingKey,
SaverProvingKeyUncompressed,
SaverVerifyingKeyUncompressed
} from '../saver';
import {
LegoProvingKey,
LegoProvingKeyUncompressed,
LegoVerifyingKey,
LegoVerifyingKeyUncompressed
} from '../legosnark';
import { AccumulatorParams, AccumulatorPublicKey, MembershipProvingKey, NonMembershipProvingKey } from '../accumulator';
import { BytearrayWrapper } from '../bytearray-wrapper';
import { BBSSignatureParams } from '../bbs';
import { generateSetupParamForPSSignatureParameters } from 'crypto-wasm-new';
import { PSPublicKey, PSSignatureParams } from '../ps';
import { generateSetupParamForPSPublicKey, generateSetupParamForCommitmentKey } from 'crypto-wasm-new';
import { getR1CS, ParsedR1CSFile } from '../r1cs/file';
import {
BoundCheckBppParams,
BoundCheckBppParamsUncompressed,
BoundCheckSmcParams,
BoundCheckSmcParamsUncompressed,
BoundCheckSmcWithKVVerifierParams,
BoundCheckSmcWithKVVerifierParamsUncompressed
} from '../bound-check';
import { PederCommKey, PederCommKeyUncompressed } from '../ped-com';
import { BBDT16MacParams } from '../bbdt16-mac';
/**
* Represents (public) setup parameters of different protocols. Different setup parameters can be wrapped in this and
* then a reference to this is passed to the `Statement`. This is helpful when the same setup parameter needs
* to be passed to several `Statement`s as it avoids the need of having several copies of the setup parameter.
*/
export class SetupParam extends BytearrayWrapper {
static bbsPlusSignatureParamsG1(params: BBSPlusSignatureParamsG1): SetupParam {
return new SetupParam(generateSetupParamForBBSPlusSignatureParametersG1(params.value));
}
static bbsSignatureParams(params: BBSSignatureParams): SetupParam {
return new SetupParam(generateSetupParamForBBSSignatureParameters(params.value));
}
static bbsPlusSignaturePublicKeyG2(publicKey: BBSPlusPublicKeyG2): SetupParam {
return new SetupParam(generateSetupParamForBBSPlusPublicKeyG2(publicKey.value));
}
static psSignatureParams(params: PSSignatureParams): SetupParam {
return new SetupParam(generateSetupParamForPSSignatureParameters(params.value));
}
static psSignaturePublicKey(publicKey: PSPublicKey): SetupParam {
return new SetupParam(generateSetupParamForPSPublicKey(publicKey.value));
}
static bbdt16MacParams(params: BBDT16MacParams): SetupParam {
return new SetupParam(generateSetupParamForBDDT16MacParameters(params.value));
}
static vbAccumulatorParams(params: AccumulatorParams): SetupParam {
return new SetupParam(generateSetupParamForVbAccumulatorParams(params.value));
}
static vbAccumulatorPublicKey(publicKey: AccumulatorPublicKey): SetupParam {
return new SetupParam(generateSetupParamForVbAccumulatorPublicKey(publicKey.value));
}
static vbAccumulatorMemProvingKey(provingKey: MembershipProvingKey): SetupParam {
return new SetupParam(generateSetupParamForVbAccumulatorMemProvingKey(provingKey.value));
}
static vbAccumulatorNonMemProvingKey(provingKey: NonMembershipProvingKey): SetupParam {
return new SetupParam(generateSetupParamForVbAccumulatorNonMemProvingKey(provingKey.value));
}
static pedersenCommitmentKeyG1(commitmentKey: Uint8Array[]): SetupParam {
return new SetupParam(generateSetupParamForPedersenCommitmentKeyG1(commitmentKey));
}
static saverEncryptionGens(encGens: SaverEncryptionGens): SetupParam {
return new SetupParam(generateSetupParamForSaverEncryptionGens(encGens.value, false));
}
static saverEncryptionGensUncompressed(encGens: SaverEncryptionGensUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSaverEncryptionGens(encGens.value, true));
}
static saverCommitmentKey(commKey: SaverChunkedCommitmentKey): SetupParam {
return new SetupParam(generateSetupParamForSaverCommitmentGens(commKey.value, false));
}
static saverCommitmentKeyUncompressed(commKey: SaverChunkedCommitmentKeyUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSaverCommitmentGens(commKey.value, true));
}
static saverEncryptionKey(key: SaverEncryptionKey): SetupParam {
return new SetupParam(generateSetupParamForSaverEncryptionKey(key.value, false));
}
static saverEncryptionKeyUncompressed(key: SaverEncryptionKeyUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSaverEncryptionKey(key.value, true));
}
static saverProvingKey(key: SaverProvingKey): SetupParam {
return new SetupParam(generateSetupParamForSaverProvingKey(key.value, false));
}
static saverProvingKeyUncompressed(key: SaverProvingKeyUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSaverProvingKey(key.value, true));
}
static saverVerifyingKey(key: SaverVerifyingKey): SetupParam {
return new SetupParam(generateSetupParamForSaverVerifyingKey(key.value, false));
}
static saverVerifyingKeyUncompressed(key: SaverVerifyingKeyUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSaverVerifyingKey(key.value, true));
}
static legosnarkProvingKey(key: LegoProvingKey): SetupParam {
return new SetupParam(generateSetupParamForLegoProvingKey(key.value, false));
}
static legosnarkProvingKeyUncompressed(key: LegoProvingKeyUncompressed): SetupParam {
return new SetupParam(generateSetupParamForLegoProvingKey(key.value, true));
}
static legosnarkVerifyingKey(key: LegoVerifyingKey): SetupParam {
return new SetupParam(generateSetupParamForLegoVerifyingKey(key.value, false));
}
static legosnarkVerifyingKeyUncompressed(key: LegoVerifyingKeyUncompressed): SetupParam {
return new SetupParam(generateSetupParamForLegoVerifyingKey(key.value, true));
}
static r1cs(r1cs: R1CS | ParsedR1CSFile): SetupParam {
const processedR1cs = getR1CS(r1cs);
return new SetupParam(
generateSetupParamForR1CS(
processedR1cs.curveName,
processedR1cs.numPublic,
processedR1cs.numPrivate,
processedR1cs.constraints
)
);
}
static bytes(b: Uint8Array): SetupParam {
return new SetupParam(generateSetupParamForBytes(b));
}
static fieldElementVec(arr: Uint8Array[]): SetupParam {
return new SetupParam(generateSetupParamForFieldElemVec(arr));
}
static bppSetupParams(params: BoundCheckBppParams): SetupParam {
return new SetupParam(generateSetupParamForBppParams(params.value, false));
}
static bppSetupParamsUncompressed(params: BoundCheckBppParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForBppParams(params.value, true));
}
static smcSetupParams(params: BoundCheckSmcParams): SetupParam {
return new SetupParam(generateSetupParamForSmcParams(params.value, false));
}
static smcSetupParamsUncompressed(params: BoundCheckSmcParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParams(params.value, true));
}
static smcSetupParamsKV(params: BoundCheckSmcParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKV(params.value, false));
}
static smcSetupParamsKVUncompressed(params: BoundCheckSmcParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKV(params.value, true));
}
static smcSetupParamsKVWithSk(params: BoundCheckSmcWithKVVerifierParams): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKVAndSk(params.value, false));
}
static smcSetupParamsKVWithSkUncompressed(params: BoundCheckSmcWithKVVerifierParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKVAndSk(params.value, true));
}
static pedCommKeyG1(commKey: PederCommKey): SetupParam {
return new SetupParam(generateSetupParamForCommitmentKey(commKey.value, false));
}
static pedCommKeyG1Uncompressed(commKey: PederCommKeyUncompressed): SetupParam {
return new SetupParam(generateSetupParamForCommitmentKey(commKey.value, true));
}
}