-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
35 lines (23 loc) · 1.09 KB
/
test.js
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
const fs = require('fs');
const contribute = require('./contribution/contribution.js');
const conversion = require('./contribution/conversion.js');
// const data = fs.readFileSync('./test/try_contribute_partial.json');
const data = fs.readFileSync('./test/try_contribute.json');
const obj = JSON.parse(data);
// TODO: How to create randoms?
console.log('Loading...');
contributions = conversion.decode(obj.contributions);
console.log('Loaded!!!', contributions);
const randValue = Math.floor(Math.random() * 100000);
console.log('Create new contribution...');
newContributions = contribute.contribute(contributions, BigInt(randValue));
console.log('New Contributions', newContributions);
console.log('Sample power', newContributions[0].powersOfTau.G1Powers[0]);
newContributions = contribute.updateWitness(newContributions, BigInt(randValue));
console.log('Convert back...');
newContributions = conversion.encode(newContributions);
// Store for compare.
jsonDump = JSON.stringify(newContributions, null, '\t');
fs.writeFile('./dump.json', jsonDump, (err) => {
console.log('Write error', err);
});