|
1 |
| -// import { assert, expect } from "chai"; |
2 |
| - |
3 |
| -// import { createRLN } from "./create.js"; |
4 |
| - |
5 |
| -// describe("js-rln", () => { |
6 |
| -// it("should verify a proof", async function () { |
7 |
| -// const rlnInstance = await createRLN(); |
8 |
| - |
9 |
| -// const credential = rlnInstance.zerokit.generateIdentityCredentials(); |
10 |
| - |
11 |
| -// //peer's index in the Merkle Tree |
12 |
| -// const index = 5; |
13 |
| - |
14 |
| -// // Create a Merkle tree with random members |
15 |
| -// for (let i = 0; i < 10; i++) { |
16 |
| -// if (i == index) { |
17 |
| -// // insert the current peer's pk |
18 |
| -// rlnInstance.zerokit.insertMember(credential.IDCommitment); |
19 |
| -// } else { |
20 |
| -// // create a new key pair |
21 |
| -// rlnInstance.zerokit.insertMember( |
22 |
| -// rlnInstance.zerokit.generateIdentityCredentials().IDCommitment |
23 |
| -// ); |
24 |
| -// } |
25 |
| -// } |
26 |
| - |
27 |
| -// // prepare the message |
28 |
| -// const uint8Msg = Uint8Array.from( |
29 |
| -// "Hello World".split("").map((x) => x.charCodeAt(0)) |
30 |
| -// ); |
31 |
| - |
32 |
| -// // setting up the epoch |
33 |
| -// const epoch = new Date(); |
34 |
| - |
35 |
| -// // generating proof |
36 |
| -// const proof = await rlnInstance.zerokit.generateRLNProof( |
37 |
| -// uint8Msg, |
38 |
| -// index, |
39 |
| -// epoch, |
40 |
| -// credential.IDSecretHash |
41 |
| -// ); |
42 |
| - |
43 |
| -// try { |
44 |
| -// // verify the proof |
45 |
| -// const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
46 |
| -// expect(verifResult).to.be.true; |
47 |
| -// } catch (err) { |
48 |
| -// assert.fail(0, 1, "should not have failed proof verification"); |
49 |
| -// } |
50 |
| - |
51 |
| -// try { |
52 |
| -// // Modifying the signal so it's invalid |
53 |
| -// uint8Msg[4] = 4; |
54 |
| -// // verify the proof |
55 |
| -// const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
56 |
| -// expect(verifResult).to.be.false; |
57 |
| -// } catch (err) { |
58 |
| -// console.log(err); |
59 |
| -// } |
60 |
| -// }); |
61 |
| -// it("should verify a proof with a seeded membership key generation", async function () { |
62 |
| -// const rlnInstance = await createRLN(); |
63 |
| -// const seed = "This is a test seed"; |
64 |
| -// const credential = |
65 |
| -// rlnInstance.zerokit.generateSeededIdentityCredential(seed); |
66 |
| - |
67 |
| -// //peer's index in the Merkle Tree |
68 |
| -// const index = 5; |
69 |
| - |
70 |
| -// // Create a Merkle tree with random members |
71 |
| -// for (let i = 0; i < 10; i++) { |
72 |
| -// if (i == index) { |
73 |
| -// // insert the current peer's pk |
74 |
| -// rlnInstance.zerokit.insertMember(credential.IDCommitment); |
75 |
| -// } else { |
76 |
| -// // create a new key pair |
77 |
| -// rlnInstance.zerokit.insertMember( |
78 |
| -// rlnInstance.zerokit.generateIdentityCredentials().IDCommitment |
79 |
| -// ); |
80 |
| -// } |
81 |
| -// } |
82 |
| - |
83 |
| -// // prepare the message |
84 |
| -// const uint8Msg = Uint8Array.from( |
85 |
| -// "Hello World".split("").map((x) => x.charCodeAt(0)) |
86 |
| -// ); |
87 |
| - |
88 |
| -// // setting up the epoch |
89 |
| -// const epoch = new Date(); |
90 |
| - |
91 |
| -// // generating proof |
92 |
| -// const proof = await rlnInstance.zerokit.generateRLNProof( |
93 |
| -// uint8Msg, |
94 |
| -// index, |
95 |
| -// epoch, |
96 |
| -// credential.IDSecretHash |
97 |
| -// ); |
98 |
| - |
99 |
| -// try { |
100 |
| -// // verify the proof |
101 |
| -// const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
102 |
| -// expect(verifResult).to.be.true; |
103 |
| -// } catch (err) { |
104 |
| -// assert.fail(0, 1, "should not have failed proof verification"); |
105 |
| -// } |
106 |
| - |
107 |
| -// try { |
108 |
| -// // Modifying the signal so it's invalid |
109 |
| -// uint8Msg[4] = 4; |
110 |
| -// // verify the proof |
111 |
| -// const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
112 |
| -// expect(verifResult).to.be.false; |
113 |
| -// } catch (err) { |
114 |
| -// console.log(err); |
115 |
| -// } |
116 |
| -// }); |
117 |
| - |
118 |
| -// it("should generate the same membership key if the same seed is provided", async function () { |
119 |
| -// const rlnInstance = await createRLN(); |
120 |
| -// const seed = "This is a test seed"; |
121 |
| -// const memKeys1 = rlnInstance.zerokit.generateSeededIdentityCredential(seed); |
122 |
| -// const memKeys2 = rlnInstance.zerokit.generateSeededIdentityCredential(seed); |
123 |
| - |
124 |
| -// memKeys1.IDCommitment.forEach((element, index) => { |
125 |
| -// expect(element).to.equal(memKeys2.IDCommitment[index]); |
126 |
| -// }); |
127 |
| -// memKeys1.IDNullifier.forEach((element, index) => { |
128 |
| -// expect(element).to.equal(memKeys2.IDNullifier[index]); |
129 |
| -// }); |
130 |
| -// memKeys1.IDSecretHash.forEach((element, index) => { |
131 |
| -// expect(element).to.equal(memKeys2.IDSecretHash[index]); |
132 |
| -// }); |
133 |
| -// memKeys1.IDTrapdoor.forEach((element, index) => { |
134 |
| -// expect(element).to.equal(memKeys2.IDTrapdoor[index]); |
135 |
| -// }); |
136 |
| -// }); |
137 |
| -// }); |
| 1 | +import { expect } from "chai"; |
| 2 | + |
| 3 | +import { RLNInstance } from "./rln.js"; |
| 4 | + |
| 5 | +describe("js-rln", () => { |
| 6 | + // it("should verify a proof", async function () { |
| 7 | + // const rlnInstance = await createRLN(); |
| 8 | + |
| 9 | + // const credential = rlnInstance.zerokit.generateIdentityCredentials(); |
| 10 | + |
| 11 | + // //peer's index in the Merkle Tree |
| 12 | + // const index = 5; |
| 13 | + |
| 14 | + // // Create a Merkle tree with random members |
| 15 | + // for (let i = 0; i < 10; i++) { |
| 16 | + // if (i == index) { |
| 17 | + // // insert the current peer's pk |
| 18 | + // rlnInstance.zerokit.insertMember(credential.IDCommitment); |
| 19 | + // } else { |
| 20 | + // // create a new key pair |
| 21 | + // rlnInstance.zerokit.insertMember( |
| 22 | + // rlnInstance.zerokit.generateIdentityCredentials().IDCommitment |
| 23 | + // ); |
| 24 | + // } |
| 25 | + // } |
| 26 | + |
| 27 | + // // prepare the message |
| 28 | + // const uint8Msg = Uint8Array.from( |
| 29 | + // "Hello World".split("").map((x) => x.charCodeAt(0)) |
| 30 | + // ); |
| 31 | + |
| 32 | + // // setting up the epoch |
| 33 | + // const epoch = new Date(); |
| 34 | + |
| 35 | + // // generating proof |
| 36 | + // const proof = await rlnInstance.zerokit.generateRLNProof( |
| 37 | + // uint8Msg, |
| 38 | + // index, |
| 39 | + // epoch, |
| 40 | + // credential.IDSecretHash |
| 41 | + // ); |
| 42 | + |
| 43 | + // try { |
| 44 | + // // verify the proof |
| 45 | + // const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
| 46 | + // expect(verifResult).to.be.true; |
| 47 | + // } catch (err) { |
| 48 | + // assert.fail(0, 1, "should not have failed proof verification"); |
| 49 | + // } |
| 50 | + |
| 51 | + // try { |
| 52 | + // // Modifying the signal so it's invalid |
| 53 | + // uint8Msg[4] = 4; |
| 54 | + // // verify the proof |
| 55 | + // const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
| 56 | + // expect(verifResult).to.be.false; |
| 57 | + // } catch (err) { |
| 58 | + // console.log(err); |
| 59 | + // } |
| 60 | + // }); |
| 61 | + // it("should verify a proof with a seeded membership key generation", async function () { |
| 62 | + // const rlnInstance = await createRLN(); |
| 63 | + // const seed = "This is a test seed"; |
| 64 | + // const credential = |
| 65 | + // rlnInstance.zerokit.generateSeededIdentityCredential(seed); |
| 66 | + |
| 67 | + // //peer's index in the Merkle Tree |
| 68 | + // const index = 5; |
| 69 | + |
| 70 | + // // Create a Merkle tree with random members |
| 71 | + // for (let i = 0; i < 10; i++) { |
| 72 | + // if (i == index) { |
| 73 | + // // insert the current peer's pk |
| 74 | + // rlnInstance.zerokit.insertMember(credential.IDCommitment); |
| 75 | + // } else { |
| 76 | + // // create a new key pair |
| 77 | + // rlnInstance.zerokit.insertMember( |
| 78 | + // rlnInstance.zerokit.generateIdentityCredentials().IDCommitment |
| 79 | + // ); |
| 80 | + // } |
| 81 | + // } |
| 82 | + |
| 83 | + // // prepare the message |
| 84 | + // const uint8Msg = Uint8Array.from( |
| 85 | + // "Hello World".split("").map((x) => x.charCodeAt(0)) |
| 86 | + // ); |
| 87 | + |
| 88 | + // // setting up the epoch |
| 89 | + // const epoch = new Date(); |
| 90 | + |
| 91 | + // // generating proof |
| 92 | + // const proof = await rlnInstance.zerokit.generateRLNProof( |
| 93 | + // uint8Msg, |
| 94 | + // index, |
| 95 | + // epoch, |
| 96 | + // credential.IDSecretHash |
| 97 | + // ); |
| 98 | + |
| 99 | + // try { |
| 100 | + // // verify the proof |
| 101 | + // const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
| 102 | + // expect(verifResult).to.be.true; |
| 103 | + // } catch (err) { |
| 104 | + // assert.fail(0, 1, "should not have failed proof verification"); |
| 105 | + // } |
| 106 | + |
| 107 | + // try { |
| 108 | + // // Modifying the signal so it's invalid |
| 109 | + // uint8Msg[4] = 4; |
| 110 | + // // verify the proof |
| 111 | + // const verifResult = rlnInstance.zerokit.verifyRLNProof(proof, uint8Msg); |
| 112 | + // expect(verifResult).to.be.false; |
| 113 | + // } catch (err) { |
| 114 | + // console.log(err); |
| 115 | + // } |
| 116 | + // }); |
| 117 | + |
| 118 | + it.only("should generate the same membership key if the same seed is provided", async function () { |
| 119 | + const rlnInstance = await RLNInstance.create(); |
| 120 | + |
| 121 | + console.log("rlnInstance", rlnInstance); |
| 122 | + const seed = "This is a test seed"; |
| 123 | + const memKeys1 = rlnInstance.zerokit.generateSeededIdentityCredential(seed); |
| 124 | + console.log("memKeys1", memKeys1); |
| 125 | + const memKeys2 = rlnInstance.zerokit.generateSeededIdentityCredential(seed); |
| 126 | + |
| 127 | + memKeys1.IDCommitment.forEach((element, index) => { |
| 128 | + expect(element).to.equal(memKeys2.IDCommitment[index]); |
| 129 | + }); |
| 130 | + memKeys1.IDNullifier.forEach((element, index) => { |
| 131 | + expect(element).to.equal(memKeys2.IDNullifier[index]); |
| 132 | + }); |
| 133 | + memKeys1.IDSecretHash.forEach((element, index) => { |
| 134 | + expect(element).to.equal(memKeys2.IDSecretHash[index]); |
| 135 | + }); |
| 136 | + memKeys1.IDTrapdoor.forEach((element, index) => { |
| 137 | + expect(element).to.equal(memKeys2.IDTrapdoor[index]); |
| 138 | + }); |
| 139 | + }); |
| 140 | +}); |
0 commit comments