-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutil.ts
71 lines (65 loc) · 2.13 KB
/
util.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
import {
adaptKeyForParams,
buildProverStatement, buildProverStatementFromSetupParamsRef,
buildVerifierStatement, buildVerifierStatementFromSetupParamsRef,
isKvac, isPS, PublicKey,
Signature,
SignatureParams
} from '../../scheme';
import { checkResult } from '../../utils';
export function signAndVerify(messages, encoder, label, sk, pk) {
const signed = Signature.signMessageObject(messages, sk, label, encoder);
checkResult(isKvac() ? signed.signature.verifyMessageObject(messages, sk, label, encoder) : signed.signature.verifyMessageObject(messages, pk, label, encoder));
return signed;
}
export function proverStmt(params: SignatureParams, revealedMsgs: Map<number, Uint8Array>, pk?: PublicKey, encode = false) {
return !isPS() ? buildProverStatement(
params,
revealedMsgs,
encode
) : buildProverStatement(
params,
adaptKeyForParams(pk, params),
revealedMsgs,
encode
)
}
export function verifierStmt(params: SignatureParams, revealedMsgs: Map<number, Uint8Array>, pk?: PublicKey, encode = false) {
return isKvac() ? buildVerifierStatement(
params,
revealedMsgs,
encode
): buildVerifierStatement(
params,
adaptKeyForParams(pk, params),
revealedMsgs,
encode
)
}
export function proverStmtFromSetupParamsRef(paramsRef: number, revealedMsgs: Map<number, Uint8Array>, pkRef?: number, encode = false) {
return !isPS() ? buildProverStatementFromSetupParamsRef(
paramsRef,
revealedMsgs,
encode
) : buildProverStatementFromSetupParamsRef(
paramsRef,
pkRef,
revealedMsgs,
encode
)
}
export function verifierStmtFromSetupParamsRef(paramsRef: number, revealedMsgs: Map<number, Uint8Array>, pkRef?: PublicKey, encode = false) {
return isKvac() ? buildVerifierStatementFromSetupParamsRef(
paramsRef,
revealedMsgs,
encode
): buildVerifierStatementFromSetupParamsRef(
paramsRef,
pkRef,
revealedMsgs,
encode
)
}
export function adaptedSigParams(attributesStruct, label) {
return isKvac() ? SignatureParams.getMacParamsForMsgStructure(attributesStruct, label) : SignatureParams.getSigParamsForMsgStructure(attributesStruct, label);
}