-
Notifications
You must be signed in to change notification settings - Fork 9
/
types-and-consts.ts
306 lines (263 loc) · 10.9 KB
/
types-and-consts.ts
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import { KBUniversalMembershipWitness, KBUniversalNonMembershipWitness } from '../accumulator';
import { KBUniversalAccumulatorValue } from '../accumulator';
import { BBSPublicKey, BBSSecretKey, BBSSignature, BBSSignatureParams } from '../bbs';
import { LegoProvingKey, LegoProvingKeyUncompressed } from '../legosnark';
import {
SaverChunkedCommitmentKey,
SaverCiphertext,
SaverEncryptionGens,
SaverEncryptionGensUncompressed,
SaverEncryptionKey,
SaverProvingKey,
SaverProvingKeyUncompressed
} from '../saver';
import { R1CS } from 'crypto-wasm-new';
import { BBSPlusPublicKeyG2, BBSPlusSecretKey, BBSPlusSignatureG1, BBSPlusSignatureParamsG1 } from '../bbs-plus';
import { PSPublicKey, PSSecretKey, PSSignature, PSSignatureParams } from '../ps';
import {
Accumulator,
AccumulatorParams,
AccumulatorPublicKey,
AccumulatorSecretKey,
MembershipProvingKey,
NonMembershipProvingKey,
VBMembershipWitness,
VBNonMembershipWitness
} from '../accumulator';
import {
BoundCheckBppParams,
BoundCheckBppParamsUncompressed,
BoundCheckSmcParams,
BoundCheckSmcParamsUncompressed,
BoundCheckSmcWithKVProverParams,
BoundCheckSmcWithKVProverParamsUncompressed,
BoundCheckSmcWithKVVerifierParams,
BoundCheckSmcWithKVVerifierParamsUncompressed
} from '../bound-check';
import { PederCommKey, PederCommKeyUncompressed } from '../ped-com';
import { BBDT16Mac, BBDT16MacParams, BBDT16MacSecretKey } from '../bbdt16-mac';
/**
* Reference to an attribute of a credential. The first item of the pair is the credential index in the presentation and the
* second item is the fully qualified attribute name.
*/
export type AttributeRef = [number, string];
/**
* Array of references to attributes that are equal
*/
export type AttributeEquality = AttributeRef[];
/**
* All possible predicate parameter types
*/
export type PredicateParamType =
| LegoProvingKey
| LegoProvingKeyUncompressed
| SaverProvingKey
| SaverProvingKeyUncompressed
| SaverEncryptionKey
| SaverChunkedCommitmentKey
| R1CS
| Uint8Array
| BoundCheckBppParams
| BoundCheckBppParamsUncompressed
| BoundCheckSmcParams
| BoundCheckSmcParamsUncompressed
| BoundCheckSmcWithKVProverParams
| BoundCheckSmcWithKVProverParamsUncompressed
| BoundCheckSmcWithKVVerifierParams
| BoundCheckSmcWithKVVerifierParamsUncompressed;
/**
* All possible bound check parameter types
*/
export type BoundCheckParamType =
| LegoProvingKey
| LegoProvingKeyUncompressed
| BoundCheckBppParams
| BoundCheckBppParamsUncompressed
| BoundCheckSmcParams
| BoundCheckSmcParamsUncompressed
| BoundCheckSmcWithKVProverParams
| BoundCheckSmcWithKVProverParamsUncompressed
| BoundCheckSmcWithKVVerifierParams
| BoundCheckSmcWithKVVerifierParamsUncompressed;
/**
* The first item is the fully qualified attribute name
*/
export type BlindedAttributeEquality = [string, AttributeRef[]];
export type DateType = Date | string;
export type BoundType = number | DateType;
/**
* The 1st element is an array of all attribute names as flattened and sorted and 2nd element is an array of types of those attributes
* in the same order
*/
export type FlattenedSchema = [string[], object[]];
export type AttributeCiphertexts = { [key: string]: object | SaverCiphertext | SaverCiphertext[] };
export type SecretKey = BBSSecretKey | BBSPlusSecretKey | PSSecretKey | BBDT16MacSecretKey;
export type PublicKey = BBSPublicKey | BBSPlusPublicKeyG2 | PSPublicKey;
export type Signature = BBSSignature | BBSPlusSignatureG1 | PSSignature | BBDT16Mac;
export type SignatureParams = BBSSignatureParams | BBSPlusSignatureParamsG1 | PSSignatureParams | BBDT16MacParams;
export type SignatureParamsClass =
| typeof BBSSignatureParams
| typeof BBSPlusSignatureParamsG1
| typeof PSSignatureParams
| typeof BBDT16MacParams;
/**
* A parameter to verify the credential. This could be a public key or the secret key. Secret key is used to verify credentials
* in situations where the issuer and verifier are the same entity (or share the secret key). Thus, such credentials are not
* publicly verifiable
*/
export type CredentialVerificationParam = PublicKey | BBDT16MacSecretKey;
/**
* A parameter to verify the proof of accumulator (non)membership in zero-knowledge. This could be a public key or the secret key.
* Secret key is used to verify the proof in situations where the revocation authority and verifier are the same entity (or share the secret key).
* Thus, such proofs are not publicly verifiable
*/
export type AccumulatorVerificationParam = AccumulatorPublicKey | AccumulatorSecretKey;
export type AccumulatorWitnessType =
| VBMembershipWitness
| VBNonMembershipWitness
| KBUniversalMembershipWitness
| KBUniversalNonMembershipWitness;
export type AccumulatorValueType = Uint8Array | KBUniversalAccumulatorValue;
export const VERSION_STR = 'version';
export const CRYPTO_VERSION_STR = 'cryptoVersion';
export const SCHEMA_STR = 'credentialSchema';
export const JSON_SCHEMA_STR = 'jsonSchema';
export const FULL_SCHEMA_STR = 'fullJsonSchema';
export const SCHEMA_TYPE_STR = 'JsonSchemaValidator2018';
export const SCHEMA_PROPS_STR = 'properties';
export const SCHEMA_DETAILS_STR = 'details';
export const SUBJECT_STR = 'credentialSubject';
export const STATUS_STR = 'credentialStatus';
export const TYPE_STR = 'type';
export const VB_ACCUMULATOR_22 = 'DockVBAccumulator2022';
export const KB_UNI_ACCUMULATOR_24 = 'DockKBUniversalAccumulator2024';
export const ID_STR = 'id';
export const REV_CHECK_STR = 'revocationCheck';
export const REV_ID_STR = 'revocationId';
export const MEM_CHECK_STR = 'membership';
export const NON_MEM_CHECK_STR = 'non-membership';
export const MEM_CHECK_KV_STR = 'membership-kv';
export const NON_MEM_CHECK_KV_STR = 'non-membership-kv';
export const PROOF_STR = 'proof';
export const BBS_CRED_PROOF_TYPE = 'Bls12381BBSSignatureDock2023';
export const BBS_BLINDED_CRED_PROOF_TYPE = 'Bls12381BlindedBBSSignatureDock2023';
export const BBS_PLUS_CRED_PROOF_TYPE = 'Bls12381BBS+SignatureDock2022';
export const BBS_PLUS_BLINDED_CRED_PROOF_TYPE = 'Bls12381BlindedBBS+SignatureDock2023';
export const PS_CRED_PROOF_TYPE = 'Bls12381PSSignatureDock2023';
export const BBDT16_CRED_PROOF_TYPE = 'Bls12381BBDT16MACDock2024';
export const BBDT16_BLINDED_CRED_PROOF_TYPE = 'Bls12381BlindedBBDT16MACDock2024';
export const LEGOGROTH16 = 'LegoGroth16';
export const SAVER = 'SAVER';
export const BPP = 'Bulletproofs++';
export const SMC = 'Set-membership-check';
export const SMC_KV = 'Set-membership-check-with-keyed-verification';
export const UPROVE = 'UProve';
const te = new TextEncoder();
/** Label used for generating BBS+ signature parameters */
export const BBS_SIGNATURE_PARAMS_LABEL = 'DockBBSSignature2023';
export const BBS_SIGNATURE_PARAMS_LABEL_BYTES = te.encode(BBS_SIGNATURE_PARAMS_LABEL);
/** Label used for generating BBS+ signature parameters */
export const BBS_PLUS_SIGNATURE_PARAMS_LABEL = 'DockBBS+Signature2022';
export const BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES = te.encode(BBS_PLUS_SIGNATURE_PARAMS_LABEL);
/** Label used for generating BBDT16 MAC parameters */
export const BBDT16_MAC_PARAMS_LABEL = 'DockBBDT16MAC';
export const BBDT16_MAC_PARAMS_LABEL_BYTES = te.encode(BBDT16_MAC_PARAMS_LABEL);
/** Label used for generating PS signature parameters */
export const PS_SIGNATURE_PARAMS_LABEL = 'DockPSSignature2023';
export const PS_SIGNATURE_PARAMS_LABEL_BYTES = te.encode(PS_SIGNATURE_PARAMS_LABEL);
/** Label used for generating accumulator parameters */
export const ACCUMULATOR_PARAMS_LABEL = 'DockVBAccumulator2022';
export const ACCUMULATOR_PARAMS_LABEL_BYTES = te.encode(ACCUMULATOR_PARAMS_LABEL);
/** Label used for generating accumulator proving key */
export const ACCUMULATOR_PROVING_KEY_LABEL = 'DockVBAccumulatorProvingKey2022';
export const ACCUMULATOR_PROVING_KEY_LABEL_BYTES = te.encode(ACCUMULATOR_PROVING_KEY_LABEL);
/** Label used for generating SAVER encryption generators */
export const SAVER_ENCRYPTION_GENS_LABEL = 'DockSAVEREncryptionGens2022';
export const SAVER_ENCRYPTION_GENS_LABEL_BYTES = te.encode(SAVER_ENCRYPTION_GENS_LABEL);
/** Label used for generating Bulletproofs++ generators */
export const BPP_GENS_LABEL = 'DockBulletproofs++2023';
export const BPP_GENS_LABEL_BYTES = te.encode(BPP_GENS_LABEL);
/** Label used for generating commitment key for proving inequality */
export const INEQUALITY_COMM_KEY_LABEL = 'DockInequalityDiscreteLog2023';
export const INEQUALITY_COMM_KEY_LABEL_BYTES = te.encode(INEQUALITY_COMM_KEY_LABEL);
/** Schema id for an embedded schema and when no explicit id is provided */
export const EMPTY_SCHEMA_ID = 'data:application/json;charset=utf-8,';
/** Mandatory fields of a schema when serialized */
export const SCHEMA_FIELDS = [
`${SCHEMA_STR}.${SCHEMA_DETAILS_STR}`,
`${SCHEMA_STR}.${ID_STR}`,
`${SCHEMA_STR}.${TYPE_STR}`,
`${SCHEMA_STR}.${VERSION_STR}`
];
export function dockAccumulatorParams(): AccumulatorParams {
return Accumulator.generateParams(ACCUMULATOR_PARAMS_LABEL_BYTES);
}
export function dockAccumulatorMemProvingKey(): MembershipProvingKey {
return MembershipProvingKey.generate(ACCUMULATOR_PROVING_KEY_LABEL_BYTES);
}
export function dockAccumulatorNonMemProvingKey(): NonMembershipProvingKey {
return NonMembershipProvingKey.generate(ACCUMULATOR_PROVING_KEY_LABEL_BYTES);
}
export function dockSaverEncryptionGens(): SaverEncryptionGens {
return SaverEncryptionGens.generate(SAVER_ENCRYPTION_GENS_LABEL_BYTES);
}
export function dockSaverEncryptionGensUncompressed(): SaverEncryptionGensUncompressed {
return SaverEncryptionGens.generate(SAVER_ENCRYPTION_GENS_LABEL_BYTES).decompress();
}
export function dockBoundCheckBppSetup(): BoundCheckBppParams {
return new BoundCheckBppParams(BPP_GENS_LABEL_BYTES);
}
export function dockBoundCheckBppSetupUncompressed(): BoundCheckBppParamsUncompressed {
return new BoundCheckBppParams(BPP_GENS_LABEL_BYTES).decompress();
}
export function dockInequalityCommKey(): PederCommKey {
return new PederCommKey(INEQUALITY_COMM_KEY_LABEL_BYTES);
}
export function dockInequalityCommKeyUncompressed(): PederCommKeyUncompressed {
return new PederCommKey(INEQUALITY_COMM_KEY_LABEL_BYTES).decompress();
}
/**
* Possible signature types
*/
export enum SignatureType {
Bbs = BBS_CRED_PROOF_TYPE,
BbsPlus = BBS_PLUS_CRED_PROOF_TYPE,
Ps = PS_CRED_PROOF_TYPE,
Bbdt16 = BBDT16_CRED_PROOF_TYPE
}
/**
* Possible blind-signature types
*/
export enum BlindSignatureType {
Bbs = BBS_BLINDED_CRED_PROOF_TYPE,
BbsPlus = BBS_PLUS_BLINDED_CRED_PROOF_TYPE,
Bbdt16 = BBDT16_BLINDED_CRED_PROOF_TYPE
}
/**
* Possible revocation protocols
*/
export enum RevocationStatusProtocol {
Vb22 = VB_ACCUMULATOR_22,
KbUni24 = KB_UNI_ACCUMULATOR_24
}
/**
* Possible bound check protocols
*/
export enum BoundCheckProtocol {
Legogroth16 = LEGOGROTH16,
Bpp = BPP,
Smc = SMC,
SmcKV = SMC_KV
}
/**
* Possible verifiable encryption protocols
*/
export enum VerifiableEncryptionProtocol {
Saver = SAVER
}
export enum CircomProtocol {
Legogroth16 = LEGOGROTH16
}
export enum InequalityProtocol {
Uprove = UPROVE
}