downloadKeys.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const axios = require('axios')
  2. const path = require('path')
  3. const fs = require('fs')
  4. const files = ['withdraw.json', 'withdraw_proving_key.bin', 'Verifier.sol', 'withdraw_verification_key.json']
  5. const circuitsPath = __dirname + '/../build/circuits'
  6. const contractsPath = __dirname + '/../build/contracts'
  7. async function downloadFile({ url, path }) {
  8. const writer = fs.createWriteStream(path)
  9. const response = await axios({
  10. url,
  11. method: 'GET',
  12. responseType: 'stream',
  13. })
  14. response.data.pipe(writer)
  15. return new Promise((resolve, reject) => {
  16. writer.on('finish', resolve)
  17. writer.on('error', reject)
  18. })
  19. }
  20. async function main() {
  21. const release = await axios.get('https://api.github.com/repos/tornadocash/tornado-core/releases/latest')
  22. const { assets } = release.data
  23. if (!fs.existsSync(circuitsPath)) {
  24. fs.mkdirSync(circuitsPath, { recursive: true })
  25. fs.mkdirSync(contractsPath, { recursive: true })
  26. }
  27. for (let asset of assets) {
  28. if (files.includes(asset.name)) {
  29. console.log(`Downloading ${asset.name} ...`)
  30. await downloadFile({
  31. url: asset.browser_download_url,
  32. path: path.resolve(__dirname, circuitsPath, asset.name),
  33. })
  34. }
  35. }
  36. }
  37. main()