Riskless/static/js/modules/interface/proofs.js

39 lines
858 B
JavaScript
Raw Normal View History

2023-04-13 12:32:29 +00:00
/**
* CSPRNG Fisher-Yates shuffle.
*
* Only works on lists up to 255 elements.
*/
2023-04-10 18:05:10 +00:00
function cryptoShuffle(l) {
2023-04-10 21:23:06 +00:00
for (let i = l.length - 1; i > 0; i--) {
let value = new Uint8Array([0]);
crypto.getRandomValues(value);
while (value[0] > i) {
crypto.getRandomValues(value);
}
let temp = l[i];
l[i] = l[value[0]];
l[value[0]] = temp;
}
return l;
2023-04-10 18:05:10 +00:00
}
window.cryptoShuffle = cryptoShuffle;
function proveRegions(regions) {
// Construct prover coins
2023-04-10 21:23:06 +00:00
let coins = [];
2023-04-10 18:05:10 +00:00
let regionNames = Object.keys(regions.keys());
2023-04-10 21:23:06 +00:00
for (let x = 0; x < 20; x++) {
let psi = cryptoShuffle(regionNames).join("");
}
2023-04-10 18:05:10 +00:00
// Construct verifier coins
let hasher = new jsSHA("SHA3-256", "TEXT");
hasher.update(JSON.stringify(regions));
// Construct prover proofs
}