-
Notifications
You must be signed in to change notification settings - Fork 9
/
scheme.ts
212 lines (208 loc) · 8.86 KB
/
scheme.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
import { encodeMessageForSigning, encodeMessageForSigningInConstantTime } from 'crypto-wasm-new';
import {
BBSBlindSignature,
BBSCredential,
BBSCredentialBuilder,
BBSKeypair,
BBSPlusBlindSignatureG1,
BBSPlusCredential,
BBSPlusCredentialBuilder,
BBSPlusKeypairG2,
BBSPlusPoKSignatureProtocol,
BBSPlusPublicKeyG2,
BBSPlusSecretKey,
BBSPlusSignatureG1,
BBSPlusSignatureParamsG1,
BBSPoKSignatureProtocol,
BBSPublicKey,
BBSSecretKey,
BBSSignature,
BBSSignatureParams,
PSBlindSignature,
PSCredential,
PSCredentialBuilder,
PSKeypair,
PSPoKSignatureProtocol,
PSPublicKey,
PSSecretKey,
PSSignature,
PSSignatureParams,
SetupParam,
Statement,
Witness,
getBBSPlusStatementForBlindSigRequest,
getBBSPlusWitnessForBlindSigRequest,
getBBSStatementForBlindSigRequest,
getBBSWitnessForBlindSigRequest,
getPSStatementsForBlindSigRequest,
getPSWitnessesForBlindSigRequest,
BBS_SIGNATURE_PARAMS_LABEL_BYTES,
BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES,
PS_SIGNATURE_PARAMS_LABEL_BYTES,
BBDT16_MAC_PARAMS_LABEL_BYTES,
getBBDT16StatementForBlindMacRequest,
getBBDT16WitnessForBlindMacRequest,
BBDT16CredentialBuilder,
BBDT16Credential,
BBDT16KeypairG1,
BBDT16MacPublicKeyG1,
BBS_CRED_PROOF_TYPE, BBS_PLUS_CRED_PROOF_TYPE, PS_CRED_PROOF_TYPE, BBDT16_CRED_PROOF_TYPE
} from '../src';
import { BBDT16BlindMac, BBDT16Mac, BBDT16MacParams, BBDT16MacSecretKey } from '../src';
export { Presentation } from '../src/anonymous-credentials/presentation';
export { PresentationBuilder } from '../src/anonymous-credentials/presentation-builder';
export let Scheme: string = process.env.TEST_SIGNATURE_SCHEME || 'BBS',
SignatureLabelBytes: Uint8Array,
PublicKey,
SecretKey,
Signature,
KeyPair,
BlindSignature,
SignatureParams,
PoKSignatureProtocol,
getStatementForBlindSigRequest,
getWitnessForBlindSigRequest,
buildWitness,
buildProverStatement,
buildVerifierStatement,
buildPublicKeySetupParam,
buildSignatureParamsSetupParam,
buildProverStatementFromSetupParamsRef,
buildVerifierStatementFromSetupParamsRef,
CredentialBuilder,
Credential,
CredentialProofType,
encodeMessageForSigningIfPS: (msg: Uint8Array) => Uint8Array,
encodeMessageForSigningIfNotPS: (msg: Uint8Array) => Uint8Array,
isBBS = () => false,
isBBSPlus = () => false,
isPS = () => false,
isBBDT16 = () => false,
isKvac = () => false,
adaptKeyForParams = (key, _params) => key;
switch (Scheme) {
case 'BBS':
PublicKey = BBSPublicKey;
SecretKey = BBSSecretKey;
Signature = BBSSignature;
BlindSignature = BBSBlindSignature;
KeyPair = BBSKeypair;
SignatureParams = BBSSignatureParams;
PoKSignatureProtocol = BBSPoKSignatureProtocol;
buildWitness = Witness.bbsSignatureConstantTime;
buildProverStatement = Statement.bbsSignatureProverConstantTime;
buildVerifierStatement = Statement.bbsSignatureVerifierConstantTime;
buildPublicKeySetupParam = SetupParam.bbsPlusSignaturePublicKeyG2;
buildSignatureParamsSetupParam = SetupParam.bbsSignatureParams;
buildProverStatementFromSetupParamsRef = Statement.bbsSignatureProverFromSetupParamRefsConstantTime;
buildVerifierStatementFromSetupParamsRef = Statement.bbsSignatureVerifierFromSetupParamRefsConstantTime;
getStatementForBlindSigRequest = getBBSStatementForBlindSigRequest;
getWitnessForBlindSigRequest = getBBSWitnessForBlindSigRequest;
CredentialBuilder = BBSCredentialBuilder;
Credential = BBSCredential;
CredentialProofType = BBS_CRED_PROOF_TYPE;
encodeMessageForSigningIfPS = (msg) => msg;
encodeMessageForSigningIfNotPS = encodeMessageForSigningInConstantTime;
SignatureLabelBytes = BBS_SIGNATURE_PARAMS_LABEL_BYTES;
isBBS = () => true;
break;
case 'BBS+':
PublicKey = BBSPlusPublicKeyG2;
SecretKey = BBSPlusSecretKey;
Signature = BBSPlusSignatureG1;
BlindSignature = BBSPlusBlindSignatureG1;
KeyPair = BBSPlusKeypairG2;
SignatureParams = BBSPlusSignatureParamsG1;
PoKSignatureProtocol = BBSPlusPoKSignatureProtocol;
buildWitness = Witness.bbsPlusSignatureConstantTime;
buildProverStatement = Statement.bbsPlusSignatureProverConstantTime;
buildVerifierStatement = Statement.bbsPlusSignatureVerifierConstantTime;
buildPublicKeySetupParam = SetupParam.bbsPlusSignaturePublicKeyG2;
buildSignatureParamsSetupParam = SetupParam.bbsPlusSignatureParamsG1;
buildProverStatementFromSetupParamsRef = Statement.bbsPlusSignatureProverFromSetupParamRefsConstantTime;
buildVerifierStatementFromSetupParamsRef = Statement.bbsPlusSignatureVerifierFromSetupParamRefsConstantTime;
getStatementForBlindSigRequest = getBBSPlusStatementForBlindSigRequest;
getWitnessForBlindSigRequest = getBBSPlusWitnessForBlindSigRequest;
CredentialBuilder = BBSPlusCredentialBuilder;
Credential = BBSPlusCredential;
CredentialProofType = BBS_PLUS_CRED_PROOF_TYPE;
SignatureLabelBytes = BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES;
encodeMessageForSigningIfPS = (msg) => msg;
encodeMessageForSigningIfNotPS = encodeMessageForSigningInConstantTime;
isBBSPlus = () => true;
break;
case 'PS':
PublicKey = PSPublicKey;
SecretKey = PSSecretKey;
Signature = PSSignature;
KeyPair = PSKeypair;
BlindSignature = PSBlindSignature;
SignatureParams = PSSignatureParams;
PoKSignatureProtocol = PSPoKSignatureProtocol;
buildWitness = Witness.psSignatureConstantTime;
buildProverStatement = Statement.psSignatureConstantTime;
buildVerifierStatement = Statement.psSignatureConstantTime;
buildPublicKeySetupParam = SetupParam.psSignaturePublicKey;
buildSignatureParamsSetupParam = SetupParam.psSignatureParams;
buildProverStatementFromSetupParamsRef = Statement.psSignatureFromSetupParamRefsConstantTime;
buildVerifierStatementFromSetupParamsRef = Statement.psSignatureFromSetupParamRefsConstantTime;
getStatementForBlindSigRequest = getPSStatementsForBlindSigRequest;
getWitnessForBlindSigRequest = getPSWitnessesForBlindSigRequest;
CredentialBuilder = PSCredentialBuilder;
Credential = PSCredential;
CredentialProofType = PS_CRED_PROOF_TYPE;
SignatureLabelBytes = PS_SIGNATURE_PARAMS_LABEL_BYTES;
encodeMessageForSigningIfPS = encodeMessageForSigningInConstantTime;
encodeMessageForSigningIfNotPS = (msg) => msg;
isPS = () => true;
adaptKeyForParams = (key, params) => key.adaptForLess(params.supportedMessageCount());
break;
case 'BBDT16':
PublicKey = BBDT16MacPublicKeyG1;
SecretKey = BBDT16MacSecretKey;
Signature = BBDT16Mac;
BlindSignature = BBDT16BlindMac;
KeyPair = BBDT16KeypairG1;
SignatureParams = BBDT16MacParams;
PoKSignatureProtocol = undefined;
buildWitness = Witness.bbdt16MacConstantTime;
buildProverStatement = Statement.bbdt16MacConstantTime;
buildVerifierStatement = Statement.bbdt16MacConstantTime;
buildPublicKeySetupParam = undefined;
buildSignatureParamsSetupParam = SetupParam.bbdt16MacParams;
buildProverStatementFromSetupParamsRef = Statement.bbdt16MacFromSetupParamRefsConstantTime;
buildVerifierStatementFromSetupParamsRef = Statement.bbdt16MacFromSetupParamRefsConstantTime;
getStatementForBlindSigRequest = getBBDT16StatementForBlindMacRequest;
getWitnessForBlindSigRequest = getBBDT16WitnessForBlindMacRequest;
CredentialBuilder = BBDT16CredentialBuilder;
Credential = BBDT16Credential;
CredentialProofType = BBDT16_CRED_PROOF_TYPE;
SignatureLabelBytes = BBDT16_MAC_PARAMS_LABEL_BYTES;
encodeMessageForSigningIfPS = (msg) => msg;
encodeMessageForSigningIfNotPS = encodeMessageForSigningInConstantTime;
isBBDT16 = () => true,
isKvac = () => true;
break;
default:
throw new Error(
`Unknown signature scheme provided in \`TEST_SIGNATURE_SCHEME\`: ${Scheme}, expected either \`BBS\`, \`BBS+\`, \`PS\` or BBDT16`
);
}
export type PublicKey = typeof PublicKey;
export type KeyPair = typeof KeyPair;
export type SecretKey = typeof SecretKey;
export type Signature = typeof Signature;
export type BlindSignature = typeof BlindSignature;
export type SignatureParams = typeof SignatureParams;
export type PoKSignatureProtocol = typeof PoKSignatureProtocol;
export type buildWitness = typeof buildWitness;
export type buildProverStatement = typeof buildProverStatement;
export type buildVerifierStatement = typeof buildVerifierStatement;
export type buildPublicKeySetupParam = typeof buildPublicKeySetupParam;
export type buildSignatureParamsSetupParam = typeof buildSignatureParamsSetupParam;
export type buildProverStatementFromSetupParamsRef = typeof buildProverStatementFromSetupParamsRef;
export type buildVerifierStatementFromSetupParamsRef = typeof buildVerifierStatementFromSetupParamsRef;
export type getStatementForBlindSigRequest = typeof getStatementForBlindSigRequest;
export type getWitnessForBlindSigRequest = typeof getWitnessForBlindSigRequest;
export type CredentialBuilder = typeof CredentialBuilder;
export type Credential = typeof Credential;