@bullpenfi/cli 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bullpenfi/cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "CLI for Bullpen prediction markets",
5
5
  "bin": {
6
6
  "bullpen": "bin/bullpen"
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ const crypto = require("crypto");
3
4
  const https = require("https");
4
5
  const fs = require("fs");
5
6
  const path = require("path");
@@ -56,11 +57,32 @@ function download(url) {
56
57
  });
57
58
  }
58
59
 
60
+ /// Verify the SHA-256 checksum of a file against a .sha256 checksum file.
61
+ function verifyChecksum(filePath, checksumContent) {
62
+ const expected = checksumContent.toString("utf8").trim().split(/\s+/)[0];
63
+ if (!expected) {
64
+ throw new Error("Checksum file is empty or malformed");
65
+ }
66
+
67
+ const fileData = fs.readFileSync(filePath);
68
+ const actual = crypto.createHash("sha256").update(fileData).digest("hex");
69
+
70
+ if (actual !== expected) {
71
+ throw new Error(
72
+ `Checksum mismatch!\n Expected: ${expected}\n Got: ${actual}\n` +
73
+ "The downloaded binary may be corrupted. Please try again."
74
+ );
75
+ }
76
+ }
77
+
59
78
  async function main() {
60
79
  const target = getTarget();
61
80
  const version = require("../package.json").version;
62
81
  const tarballName = `bullpen-${version}-${target}.tar.gz`;
63
- const downloadUrl = `https://github.com/BullpenFi/bullpen-cli-releases/releases/download/v${version}/${tarballName}`;
82
+ const checksumName = `${tarballName}.sha256`;
83
+ const baseUrl = `https://github.com/BullpenFi/bullpen-cli-releases/releases/download/v${version}`;
84
+ const downloadUrl = `${baseUrl}/${tarballName}`;
85
+ const checksumUrl = `${baseUrl}/${checksumName}`;
64
86
 
65
87
  const binDir = path.join(__dirname, "..", "bin");
66
88
  const binaryPath = path.join(binDir, "bullpen-native");
@@ -75,6 +97,12 @@ async function main() {
75
97
  fs.writeFileSync(tarballPath, data);
76
98
  console.log(`Download complete (${(data.length / 1024 / 1024).toFixed(1)} MB)`);
77
99
 
100
+ // Download and verify checksum
101
+ console.log("Verifying checksum...");
102
+ const checksumData = await download(checksumUrl);
103
+ verifyChecksum(tarballPath, checksumData);
104
+ console.log("Checksum verified.");
105
+
78
106
  // Extract the tarball
79
107
  console.log("Extracting binary...");
80
108
  execSync(`tar xzf "${tarballPath}" -C "${tmpDir}"`);