1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 |
|
4 |
|
5 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
8 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
9 | desc = { enumerable: true, get: function() { return m[k]; } };
|
10 | }
|
11 | Object.defineProperty(o, k2, desc);
|
12 | }) : (function(o, m, k, k2) {
|
13 | if (k2 === undefined) k2 = k;
|
14 | o[k2] = m[k];
|
15 | }));
|
16 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
17 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
18 | }) : function(o, v) {
|
19 | o["default"] = v;
|
20 | });
|
21 | var __importStar = (this && this.__importStar) || function (mod) {
|
22 | if (mod && mod.__esModule) return mod;
|
23 | var result = {};
|
24 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
25 | __setModuleDefault(result, mod);
|
26 | return result;
|
27 | };
|
28 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
29 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
30 | };
|
31 | Object.defineProperty(exports, "__esModule", { value: true });
|
32 | const fs = __importStar(require("fs"));
|
33 | const follow_redirects_1 = require("follow-redirects");
|
34 | const memorystream_1 = __importDefault(require("memorystream"));
|
35 | const js_sha3_1 = require("js-sha3");
|
36 | const pkg = require('./package.json');
|
37 | function getVersionList(cb) {
|
38 | console.log('Retrieving available version list...');
|
39 | const mem = new memorystream_1.default(null, { readable: false });
|
40 | follow_redirects_1.https.get('https://binaries.soliditylang.org/bin/list.json', function (response) {
|
41 | if (response.statusCode !== 200) {
|
42 | console.log('Error downloading file: ' + response.statusCode);
|
43 | process.exit(1);
|
44 | }
|
45 | response.pipe(mem);
|
46 | response.on('end', function () {
|
47 | cb(mem.toString());
|
48 | });
|
49 | });
|
50 | }
|
51 | function downloadBinary(outputName, version, expectedHash) {
|
52 | console.log('Downloading version', version);
|
53 |
|
54 | if (fs.existsSync(outputName)) {
|
55 | fs.unlinkSync(outputName);
|
56 | }
|
57 | process.on('SIGINT', function () {
|
58 | console.log('Interrupted, removing file.');
|
59 | fs.unlinkSync(outputName);
|
60 | process.exit(1);
|
61 | });
|
62 | const file = fs.createWriteStream(outputName, { encoding: 'binary' });
|
63 | follow_redirects_1.https.get('https://binaries.soliditylang.org/bin/' + version, function (response) {
|
64 | if (response.statusCode !== 200) {
|
65 | console.log('Error downloading file: ' + response.statusCode);
|
66 | process.exit(1);
|
67 | }
|
68 | response.pipe(file);
|
69 | file.on('finish', function () {
|
70 | file.close(function () {
|
71 | const hash = '0x' + (0, js_sha3_1.keccak256)(fs.readFileSync(outputName, { encoding: 'binary' }));
|
72 | if (expectedHash !== hash) {
|
73 | console.log('Hash mismatch: ' + expectedHash + ' vs ' + hash);
|
74 | process.exit(1);
|
75 | }
|
76 | console.log('Done.');
|
77 | });
|
78 | });
|
79 | });
|
80 | }
|
81 | console.log('Downloading correct solidity binary...');
|
82 | getVersionList(function (list) {
|
83 | list = JSON.parse(list);
|
84 | const wanted = pkg.version.match(/^(\d+\.\d+\.\d+)$/)[1];
|
85 | const releaseFileName = list.releases[wanted];
|
86 | const expectedFile = list.builds.filter(function (entry) { return entry.path === releaseFileName; })[0];
|
87 | if (!expectedFile) {
|
88 | console.log('Version list is invalid or corrupted?');
|
89 | process.exit(1);
|
90 | }
|
91 | const expectedHash = expectedFile.keccak256;
|
92 | downloadBinary('soljson.js', releaseFileName, expectedHash);
|
93 | });
|