-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathproof.ts
89 lines (82 loc) · 2.5 KB
/
proof.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
/**
* Proof of knowledge of signature protocol
*/
import { BBSSignature } from './signature';
import { BBSSignatureParams } from './params';
import {
BbsPoKSigProtocol,
VerifyResult,
bbsInitializeProofOfKnowledgeOfSignatureNew,
bbsGenProofOfKnowledgeOfSignatureNew,
bbsChallengeContributionFromProtocolNew,
bbsVerifyProofOfKnowledgeOfSignatureNew,
bbsChallengeContributionFromProofNew
} from 'crypto-wasm-new';
import { BBSPublicKey } from './keys';
import { BytearrayWrapper } from '../bytearray-wrapper';
export class BBSPoKSignatureProtocol {
value: BbsPoKSigProtocol;
constructor(protocol: BbsPoKSigProtocol) {
this.value = protocol;
}
static initialize(
messages: Uint8Array[],
signature: BBSSignature,
params: BBSSignatureParams,
encodeMessages: boolean,
blindings: Map<number, Uint8Array> = new Map(),
revealed: Set<number> = new Set()
): BBSPoKSignatureProtocol {
if (messages.length !== params.supportedMessageCount()) {
throw new Error(
`Number of messages ${
messages.length
} is different from ${params.supportedMessageCount()} supported by the signature params`
);
}
const protocol = bbsInitializeProofOfKnowledgeOfSignatureNew(
signature.value,
params.value,
messages,
blindings,
revealed,
encodeMessages
);
return new BBSPoKSignatureProtocol(protocol);
}
generateProof(challenge: Uint8Array): BBSPoKSigProof {
return new BBSPoKSigProof(bbsGenProofOfKnowledgeOfSignatureNew(this.value, challenge));
}
challengeContribution(
params: BBSSignatureParams,
encodeMessages: boolean,
revealedMsgs: Map<number, Uint8Array> = new Map()
): Uint8Array {
return bbsChallengeContributionFromProtocolNew(this.value, revealedMsgs, params.value, encodeMessages);
}
}
export class BBSPoKSigProof extends BytearrayWrapper {
verify(
challenge: Uint8Array,
publicKey: BBSPublicKey,
params: BBSSignatureParams,
encodeMessages: boolean,
revealedMsgs: Map<number, Uint8Array> = new Map()
): VerifyResult {
return bbsVerifyProofOfKnowledgeOfSignatureNew(
this.value,
revealedMsgs,
challenge,
publicKey.value,
params.value,
encodeMessages
);
}
challengeContribution(
params: BBSSignatureParams,
encodeMessages: boolean,
revealedMsgs: Map<number, Uint8Array> = new Map()
): Uint8Array {
return bbsChallengeContributionFromProofNew(this.value, revealedMsgs, params.value, encodeMessages);
}
}