mirror of
https://github.com/tornadocash/phase2-wasm.git
synced 2024-11-23 10:27:21 +01:00
improve randomness
This commit is contained in:
parent
782d425e24
commit
ae122a0c8d
18
js/index.js
18
js/index.js
@ -3,10 +3,22 @@ import("../pkg/index.js").catch(console.error);
|
|||||||
async function main() {
|
async function main() {
|
||||||
const pkg = await import("../pkg/index.js")
|
const pkg = await import("../pkg/index.js")
|
||||||
console.log('Downloading previous contribution from /params.bin')
|
console.log('Downloading previous contribution from /params.bin')
|
||||||
let params = await fetch('params.bin')
|
const params = await fetch('params.bin')
|
||||||
params = new Uint8Array(await params.arrayBuffer())
|
params = new Uint8Array(await params.arrayBuffer())
|
||||||
const entropy = new Uint8Array(32)
|
|
||||||
window.crypto.getRandomValues(entropy)
|
const userInput = prompt('Please enter some random symbols')
|
||||||
|
if (!userInput.length) {
|
||||||
|
throw new Error('Zero symbols entered')
|
||||||
|
}
|
||||||
|
const msgBuffer = new TextEncoder('utf-8').encode(userInput)
|
||||||
|
const hashBuffer = await window.crypto.subtle.digest('SHA-256', msgBuffer)
|
||||||
|
const entropyFromUser = new Uint8Array(hashBuffer)
|
||||||
|
const entropyFromBrowser = window.crypto.getRandomValues(new Uint8Array(32))
|
||||||
|
const entropy = new Uint8Array(entropyFromBrowser.length)
|
||||||
|
for (let i = 0; i < entropyFromBrowser.length; i++) {
|
||||||
|
entropy[i] = entropyFromBrowser[i] ^ entropyFromUser[i]
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Contributing with entropy', entropy) // shouldn't be logged on prod
|
console.log('Contributing with entropy', entropy) // shouldn't be logged on prod
|
||||||
const result = pkg.contribute(params, entropy)
|
const result = pkg.contribute(params, entropy)
|
||||||
console.log('Your contribution', result)
|
console.log('Your contribution', result)
|
||||||
|
Loading…
Reference in New Issue
Block a user