From e2199c1a952d020dcb0ba06511148bb78452b9cf Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Wed, 26 Feb 2020 00:13:09 +1000 Subject: [PATCH 01/16] attestation watcher --- .env.example | 4 ++ package.json | 3 +- pages/index.vue | 4 +- server/attestationWatcher.js | 78 ++++++++++++++++++++++++++++++++ server/controllers/contribute.js | 4 +- server/index.js | 4 ++ server/models/contribution.js | 3 +- yarn.lock | 53 ++++++++++++++++++++-- 8 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 server/attestationWatcher.js diff --git a/.env.example b/.env.example index 9c87309..67f864d 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,10 @@ 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= +TWITTER_HASHTAG= +TWITTER_INTERVAL_ATTESTATION=300000 GITHUB_CLIEND_ID= GITHUB_CLIENT_SECRET= diff --git a/package.json b/package.json index f088f47..712f932 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "nuxt": "^2.0.0", "nuxt-buefy": "^0.3.2", "oauth": "^0.9.15", - "sequelize": "^5.21.3" + "sequelize": "^5.21.3", + "twitter": "^1.7.1" }, "devDependencies": { "@nuxtjs/eslint-config": "^1.0.1", diff --git a/pages/index.vue b/pages/index.vue index 90da205..fcfeab4 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -57,7 +57,9 @@ diff --git a/server/attestationWatcher.js b/server/attestationWatcher.js new file mode 100644 index 0000000..ee66528 --- /dev/null +++ b/server/attestationWatcher.js @@ -0,0 +1,78 @@ +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 +} = 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') + +async function attestationWatcher() { + // get the last saved tweet + let initTweet + try { + initTweet = require('/tmp/lastTweet.json').lastTweet + } catch (e) { + initTweet = process.env.LAST_TWEET + } + + // get all contributions without attestation + const contributions = await Contribution.findAll({ + where: { + socialType: 'twitter', + attestation: null + }, + attributes: ['id', 'handle', 'socialType', 'attestation'] + }) + + const params = { + since_id: initTweet, + q: `#${TWITTER_HASHTAG} -filter:retweets`, + result_type: 'recent', + count: 100 + } + + // search tweets with params + client.get('search/tweets', params, function(error, tweets, response) { + if (!error) { + tweets.statuses.forEach((tweet) => { + contributions.forEach((contribution) => { + // compare account compliance + if (contribution.handle === tweet.user.screen_name) { + // update the database record by id + Contribution.update({ attestation: tweet.id_str }, { where: { id: contribution.id } }) + console.log( + `Succesful attestation https://${contribution.socialType}.com/${contribution.handle}/status/${tweet.id_str}` + ) + } + }) + }) + + // 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/contribute.js b/server/controllers/contribute.js index 99870e8..c2375c6 100644 --- a/server/controllers/contribute.js +++ b/server/controllers/contribute.js @@ -46,9 +46,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) => { diff --git a/server/index.js b/server/index.js index 7c67efb..d3d345c 100644 --- a/server/index.js +++ b/server/index.js @@ -9,6 +9,7 @@ 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() @@ -50,5 +51,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/yarn.lock b/yarn.lock index 0eb68c0..01828c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3004,6 +3004,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 +4313,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== @@ -7405,7 +7410,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 +7467,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 +7773,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 +8927,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 +8974,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" From 627490bbe6d901a827dccc7f98bdb724550fb56a Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 28 Feb 2020 10:57:30 +0300 Subject: [PATCH 02/16] pass hashtag to tweet text --- .env.example | 3 ++- server/attestationWatcher.js | 4 ++-- store/user.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 67f864d..4e6c925 100644 --- a/.env.example +++ b/.env.example @@ -12,7 +12,8 @@ TWITTER_CONSUMER_SECRET= TWITTER_CALLBACK_URL=https://ceremony.tornado.cash/api/oauth_callback/twitter TWITTER_ACCESS_TOKEN_KEY= TWITTER_ACCESS_TOKEN_SECRET= -TWITTER_HASHTAG= +# hashtag should be provided without # sign +NUXT_ENV_TWITTER_HASHTAG= TWITTER_INTERVAL_ATTESTATION=300000 GITHUB_CLIEND_ID= diff --git a/server/attestationWatcher.js b/server/attestationWatcher.js index ee66528..eacfa1c 100644 --- a/server/attestationWatcher.js +++ b/server/attestationWatcher.js @@ -6,7 +6,7 @@ const { TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN_KEY, TWITTER_ACCESS_TOKEN_SECRET, - TWITTER_HASHTAG, + NUXT_ENV_TWITTER_HASHTAG, TWITTER_INTERVAL_ATTESTATION } = process.env @@ -39,7 +39,7 @@ async function attestationWatcher() { const params = { since_id: initTweet, - q: `#${TWITTER_HASHTAG} -filter:retweets`, + q: `#${NUXT_ENV_TWITTER_HASHTAG} -filter:retweets`, result_type: 'recent', count: 100 } diff --git a/store/user.js b/store/user.js index 1d209e3..f584d47 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 Tornado.cash Trusted Setup Ceremony! 🚀 %23${process.env.NUXT_ENV_TWITTER_HASHTAG}` const popUpWindowWidth = 600 const popUpWindowHeight = 250 const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX From 27676cabf0a9fbc49a0d7439092bcd525349319f Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 28 Feb 2020 11:23:54 +0300 Subject: [PATCH 03/16] fix bug. Using the `access_token` query parameter is deprecated and will be removed July 1st, 2020. (c) Github --- server/controllers/authorize.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/controllers/authorize.js b/server/controllers/authorize.js index 003086a..87df5e0 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 From 32eb117a0f6ec602bc98c38b9490f3ae456f7793 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 28 Feb 2020 16:38:36 +0300 Subject: [PATCH 04/16] wordings --- pages/authorize-contribution.vue | 4 ++-- pages/make-contribution.vue | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pages/authorize-contribution.vue b/pages/authorize-contribution.vue index 6448073..1e98493 100644 --- a/pages/authorize-contribution.vue +++ b/pages/authorize-contribution.vue @@ -27,7 +27,7 @@ target="_blank" outlined > - Tweet about your contribution + Post attestation
@@ -90,7 +90,7 @@ export default { body: JSON.stringify(body) }) if (response.ok) { - this.status.msg = `Your contribution is verified and authorized. Thank you.` + this.status.msg = `Your contribution authorized. Now you can post attestation from your twitter account.` this.status.type = 'is-success' this.hideSaveBtn = true } else { diff --git a/pages/make-contribution.vue b/pages/make-contribution.vue index 322434f..99ac3d3 100644 --- a/pages/make-contribution.vue +++ b/pages/make-contribution.vue @@ -49,7 +49,7 @@ target="_blank" outlined > - Tweet about your contribution + Post attestation

@@ -160,7 +160,8 @@ export default { body: formData }) if (resp.ok) { - this.status.msg = 'Your contribution is verified and recorded. Thank you.' + this.status.msg = + 'Your contribution is verified and recorded. Now you can post attestation from your twitter account.' this.status.type = 'is-success' const responseData = await resp.json() this.$store.commit('user/SET_CONTRIBUTION_INDEX', responseData.contributionIndex) From 49b87d51b3f55257be5a6852a5cb7984035545d9 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Sat, 29 Feb 2020 14:28:00 +1000 Subject: [PATCH 05/16] hide attestation button -fix button padding -fix response on logout request -fix cursor when disabled fieldset --- assets/styles/components/_ceremony.scss | 12 ++++++++++++ pages/make-contribution.vue | 17 ++++++++++------- server/controllers/authorize.js | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/assets/styles/components/_ceremony.scss b/assets/styles/components/_ceremony.scss index 71ec776..1dd0db7 100644 --- a/assets/styles/components/_ceremony.scss +++ b/assets/styles/components/_ceremony.scss @@ -79,6 +79,7 @@ .box { background-color: $primary-invert; border-color: #393939; + cursor: inherit; .title { color: $white; @@ -148,4 +149,15 @@ margin-bottom: $block-spacing; } } + + > .buttons { + &:not(:last-child) { + margin-bottom: 0; + } + + .button { + margin-bottom: 2rem; + } + } + } diff --git a/pages/make-contribution.vue b/pages/make-contribution.vue index 99ac3d3..86601c2 100644 --- a/pages/make-contribution.vue +++ b/pages/make-contribution.vue @@ -42,7 +42,7 @@ Make the contribution { router.get('/logout', (req, res) => { req.session.destroy() + res.send('OK') }) module.exports = router From ef1693cfeccda51839916ae1758a0184db9c39c6 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Sat, 29 Feb 2020 19:17:53 +1000 Subject: [PATCH 06/16] update logic --- server/attestationWatcher.js | 66 +++++++++++++++++++++++------------- store/user.js | 2 +- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/server/attestationWatcher.js b/server/attestationWatcher.js index eacfa1c..27f668f 100644 --- a/server/attestationWatcher.js +++ b/server/attestationWatcher.js @@ -7,7 +7,8 @@ const { TWITTER_ACCESS_TOKEN_KEY, TWITTER_ACCESS_TOKEN_SECRET, NUXT_ENV_TWITTER_HASHTAG, - TWITTER_INTERVAL_ATTESTATION + TWITTER_INTERVAL_ATTESTATION, + NODE_ENV } = process.env const client = new Twitter({ @@ -19,24 +20,15 @@ const client = new Twitter({ const { Contribution } = require('./models') -async function attestationWatcher() { +function attestationWatcher() { // get the last saved tweet let initTweet try { initTweet = require('/tmp/lastTweet.json').lastTweet } catch (e) { - initTweet = process.env.LAST_TWEET + initTweet = 0 } - // get all contributions without attestation - const contributions = await Contribution.findAll({ - where: { - socialType: 'twitter', - attestation: null - }, - attributes: ['id', 'handle', 'socialType', 'attestation'] - }) - const params = { since_id: initTweet, q: `#${NUXT_ENV_TWITTER_HASHTAG} -filter:retweets`, @@ -45,20 +37,48 @@ async function attestationWatcher() { } // search tweets with params - client.get('search/tweets', params, function(error, tweets, response) { + client.get('search/tweets', params, async function(error, tweets, response) { if (!error) { - tweets.statuses.forEach((tweet) => { - contributions.forEach((contribution) => { - // compare account compliance - if (contribution.handle === tweet.user.screen_name) { - // update the database record by id - Contribution.update({ attestation: tweet.id_str }, { where: { id: contribution.id } }) - console.log( - `Succesful attestation https://${contribution.socialType}.com/${contribution.handle}/status/${tweet.id_str}` + 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( diff --git a/store/user.js b/store/user.js index f584d47..a0dfb88 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! 🚀 %23${process.env.NUXT_ENV_TWITTER_HASHTAG}` + const tweetText = `Just made the contribution %23${state.contributionIndex} to @TornadoCash Trusted Setup Ceremony! 🚀 %23${process.env.NUXT_ENV_TWITTER_HASHTAG}` const popUpWindowWidth = 600 const popUpWindowHeight = 250 const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX From a94a33736343eaaa1118e3a8a489a7d675db3495 Mon Sep 17 00:00:00 2001 From: Alexey Date: Sat, 29 Feb 2020 14:22:45 +0300 Subject: [PATCH 07/16] contribution hash; authorize fix --- package.json | 1 + pages/authorize-contribution.vue | 16 +++++++++++++--- pages/make-contribution.vue | 15 +++++++++++---- server/controllers/contribute.js | 18 ++++++++++++------ yarn.lock | 9 ++++++++- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 712f932..b0451f5 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@open-wc/webpack-import-meta-loader": "^0.4.1", "async-mutex": "^0.1.4", "aws-sdk": "^2.610.0", + "blake2": "^4.0.0", "body-parser": "^1.19.0", "cross-env": "^5.2.0", "crypto": "^1.0.1", diff --git a/pages/authorize-contribution.vue b/pages/authorize-contribution.vue index 1e98493..5e3593d 100644 --- a/pages/authorize-contribution.vue +++ b/pages/authorize-contribution.vue @@ -4,7 +4,7 @@ Hello, @{{ handle }}

- Do you want to authorize your contribution #{{ contributionIndex }}? Please sign in. + {{ title }}

@@ -46,7 +46,7 @@ export default { }, data() { return { - contributionIndex: 1, + contributionIndex: null, token: null, status: { type: '', @@ -57,7 +57,17 @@ export default { }, computed: { ...mapState('user', ['name', 'handle', 'company']), - ...mapGetters('user', ['isLoggedIn', 'hasErrorName']) + ...mapGetters('user', ['isLoggedIn', 'hasErrorName']), + title() { + if (this.status.type === 'is-danger' || !this.contributionIndex) { + return null + } + if (!this.isLoggedIn) { + return `Do you want to authorize your contribution #${this.contributionIndex}? Please sign in.` + } else { + return `Please, specify your name and organization.` + } + } }, async mounted() { this.$root.$emit('enableLoading') diff --git a/pages/make-contribution.vue b/pages/make-contribution.vue index 86601c2..93cd2c1 100644 --- a/pages/make-contribution.vue +++ b/pages/make-contribution.vue @@ -30,6 +30,12 @@
{{ status.msg }}
+
+ Your contribution hash (Blake2b) is {{ contributionHash }} +
+
{ 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}`) @@ -113,6 +119,7 @@ router.post('/authorize_contribution', async (req, res) => { } const contribution = await Contribution.findOne({ where: { token: req.body.token } }) + console.log('contribution', contribution.dataValues.id) if (!contribution) { res.status(404).send('There is no such contribution') return @@ -136,14 +143,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/yarn.lock b/yarn.lock index 01828c7..ffe9c57 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" @@ -5882,7 +5889,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== From 53ddd3464b522b726823cda90abeeb9fa60a37ca Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Sat, 29 Feb 2020 22:47:04 +1000 Subject: [PATCH 08/16] add copy contribution hash button --- assets/styles/components/_ceremony.scss | 10 ++++++++++ pages/index.vue | 2 +- pages/make-contribution.vue | 23 +++++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/assets/styles/components/_ceremony.scss b/assets/styles/components/_ceremony.scss index 1dd0db7..cd397fe 100644 --- a/assets/styles/components/_ceremony.scss +++ b/assets/styles/components/_ceremony.scss @@ -134,6 +134,16 @@ display: none; } } + + &.has-addons .control { + &:not(:last-child) { + z-index: 1; + } + + &:last-child { + z-index: 10; + } + } } .currently { diff --git a/pages/index.vue b/pages/index.vue index fcfeab4..ef074b1 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -99,7 +99,7 @@
{{ status.msg }}
-
- Your contribution hash (Blake2b) is {{ contributionHash }} +
+
Your contribution hash (Blake2b)
+ + +

+ Copy +

+
-
- You still can authorize your contribution by following this link. +
+ You still can authorize your contribution by following this + link.
@@ -204,6 +211,14 @@ export default { onAnonymousHandler() { this.logOut() this.contributionType = 'anonymous' + }, + copyСontributionHash() { + navigator.clipboard.writeText(this.contributionHash).then(() => { + this.$buefy.toast.open({ + message: 'Copied!', + type: 'is-primary' + }) + }) } } } From f4991132c49600654737607eb1631abb37283ee3 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Sat, 29 Feb 2020 22:54:36 +1000 Subject: [PATCH 09/16] fix --- pages/make-contribution.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/make-contribution.vue b/pages/make-contribution.vue index 304203e..ec25ea5 100644 --- a/pages/make-contribution.vue +++ b/pages/make-contribution.vue @@ -35,7 +35,7 @@

- Copy + Copy

@@ -212,7 +212,7 @@ export default { this.logOut() this.contributionType = 'anonymous' }, - copyСontributionHash() { + copyContributionHash() { navigator.clipboard.writeText(this.contributionHash).then(() => { this.$buefy.toast.open({ message: 'Copied!', From f9840388d8899b813cb612a2b5a0b50592cd0930 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Sat, 29 Feb 2020 23:57:47 +1000 Subject: [PATCH 10/16] fix contributionIndex --- pages/authorize-contribution.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pages/authorize-contribution.vue b/pages/authorize-contribution.vue index 5e3593d..4e4a5d6 100644 --- a/pages/authorize-contribution.vue +++ b/pages/authorize-contribution.vue @@ -46,7 +46,6 @@ export default { }, data() { return { - contributionIndex: null, token: null, status: { type: '', @@ -67,6 +66,14 @@ export default { } else { return `Please, specify your name and organization.` } + }, + contributionIndex: { + get() { + return this.$store.state.user.contributionIndex + }, + set(value) { + this.$store.commit('user/SET_CONTRIBUTION_INDEX', value) + } } }, async mounted() { From c725b54d842f4325b24a27a6e4ab50a79f3d21c4 Mon Sep 17 00:00:00 2001 From: Alexey Date: Sat, 29 Feb 2020 17:38:13 +0300 Subject: [PATCH 11/16] tidy --- pages/authorize-contribution.vue | 12 ++---------- server/controllers/contribute.js | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/pages/authorize-contribution.vue b/pages/authorize-contribution.vue index 4e4a5d6..bab83be 100644 --- a/pages/authorize-contribution.vue +++ b/pages/authorize-contribution.vue @@ -55,7 +55,7 @@ export default { } }, computed: { - ...mapState('user', ['name', 'handle', 'company']), + ...mapState('user', ['name', 'handle', 'company', 'contributionIndex']), ...mapGetters('user', ['isLoggedIn', 'hasErrorName']), title() { if (this.status.type === 'is-danger' || !this.contributionIndex) { @@ -66,14 +66,6 @@ export default { } else { return `Please, specify your name and organization.` } - }, - contributionIndex: { - get() { - return this.$store.state.user.contributionIndex - }, - set(value) { - this.$store.commit('user/SET_CONTRIBUTION_INDEX', value) - } } }, async mounted() { @@ -135,7 +127,7 @@ export default { }) if (response.ok) { const { id } = await response.json() - this.contributionIndex = id + this.$store.commit('user/SET_CONTRIBUTION_INDEX', id) } else { const error = await response.text() this.status.msg = error diff --git a/server/controllers/contribute.js b/server/controllers/contribute.js index 088797f..71d1c9f 100644 --- a/server/controllers/contribute.js +++ b/server/controllers/contribute.js @@ -119,7 +119,6 @@ router.post('/authorize_contribution', async (req, res) => { } const contribution = await Contribution.findOne({ where: { token: req.body.token } }) - console.log('contribution', contribution.dataValues.id) if (!contribution) { res.status(404).send('There is no such contribution') return From 21e6254d13361470d4fcfcc22f183b529abb95c4 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Sun, 1 Mar 2020 01:27:01 +1000 Subject: [PATCH 12/16] instructions --- assets/styles/app.scss | 1 + assets/styles/components/_base.scss | 3 ++ assets/styles/components/_ceremony.scss | 4 ++ components/Navbar.vue | 2 +- nuxt.config.js | 2 +- package.json | 3 +- pages/instructions.vue | 62 +++++++++++++++++++++++++ pages/make-contribution.vue | 5 +- plugins/highlight.js | 4 ++ yarn.lock | 12 +++++ 10 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 pages/instructions.vue create mode 100644 plugins/highlight.js diff --git a/assets/styles/app.scss b/assets/styles/app.scss index a31a233..5469b35 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 '~highlight.js/scss/vs2015.scss'; .wrapper { display: flex; diff --git a/assets/styles/components/_base.scss b/assets/styles/components/_base.scss index 652a255..6f06658 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: #DCDCDC; $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: #1E1E1E; + .columns { @include from(576px) { &.is-small { diff --git a/assets/styles/components/_ceremony.scss b/assets/styles/components/_ceremony.scss index cd397fe..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) { 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/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/yarn.lock b/yarn.lock index ffe9c57..5a48bb5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4448,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" @@ -9354,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" From b793827b30e62ce5d741f61f81423c5274a07ca7 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Sun, 1 Mar 2020 19:49:00 +1000 Subject: [PATCH 13/16] update styles --- assets/styles/app.scss | 2 +- assets/styles/components/_base.scss | 4 ++-- assets/styles/components/_highlight.scss | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 assets/styles/components/_highlight.scss diff --git a/assets/styles/app.scss b/assets/styles/app.scss index 5469b35..a8236b0 100644 --- a/assets/styles/app.scss +++ b/assets/styles/app.scss @@ -10,7 +10,7 @@ @import 'components/status'; @import 'components/fieldset'; @import 'components/form'; -@import '~highlight.js/scss/vs2015.scss'; +@import 'components/highlight'; .wrapper { display: flex; diff --git a/assets/styles/components/_base.scss b/assets/styles/components/_base.scss index 6f06658..d0db859 100644 --- a/assets/styles/components/_base.scss +++ b/assets/styles/components/_base.scss @@ -10,7 +10,7 @@ $warning: #ff8a00; $black: #2c4538; $danger: #FF0658; $dark: #242424; -$pre: #DCDCDC; +$pre: $white; $info: $primary-invert; $info-invert: $white; $custom-colors: ("black": ($black, $primary-invert)); @@ -160,7 +160,7 @@ $pagination-current-color: $primary-invert; $pagination-current-background-color: $primary; $pagination-current-border-color: $primary; -$pre-background: #1E1E1E; +$pre-background: rgba($primary, 0.104); .columns { @include from(576px) { 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; +} From 3e4df53381293d6efe37d06d4d1c5798b2cebe8b Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 2 Mar 2020 10:58:11 +0300 Subject: [PATCH 14/16] fix env hashtag --- .env.example | 2 +- nuxt.config.js | 3 +++ server/attestationWatcher.js | 4 ++-- store/user.js | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 4e6c925..05ffb51 100644 --- a/.env.example +++ b/.env.example @@ -13,7 +13,7 @@ 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 -NUXT_ENV_TWITTER_HASHTAG= +TWITTER_HASHTAG= TWITTER_INTERVAL_ATTESTATION=300000 GITHUB_CLIEND_ID= diff --git a/nuxt.config.js b/nuxt.config.js index 575af92..30ee6bf 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -123,5 +123,8 @@ module.exports = { server: { port: 3000, // default: 3000 host: '0.0.0.0' // default: localhost + }, + env: { + hashtag: process.env.TWITTER_HASHTAG } } diff --git a/server/attestationWatcher.js b/server/attestationWatcher.js index 27f668f..ccdbdec 100644 --- a/server/attestationWatcher.js +++ b/server/attestationWatcher.js @@ -6,7 +6,7 @@ const { TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN_KEY, TWITTER_ACCESS_TOKEN_SECRET, - NUXT_ENV_TWITTER_HASHTAG, + TWITTER_HASHTAG, TWITTER_INTERVAL_ATTESTATION, NODE_ENV } = process.env @@ -31,7 +31,7 @@ function attestationWatcher() { const params = { since_id: initTweet, - q: `#${NUXT_ENV_TWITTER_HASHTAG} -filter:retweets`, + q: `#${TWITTER_HASHTAG} -filter:retweets`, result_type: 'recent', count: 100 } diff --git a/store/user.js b/store/user.js index a0dfb88..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 @TornadoCash Trusted Setup Ceremony! 🚀 %23${process.env.NUXT_ENV_TWITTER_HASHTAG}` + 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 From 777697f9071b15e2b4eebaaec8d78caa21b47a9c Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 2 Mar 2020 11:17:36 +0300 Subject: [PATCH 15/16] fix instructions --- pages/instructions.vue | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/pages/instructions.vue b/pages/instructions.vue index 1c81a30..bcca694 100644 --- a/pages/instructions.vue +++ b/pages/instructions.vue @@ -3,9 +3,8 @@

Instructions

-

- for Rust: + Using pure Rust implementation:

# Install rust
@@ -20,7 +19,7 @@ cargo run --release --bin tornado

- for Docker: + Using Docker container:

@@ -30,22 +29,14 @@ cargo run --release --bin tornado

First you need to install the docker on your system: + Windows + Mac + Linux

-
From f2bb2eaf6e76c9f6156e69bd39dab6811facb433 Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 2 Mar 2020 12:09:41 +0300 Subject: [PATCH 16/16] fix deploying process --- Dockerfile | 1 - package.json | 2 +- server/index.js | 12 +++--------- 3 files changed, 4 insertions(+), 11 deletions(-) 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/package.json b/package.json index cc20c3c..b3b5922 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "private": true, "scripts": { "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server", - "build": "nuxt build", + "build": "cross-env NODE_ENV=production nuxt build", "start": "cross-env NODE_ENV=production node server/index.js", "generate": "nuxt generate", "lint": "eslint --ext .js,.vue --ignore-path .gitignore ." diff --git a/server/index.js b/server/index.js index d3d345c..d38141c 100644 --- a/server/index.js +++ b/server/index.js @@ -14,19 +14,13 @@ 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,