diff --git a/lib/phase2/phase2_bg.wasm b/lib/phase2/phase2_bg.wasm index 01ee364..8c1e2d7 100644 Binary files a/lib/phase2/phase2_bg.wasm and b/lib/phase2/phase2_bg.wasm differ diff --git a/pages/make-contribution.vue b/pages/make-contribution.vue index d3db99d..78f89c8 100644 --- a/pages/make-contribution.vue +++ b/pages/make-contribution.vue @@ -82,6 +82,12 @@ import { mapGetters, mapActions } from 'vuex' import Cloak from '@/components/Cloak' import Form from '@/components/Form' const timeout = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) +function buf2hex(buffer) { + // buffer is an ArrayBuffer + return Array.prototype.map + .call(new Uint8Array(buffer), (x) => ('00' + x.toString(16)).slice(-2)) + .join('') +} export default { components: { @@ -183,12 +189,12 @@ export default { let msgBuffer = new TextEncoder('utf-8').encode(userInput) let hashBuffer = await window.crypto.subtle.digest('SHA-256', msgBuffer) const entropyFromUser = new Uint8Array(hashBuffer) - console.log('entropyFromUser', entropyFromUser.toString()) + // console.log('entropyFromUser', entropyFromUser.toString()) msgBuffer = window.crypto.getRandomValues(new Uint8Array(1024)) hashBuffer = await window.crypto.subtle.digest('SHA-256', msgBuffer) const entropyFromBrowser = new Uint8Array(hashBuffer) - console.log('entropyFromBrowser', entropyFromBrowser.toString()) + // console.log('entropyFromBrowser', entropyFromBrowser.toString()) // suffle the browser and user random const entropy = new Uint8Array(entropyFromBrowser.length) @@ -196,14 +202,19 @@ export default { entropy[i] = entropyFromBrowser[i] + entropyFromUser[i] } - console.log('entropy', entropy) + // console.log('entropy', entropy) await this.sleep(100) // so browser can render the messages const result = contribute(data, entropy) console.log('Updated params', result) + const hash = '0x' + buf2hex(result.slice(0, 64)) + const contribution = result.slice(64) + + console.log('hash', hash) + console.log('contribution', contribution) this.$root.$emit('enableLoading', 'Uploading and verifying your contribution') const formData = new FormData() - formData.append('response', new Blob([result], { type: 'application/octet-stream' })) + formData.append('response', new Blob([contribution], { type: 'application/octet-stream' })) if (this.contributionType !== 'anonymous') { formData.append('name', this.userName) formData.append('company', this.userCompany) @@ -217,7 +228,7 @@ export default { this.$store.commit('user/SET_CONTRIBUTION_INDEX', responseData.contributionIndex) this.status.msg = 'Your contribution is verified and recorded.' this.status.type = 'is-success' - this.contributionHash = responseData.hash + this.contributionHash = hash if (this.contributionType === 'anonymous') { this.authorizeLink = `${window.location.origin}/authorize-contribution?token=${responseData.token}` } diff --git a/server/controllers/contribute.js b/server/controllers/contribute.js index ac1eab7..e6bede6 100644 --- a/server/controllers/contribute.js +++ b/server/controllers/contribute.js @@ -84,12 +84,7 @@ router.post('/response', upload.single('response'), async (req, res) => { token = crypto.randomBytes(32).toString('hex') } - const contribution = await fs.readFile(`/tmp/tornado/${req.file.filename}`) - const blake2Instance = blake2.createHash('blake2b') - blake2Instance.update(contribution) - const hash = '0x' + blake2Instance.digest('hex') - - await Contribution.create({ name, company, handle, socialType, token, hash }) + await Contribution.create({ name, company, handle, socialType, token }) console.log('Contribution is correct, uploading to storage') if (process.env.DISABLE_S3 !== 'true') { @@ -103,8 +98,8 @@ router.post('/response', upload.single('response'), async (req, res) => { `./server/snark_files/response_${contributionIndex}` ) - console.log('Finished. The hash of the contribution is', hash) - res.json({ contributionIndex, token, hash }) + console.log('Contribution finished.') + res.json({ contributionIndex, token }) } catch (e) { console.error('Got error during save', e) res.status(503).send(e.toString()) diff --git a/server/models/contribution.js b/server/models/contribution.js index 0162dbb..f81360b 100644 --- a/server/models/contribution.js +++ b/server/models/contribution.js @@ -24,7 +24,6 @@ module.exports = (sequelize, DataTypes) => { company: DataTypes.STRING, handle: DataTypes.STRING, socialType: DataTypes.STRING, - hash: DataTypes.STRING, attestation: DataTypes.STRING }, { diff --git a/static/_nuxt/lib/phase2/phase2_bg.wasm b/static/_nuxt/lib/phase2/phase2_bg.wasm index 01ee364..8c1e2d7 100644 Binary files a/static/_nuxt/lib/phase2/phase2_bg.wasm and b/static/_nuxt/lib/phase2/phase2_bg.wasm differ