|
| 1 | +// TODO requires changes |
1 | 2 | import { Field, JsonProof } from "o1js"; |
2 | | -import ProvePasswordInTreeProgram, { PasswordTreePublicInput, PasswordTreeWitness } from "../common/passwordTreeProgram"; |
| 3 | +import ProvePasswordInTreeProgram, { PasswordInTreeWitness } from "../common/passwordTreeProgram"; |
3 | 4 | import { IMinAuthProver, IMinAuthProverFactory } from '../../../library/plugin/pluginType'; |
4 | 5 |
|
5 | 6 | import axios from "axios"; |
6 | 7 |
|
7 | | -export type SimplePasswordTreeProverConfiguration = { |
8 | | - apiServer: URL, |
| 8 | +export type MemberSetProverConfiguration = { |
| 9 | + apiServer: URL, |
9 | 10 | } |
10 | 11 |
|
11 | | -export class SimplePasswordTreeProver implements |
12 | | - IMinAuthProver<bigint, PasswordTreePublicInput, Field> |
| 12 | + |
| 13 | +// Prove that you belong to a set of user without revealing which user you are. |
| 14 | +export class MemberSetProver implements |
| 15 | + IMinAuthProver<bigint, PasswordInTreeWitness, Field> |
13 | 16 | { |
14 | | - private readonly cfg: SimplePasswordTreeProverConfiguration; |
15 | | - |
16 | | - async prove(publicInput: PasswordTreePublicInput, secretInput: Field) |
17 | | - : Promise<JsonProof> { |
18 | | - const proof = await ProvePasswordInTreeProgram.baseCase( |
19 | | - publicInput, Field.from(secretInput)); |
20 | | - return proof.toJSON(); |
21 | | - } |
22 | | - |
23 | | - async fetchPublicInputs(uid: bigint): Promise<PasswordTreePublicInput> { |
24 | | - const mkUrl = (endpoint: string) => `${this.cfg.apiServer}/${endpoint}`; |
25 | | - const getWitness = async (): Promise<PasswordTreeWitness> => { |
26 | | - const resp = await axios.get(mkUrl(`/witness/${uid.toString()}`)); |
27 | | - if (resp.status != 200) { |
28 | | - throw `unable to fetch witness for ${uid.toString()}, error: ${(resp.data as { error: string }).error}`; |
29 | | - } |
30 | | - return PasswordTreeWitness.fromJSON(resp.data); |
31 | | - }; |
32 | | - const getRoot = async (): Promise<Field> => { |
33 | | - const resp = await axios.get(mkUrl('/root')); |
34 | | - return Field.fromJSON(resp.data); |
| 17 | + private readonly cfg: MemberSetProverConfiguration; |
| 18 | + |
| 19 | + async prove(publicInput: PasswordInTreeWitness, secretInput: Field) |
| 20 | + : Promise<JsonProof> { |
| 21 | + const proof = await ProvePasswordInTreeProgram.baseCase( |
| 22 | + publicInput, Field.from(secretInput)); |
| 23 | + return proof.toJSON(); |
35 | 24 | } |
36 | | - const witness = await getWitness(); |
37 | | - const root = await getRoot(); |
38 | 25 |
|
39 | | - return new PasswordTreePublicInput({ witness, root }); |
40 | | - } |
| 26 | + async fetchPublicInputs(uid: bigint): Promise<PasswordInTreeWitness> { |
| 27 | + const mkUrl = (endpoint: string) => `${this.cfg.apiServer}/${endpoint}`; |
| 28 | + const getWitness = async (): Promise<PasswordInTreeWitness> => { |
| 29 | + const resp = await axios.get(mkUrl(`/witness/${uid.toString()}`)); |
| 30 | + if (resp.status != 200) { |
| 31 | + throw `unable to fetch witness for ${uid.toString()}, error: ${(resp.data as { error: string }).error}`; |
| 32 | + } |
| 33 | + return PasswordInTreeWitness.fromJSON(resp.data); |
| 34 | + }; |
| 35 | + const getRoot = async (): Promise<Field> => { |
| 36 | + const resp = await axios.get(mkUrl('/root')); |
| 37 | + return Field.fromJSON(resp.data); |
| 38 | + } |
| 39 | + const witness = await getWitness(); |
| 40 | + const root = await getRoot(); |
| 41 | + |
| 42 | + return new PasswordInTreeWitness({ witness, root }); |
| 43 | + } |
41 | 44 |
|
42 | | - constructor(cfg: SimplePasswordTreeProverConfiguration) { |
43 | | - this.cfg = cfg; |
44 | | - } |
| 45 | + constructor(cfg: MemberSetProverConfiguration) { |
| 46 | + this.cfg = cfg; |
| 47 | + } |
45 | 48 |
|
46 | | - static async initialize(cfg: SimplePasswordTreeProverConfiguration): |
47 | | - Promise<SimplePasswordTreeProver> { |
48 | | - return new SimplePasswordTreeProver(cfg); |
49 | | - } |
| 49 | + static async initialize(cfg: MemberSetProverConfiguration): |
| 50 | + Promise<MemberSetProver> { |
| 51 | + return new MemberSetProver(cfg); |
| 52 | + } |
50 | 53 | } |
51 | 54 |
|
52 | | -SimplePasswordTreeProver satisfies IMinAuthProverFactory< |
53 | | - SimplePasswordTreeProver, |
54 | | - SimplePasswordTreeProverConfiguration, |
55 | | - bigint, |
56 | | - PasswordTreePublicInput, |
57 | | - Field |
58 | | -> |
| 55 | +MemberSetProver satisfies IMinAuthProverFactory< |
| 56 | + MemberSetProver, |
| 57 | + MemberSetProverConfiguration, |
| 58 | + bigint, |
| 59 | + PasswordInTreeWitness, |
| 60 | + Field |
| 61 | + > |
0 commit comments