From 2700cb2792edc8134b4e459f0221b31b9bd77681 Mon Sep 17 00:00:00 2001 From: jude Date: Mon, 10 Apr 2023 22:23:06 +0100 Subject: [PATCH] add crypto shuffle --- static/js/modules/interface/proofs.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/static/js/modules/interface/proofs.js b/static/js/modules/interface/proofs.js index 9868111..ada55cd 100644 --- a/static/js/modules/interface/proofs.js +++ b/static/js/modules/interface/proofs.js @@ -1,13 +1,30 @@ +// Fisher-Yates shuffle function cryptoShuffle(l) { - for (let i = 0; i < l.length - 1; i++) {} + 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; } window.cryptoShuffle = cryptoShuffle; function proveRegions(regions) { // Construct prover coins + let coins = []; + let regionNames = Object.keys(regions.keys()); - let psi = [regionNames]; + for (let x = 0; x < 20; x++) { + let psi = cryptoShuffle(regionNames).join(""); + } // Construct verifier coins let hasher = new jsSHA("SHA3-256", "TEXT");