diff --git a/.env.example b/.env.example index 9c87309..05ffb51 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,11 @@ MYSQL_DATABASE=phase2 TWITTER_CONSUMER_KEY= TWITTER_CONSUMER_SECRET= TWITTER_CALLBACK_URL=https://ceremony.tornado.cash/api/oauth_callback/twitter +TWITTER_ACCESS_TOKEN_KEY= +TWITTER_ACCESS_TOKEN_SECRET= +# hashtag should be provided without # sign +TWITTER_HASHTAG= +TWITTER_INTERVAL_ATTESTATION=300000 GITHUB_CLIEND_ID= GITHUB_CLIENT_SECRET= diff --git a/Dockerfile b/Dockerfile index af1861f..97814b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,5 +11,4 @@ COPY --from=bin /usr/bin/phase2_verify_contribution /app/server/bin/ EXPOSE 3000 HEALTHCHECK CMD curl -f http://localhost:3000/ -RUN yarn build CMD ["yarn", "start"] diff --git a/assets/styles/app.scss b/assets/styles/app.scss index a31a233..a8236b0 100644 --- a/assets/styles/app.scss +++ b/assets/styles/app.scss @@ -10,6 +10,7 @@ @import 'components/status'; @import 'components/fieldset'; @import 'components/form'; +@import 'components/highlight'; .wrapper { display: flex; diff --git a/assets/styles/components/_base.scss b/assets/styles/components/_base.scss index 652a255..d0db859 100644 --- a/assets/styles/components/_base.scss +++ b/assets/styles/components/_base.scss @@ -10,6 +10,7 @@ $warning: #ff8a00; $black: #2c4538; $danger: #FF0658; $dark: #242424; +$pre: $white; $info: $primary-invert; $info-invert: $white; $custom-colors: ("black": ($black, $primary-invert)); @@ -159,6 +160,8 @@ $pagination-current-color: $primary-invert; $pagination-current-background-color: $primary; $pagination-current-border-color: $primary; +$pre-background: rgba($primary, 0.104); + .columns { @include from(576px) { &.is-small { diff --git a/assets/styles/components/_ceremony.scss b/assets/styles/components/_ceremony.scss index 71ec776..15524b4 100644 --- a/assets/styles/components/_ceremony.scss +++ b/assets/styles/components/_ceremony.scss @@ -25,6 +25,10 @@ text-decoration: underline; } } + + ul { + list-style: none; + } } .columns:not(:last-child) { @@ -79,6 +83,7 @@ .box { background-color: $primary-invert; border-color: #393939; + cursor: inherit; .title { color: $white; @@ -133,6 +138,16 @@ display: none; } } + + &.has-addons .control { + &:not(:last-child) { + z-index: 1; + } + + &:last-child { + z-index: 10; + } + } } .currently { @@ -148,4 +163,15 @@ margin-bottom: $block-spacing; } } + + > .buttons { + &:not(:last-child) { + margin-bottom: 0; + } + + .button { + margin-bottom: 2rem; + } + } + } diff --git a/assets/styles/components/_highlight.scss b/assets/styles/components/_highlight.scss new file mode 100644 index 0000000..271dd23 --- /dev/null +++ b/assets/styles/components/_highlight.scss @@ -0,0 +1,5 @@ +.hljs-comment, +.hljs-quote { + color: $primary; + font-style: italic; +} diff --git a/components/Navbar.vue b/components/Navbar.vue index 8912d8a..65882c5 100644 --- a/components/Navbar.vue +++ b/components/Navbar.vue @@ -6,7 +6,7 @@ diff --git a/pages/make-contribution.vue b/pages/make-contribution.vue index 322434f..f66b360 100644 --- a/pages/make-contribution.vue +++ b/pages/make-contribution.vue @@ -30,6 +30,19 @@
{{ status.msg }}
+
+
Your contribution hash (Blake2b)
+ + +

+ Copy +

+
+
+
+ You still can authorize your contribution by following this + link. +
- Tweet about your contribution + Post attestation

- If you don’t trust binaries, we encorage you to follow this instruction to - contribute by compiling from source code. It is very easy! + If you don’t trust binaries, we encorage you to follow this + instruction to contribute by compiling from + source code. It is very easy!

@@ -77,7 +91,9 @@ export default { status: { type: '', msg: '' - } + }, + contributionHash: null, + authorizeLink: null } }, computed: { @@ -160,13 +176,16 @@ export default { body: formData }) if (resp.ok) { - this.status.msg = 'Your contribution is verified and recorded. Thank you.' - this.status.type = 'is-success' const responseData = await resp.json() this.$store.commit('user/SET_CONTRIBUTION_INDEX', responseData.contributionIndex) - console.log( - `${window.location.origin}/authorize-contribution?token=${responseData.token}` - ) + this.status.msg = 'Your contribution is verified and recorded.' + this.status.type = 'is-success' + this.contributionHash = responseData.hash + if (this.contributionType === 'anonymous') { + this.authorizeLink = `${window.location.origin}/authorize-contribution?token=${responseData.token}` + } else { + this.status.msg += ' Now you can post attestation from your twitter account.' + } } else if (resp.status === 422) { if (retry < 3) { console.log(`Looks like someone else uploaded contribution ahead of us, retrying`) @@ -193,6 +212,14 @@ export default { onAnonymousHandler() { this.logOut() this.contributionType = 'anonymous' + }, + copyContributionHash() { + navigator.clipboard.writeText(this.contributionHash).then(() => { + this.$buefy.toast.open({ + message: 'Copied!', + type: 'is-primary' + }) + }) } } } diff --git a/plugins/highlight.js b/plugins/highlight.js new file mode 100644 index 0000000..bf321ba --- /dev/null +++ b/plugins/highlight.js @@ -0,0 +1,4 @@ +import Vue from 'vue' +import VueHighlightJS from 'vue-highlightjs' + +Vue.use(VueHighlightJS) diff --git a/server/attestationWatcher.js b/server/attestationWatcher.js new file mode 100644 index 0000000..ccdbdec --- /dev/null +++ b/server/attestationWatcher.js @@ -0,0 +1,98 @@ +const fs = require('fs') +const Twitter = require('twitter') + +const { + TWITTER_CONSUMER_KEY, + TWITTER_CONSUMER_SECRET, + TWITTER_ACCESS_TOKEN_KEY, + TWITTER_ACCESS_TOKEN_SECRET, + TWITTER_HASHTAG, + TWITTER_INTERVAL_ATTESTATION, + NODE_ENV +} = process.env + +const client = new Twitter({ + consumer_key: TWITTER_CONSUMER_KEY, + consumer_secret: TWITTER_CONSUMER_SECRET, + access_token_key: TWITTER_ACCESS_TOKEN_KEY, + access_token_secret: TWITTER_ACCESS_TOKEN_SECRET +}) + +const { Contribution } = require('./models') + +function attestationWatcher() { + // get the last saved tweet + let initTweet + try { + initTweet = require('/tmp/lastTweet.json').lastTweet + } catch (e) { + initTweet = 0 + } + + const params = { + since_id: initTweet, + q: `#${TWITTER_HASHTAG} -filter:retweets`, + result_type: 'recent', + count: 100 + } + + // search tweets with params + client.get('search/tweets', params, async function(error, tweets, response) { + if (!error) { + for (const tweet of tweets.statuses) { + if (NODE_ENV === 'development') { + console.log( + '\x1B[36m%s\x1B[0m', + `${tweet.text} https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}` + ) + } + + // find the contribution id in a tweet + let matchTweetContributionId = null + let tweetContributionId = null + + if ((matchTweetContributionId = tweet.text.match(/#([0-9]+)/))) { + tweetContributionId = Number(matchTweetContributionId[1]) + } + + // if found the contribution id then search a contribution + if (tweetContributionId) { + // try update the database record by id + try { + const result = await Contribution.update( + { attestation: tweet.id_str }, + { + where: { + id: tweetContributionId, + handle: tweet.user.screen_name, + attestation: null + } + } + ) + if (result[0]) { + console.log( + `Succesful attestation #${tweetContributionId} https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}` + ) + } + } catch (error) { + console.error(error) + } + } + } + + // save the last tweet received + fs.writeFileSync( + '/tmp/lastTweet.json', + JSON.stringify({ lastTweet: tweets.search_metadata.max_id_str }) + ) + } else { + console.error('attestationWatcher error', error) + } + }) + + setTimeout(() => { + attestationWatcher() + }, TWITTER_INTERVAL_ATTESTATION) +} + +module.exports = attestationWatcher diff --git a/server/controllers/authorize.js b/server/controllers/authorize.js index 003086a..3463e00 100644 --- a/server/controllers/authorize.js +++ b/server/controllers/authorize.js @@ -34,6 +34,7 @@ const github = new oauth.OAuth2( 'login/oauth/authorize', 'login/oauth/access_token' ) +github.useAuthorizationHeaderforGET(true) function validateProvider(req, res, next) { const { provider } = req.params @@ -175,6 +176,7 @@ router.get('/user_data/', (req, res) => { router.get('/logout', (req, res) => { req.session.destroy() + res.send('OK') }) module.exports = router diff --git a/server/controllers/contribute.js b/server/controllers/contribute.js index 99870e8..71d1c9f 100644 --- a/server/controllers/contribute.js +++ b/server/controllers/contribute.js @@ -8,6 +8,7 @@ const aws = require('aws-sdk') const express = require('express') const { Mutex } = require('async-mutex') const multer = require('multer') +const blake2 = require('blake2') const mutex = new Mutex() const s3 = new aws.S3() @@ -46,9 +47,9 @@ router.get('/challenge', (req, res) => { router.get('/contributions', async (req, res) => { const contributions = await Contribution.findAll({ - attributes: ['id', 'name', 'company', 'handle', 'socialType'] + attributes: ['id', 'name', 'company', 'handle', 'socialType', 'attestation'] }) - res.json(contributions).send() + res.json(contributions) }) router.post('/response', upload.single('response'), async (req, res) => { @@ -83,7 +84,12 @@ router.post('/response', upload.single('response'), async (req, res) => { token = crypto.randomBytes(32).toString('hex') } - await Contribution.create({ name, company, handle, socialType, token }) + 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 }) console.log('Contribution is correct, uploading to storage') if (process.env.DISABLE_S3 !== 'true') { @@ -97,8 +103,8 @@ router.post('/response', upload.single('response'), async (req, res) => { `./server/snark_files/response_${contributionIndex}` ) - console.log('Finished') - res.json({ contributionIndex, token }) + console.log('Finished. The hash of the contribution is', hash) + res.json({ contributionIndex, token, hash }) } catch (e) { console.error('Got error during save', e) await fs.unlink(`/tmp/tornado/${req.file.filename}`) @@ -136,14 +142,13 @@ router.post('/authorize_contribution', async (req, res) => { handle: req.session.handle, socialType: req.session.socialType }, - { individualHooks: true, where: { token: req.body.token }, returning: true } + { where: { id: contribution.dataValues.id }, individualHooks: true } ) + res.send('OK') } catch (e) { console.error('updateError', e) res.status(404).send('Update error') } - - res.send('OK') }) router.post('/get_contribution_index', async (req, res) => { diff --git a/server/index.js b/server/index.js index 7c67efb..d38141c 100644 --- a/server/index.js +++ b/server/index.js @@ -9,23 +9,18 @@ const config = require('../nuxt.config.js') const sessionsController = require('./controllers/authorize') const contributionController = require('./controllers/contribute') const models = require('./models') +const attestationWatcher = require('./attestationWatcher') const app = express() async function start() { - config.dev = NODE_ENV !== 'production' await models.sequelize.sync() const nuxt = new Nuxt(config) - const { host, port } = nuxt.options.server - // Build only in dev mode - if (config.dev) { - const builder = new Builder(nuxt) - await builder.build() - } else { - await nuxt.ready() - } + const builder = new Builder(nuxt) + await builder.build() + app.use( session({ secret: process.env.SESSION_SECRET, @@ -50,5 +45,8 @@ async function start() { app.listen(port, host, () => { console.log(`Server is running on port ${port}.`) }) + + attestationWatcher() + console.log('attestationWatcher started') } start() diff --git a/server/models/contribution.js b/server/models/contribution.js index 839ee5b..0162dbb 100644 --- a/server/models/contribution.js +++ b/server/models/contribution.js @@ -24,7 +24,8 @@ module.exports = (sequelize, DataTypes) => { company: DataTypes.STRING, handle: DataTypes.STRING, socialType: DataTypes.STRING, - hash: DataTypes.STRING + hash: DataTypes.STRING, + attestation: DataTypes.STRING }, { hooks: { diff --git a/store/user.js b/store/user.js index 1d209e3..d29a50c 100644 --- a/store/user.js +++ b/store/user.js @@ -53,7 +53,7 @@ const actions = { window.location.replace(`/api/connect/${provider}`) }, makeTweet({ state }) { - const tweetText = `Just made the contribution %23${state.contributionIndex} to Tornado.cash Trusted Setup Ceremony! 🚀` + const tweetText = `Just made the contribution %23${state.contributionIndex} to @TornadoCash Trusted Setup Ceremony! 🚀 %23${process.env.hashtag}` const popUpWindowWidth = 600 const popUpWindowHeight = 250 const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX diff --git a/yarn.lock b/yarn.lock index 0eb68c0..5a48bb5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1799,6 +1799,13 @@ bindings@^1.5.0: dependencies: file-uri-to-path "1.0.0" +blake2@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/blake2/-/blake2-4.0.0.tgz#32ae4c3568ef5ee4d74c50b99d774abf8fff4f60" + integrity sha512-PIOc6RXAZYBYcdpyMzI6/SCU3BH8EbmA9vr0BAVyQv48CQTXDN6viHOTM+8KQue2IPsyHNpIR3UDisz8rZDPTA== + dependencies: + nan "^2.14.0" + block-stream@*: version "0.0.9" resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" @@ -3004,6 +3011,11 @@ decode-uri-component@^0.2.0: resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU= +deep-extend@^0.5.0: + version "0.5.1" + resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.5.1.tgz#b894a9dd90d3023fbf1c55a394fb858eb2066f1f" + integrity sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w== + deep-extend@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" @@ -4308,7 +4320,7 @@ har-schema@^2.0.0: resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" integrity sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI= -har-validator@~5.1.0: +har-validator@~5.1.0, har-validator@~5.1.3: version "5.1.3" resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.1.3.tgz#1ef89ebd3e4996557675eed9893110dc350fa080" integrity sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g== @@ -4436,6 +4448,11 @@ hex-color-regex@^1.1.0: resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e" integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ== +highlight.js@*: + version "9.18.1" + resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.1.tgz#ed21aa001fe6252bb10a3d76d47573c6539fe13c" + integrity sha512-OrVKYz70LHsnCgmbXctv/bfuvntIKDz177h0Co37DQ5jamGZLVmoCVMtjMtNZY3X9DrCcKfklHPNeA0uPZhSJg== + hmac-drbg@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" @@ -5877,7 +5894,7 @@ named-placeholders@^1.1.2: dependencies: lru-cache "^4.1.3" -nan@^2.12.1, nan@^2.13.2: +nan@^2.12.1, nan@^2.13.2, nan@^2.14.0: version "2.14.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== @@ -7405,7 +7422,7 @@ pseudomap@^1.0.2: resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM= -psl@^1.1.24: +psl@^1.1.24, psl@^1.1.28: version "1.7.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.7.0.tgz#f1c4c47a8ef97167dea5d6bbf4816d736e884a3c" integrity sha512-5NsSEDv8zY70ScRnOTn7bK7eanl2MvFrOrS/R6x+dBt5g1ghnj9Zv90kO8GwT8gxcu2ANyFprnFYB85IogIJOQ== @@ -7462,7 +7479,7 @@ punycode@^1.2.4, punycode@^1.4.1: resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" integrity sha1-wNWmOycYgArY4esPpSachN1BhF4= -punycode@^2.1.0: +punycode@^2.1.0, punycode@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== @@ -7768,6 +7785,32 @@ repeating@^2.0.0: dependencies: is-finite "^1.0.0" +request@^2.72.0: + version "2.88.2" + resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3" + integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw== + dependencies: + aws-sign2 "~0.7.0" + aws4 "^1.8.0" + caseless "~0.12.0" + combined-stream "~1.0.6" + extend "~3.0.2" + forever-agent "~0.6.1" + form-data "~2.3.2" + har-validator "~5.1.3" + http-signature "~1.2.0" + is-typedarray "~1.0.0" + isstream "~0.1.2" + json-stringify-safe "~5.0.1" + mime-types "~2.1.19" + oauth-sign "~0.9.0" + performance-now "^2.1.0" + qs "~6.5.2" + safe-buffer "^5.1.2" + tough-cookie "~2.5.0" + tunnel-agent "^0.6.0" + uuid "^3.3.2" + request@^2.87.0, request@^2.88.0: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" @@ -8896,6 +8939,14 @@ tough-cookie@~2.4.3: psl "^1.1.24" punycode "^1.4.1" +tough-cookie@~2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2" + integrity sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g== + dependencies: + psl "^1.1.28" + punycode "^2.1.1" + trim-newlines@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613" @@ -8935,6 +8986,14 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= +twitter@^1.7.1: + version "1.7.1" + resolved "https://registry.yarnpkg.com/twitter/-/twitter-1.7.1.tgz#0762378f1dc1c050e48f666aca904e24b1a962f4" + integrity sha1-B2I3jx3BwFDkj2ZqypBOJLGpYvQ= + dependencies: + deep-extend "^0.5.0" + request "^2.72.0" + type-check@~0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" @@ -9300,6 +9359,13 @@ vue-eslint-parser@^7.0.0: esquery "^1.0.1" lodash "^4.17.15" +vue-highlightjs@^1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/vue-highlightjs/-/vue-highlightjs-1.3.3.tgz#29a0d57132fc1ce15cfa61e896918f5b718c5d52" + integrity sha1-KaDVcTL8HOFc+mHolpGPW3GMXVI= + dependencies: + highlight.js "*" + vue-hot-reload-api@^2.3.0: version "2.3.4" resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz#532955cc1eb208a3d990b3a9f9a70574657e08f2"