-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathproof.ts
More file actions
93 lines (75 loc) · 4.11 KB
/
proof.ts
File metadata and controls
93 lines (75 loc) · 4.11 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
import {AccumulatorParams, VerifyResult} from "../../../crypto-wasm/src/js";
import {
accumulatorChallengeContributionFromNonMembershipProof,
accumulatorInitializeMembershipProof,
accumulatorVerifyNonMembershipProof,
generateRandomFieldElement,
accumulatorChallengeContributionFromMembershipProof,
accumulatorChallengeContributionFromMembershipProtocol,
accumulatorChallengeContributionFromNonMembershipProtocol,
accumulatorGenMembershipProof,
accumulatorGenNonMembershipProof,
accumulatorInitializeNonMembershipProof,
accumulatorVerifyMembershipProof
} from "../../../crypto-wasm/src/js";
import {MembershipWitness, NonMembershipWitness} from "./accumulatorWitness";
export class MembershipProofProtocol {
value: Uint8Array;
constructor(protocol: Uint8Array) {
this.value = protocol;
}
static initialize(member: Uint8Array, witness: MembershipWitness, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array, blinding?: Uint8Array): MembershipProofProtocol {
const b = blinding === undefined ? generateRandomFieldElement() : blinding;
const protocol = accumulatorInitializeMembershipProof(member, b, witness.value, publicKey, params, provingKey);
return new MembershipProofProtocol(protocol);
}
generateProof(challenge: Uint8Array): MembershipProof {
const proof = accumulatorGenMembershipProof(this.value, challenge);
return new MembershipProof(proof);
}
challengeContribution(accumulated: Uint8Array, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array,): Uint8Array {
return accumulatorChallengeContributionFromMembershipProtocol(this.value, accumulated, publicKey, params, provingKey);
}
}
export class NonMembershipProofProtocol {
value: Uint8Array;
constructor(protocol: Uint8Array) {
this.value = protocol;
}
static initialize(nonMember: Uint8Array, witness: NonMembershipWitness, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array, blinding?: Uint8Array): MembershipProofProtocol {
const b = blinding === undefined ? generateRandomFieldElement() : blinding;
const protocol = accumulatorInitializeNonMembershipProof(nonMember, b, witness.value, publicKey, params, provingKey);
return new MembershipProofProtocol(protocol);
}
generateProof(challenge: Uint8Array): NonMembershipProof {
const proof = accumulatorGenNonMembershipProof(this.value, challenge);
return new NonMembershipProof(proof);
}
challengeContribution(accumulated: Uint8Array, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array): Uint8Array {
return accumulatorChallengeContributionFromNonMembershipProtocol(this.value, accumulated, publicKey, params, provingKey);
}
}
export class MembershipProof {
value: Uint8Array;
constructor(proof: Uint8Array) {
this.value = proof;
}
verify(accumulated: Uint8Array, challenge: Uint8Array, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array): VerifyResult {
return accumulatorVerifyMembershipProof(this.value, accumulated, challenge, publicKey, params, provingKey);
}
challengeContribution(accumulated: Uint8Array, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array): Uint8Array {
return accumulatorChallengeContributionFromMembershipProof(this.value, accumulated, publicKey, params, provingKey);
}
}
export class NonMembershipProof {
value: Uint8Array;
constructor(proof: Uint8Array) {
this.value = proof;
}
verify(accumulated: Uint8Array, challenge: Uint8Array, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array): VerifyResult {
return accumulatorVerifyNonMembershipProof(this.value, accumulated, challenge, publicKey, params, provingKey);
}
challengeContribution(accumulated: Uint8Array, publicKey: Uint8Array, params: AccumulatorParams, provingKey: Uint8Array): Uint8Array {
return accumulatorChallengeContributionFromNonMembershipProof(this.value, accumulated, publicKey, params, provingKey);
}
}