@paimaexample/npm-midnight-proof-server 0.3.122 → 0.3.124

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/binary.js CHANGED
@@ -5,6 +5,7 @@ const extract = require("extract-zip");
5
5
  const path = require("path");
6
6
 
7
7
  const CURRENT_BINARY_VERSION = "ledger-4.0.0";
8
+ const FINAL_BINARY_NAME = "midnight-proof-server";
8
9
 
9
10
  /**
10
11
  * @returns {string} The platform and architecture of the current machine. Example: "linux-amd64"
@@ -62,13 +63,26 @@ async function unzipBinary() {
62
63
  }
63
64
  await extract(zipPath, { dir: destDir });
64
65
  const platform = getPlatform();
65
- const parts = platform.split("-");
66
- if (parts[0] === "linux") {
67
- fs.chmodSync(
68
- path.join(destDir, `midnight-proof-server-${platform}`),
69
- 0o755,
70
- );
66
+ const extractedBinaryPath = path.join(
67
+ destDir,
68
+ `midnight-proof-server-${platform}`,
69
+ );
70
+ const finalBinaryPath = path.join(destDir, FINAL_BINARY_NAME);
71
+
72
+ if (fs.existsSync(extractedBinaryPath) &&
73
+ extractedBinaryPath !== finalBinaryPath) {
74
+ if (fs.existsSync(finalBinaryPath)) {
75
+ fs.unlinkSync(finalBinaryPath);
76
+ }
77
+ fs.renameSync(extractedBinaryPath, finalBinaryPath);
78
+ }
79
+
80
+ if (!fs.existsSync(finalBinaryPath)) {
81
+ throw new Error(`Expected binary not found: ${finalBinaryPath}`);
71
82
  }
83
+
84
+ fs.chmodSync(finalBinaryPath, 0o755);
85
+
72
86
  fs.unlinkSync(zipPath);
73
87
  }
74
88
 
package/index.js CHANGED
@@ -9,10 +9,12 @@ const { checkIfDockerExists, pullDockerImage, runDockerContainer } = require(
9
9
  "./docker.js",
10
10
  );
11
11
 
12
+ const FINAL_BINARY_NAME = "midnight-proof-server";
13
+
12
14
  function checkIfBinaryExists() {
13
- const platform = getPlatform();
14
- const binaryName = `midnight-proof-server-${platform}`;
15
- return fs.existsSync(path.join(__dirname, "proof-server", binaryName));
15
+ return fs.existsSync(
16
+ path.join(__dirname, "proof-server", FINAL_BINARY_NAME),
17
+ );
16
18
  }
17
19
 
18
20
  function isBinarySupported() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paimaexample/npm-midnight-proof-server",
3
- "version": "0.3.122",
3
+ "version": "0.3.124",
4
4
  "description": "A wrapper for the Midnight proof server binary",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,6 +1,7 @@
1
1
  const { spawn } = require("child_process");
2
2
  const path = require("path");
3
- const { getPlatform } = require("./binary.js");
3
+
4
+ const BINARY_NAME = "midnight-proof-server";
4
5
 
5
6
  /**
6
7
  * Executes the midnight-proof-server binary as a child process.
@@ -9,9 +10,7 @@ const { getPlatform } = require("./binary.js");
9
10
  * @returns {import('child_process').ChildProcess}
10
11
  */
11
12
  function runMidnightProofServer(env = process.env, args = []) {
12
- const platform = getPlatform();
13
- const binaryName = `midnight-proof-server-${platform}`;
14
- const binaryPath = path.join(__dirname, "proof-server", binaryName);
13
+ const binaryPath = path.join(__dirname, "proof-server", BINARY_NAME);
15
14
 
16
15
  console.log(`Starting midnight proof server binary at: ${binaryPath}`);
17
16