@effectstream/npm-midnight-proof-server 0.3.99 → 0.100.9
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 +62 -10
- package/index.js +48 -12
- package/package.json +34 -23
- package/run_midnight_proof_server.js +3 -4
- package/proof-server/readme.md +0 -0
package/binary.js
CHANGED
|
@@ -4,7 +4,8 @@ const axios = require("axios");
|
|
|
4
4
|
const extract = require("extract-zip");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
|
|
7
|
-
const CURRENT_BINARY_VERSION = "ledger-
|
|
7
|
+
const CURRENT_BINARY_VERSION = "ledger-8.0.3";
|
|
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"
|
|
@@ -35,8 +36,7 @@ function getBinaryUrl() {
|
|
|
35
36
|
throw new Error(`Unsupported platform for binary execution: ${platform}`);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
return `https://paima-midnight.nyc3.cdn.digitaloceanspaces.com/binaries/midnight-proof-server-${platform}-${CURRENT_BINARY_VERSION}.zip`;
|
|
39
|
+
return `https://github.com/effectstream/binaries/releases/download/0.3.120/midnight-proof-server-${platform}-${CURRENT_BINARY_VERSION}.zip`;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
async function downloadAndSaveBinary() {
|
|
@@ -62,14 +62,39 @@ async function unzipBinary() {
|
|
|
62
62
|
fs.mkdirSync(destDir, { recursive: true });
|
|
63
63
|
}
|
|
64
64
|
await extract(zipPath, { dir: destDir });
|
|
65
|
+
|
|
65
66
|
const platform = getPlatform();
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
const extractedBinaryPath = path.join(
|
|
68
|
+
destDir,
|
|
69
|
+
`midnight-proof-server-${platform}-${CURRENT_BINARY_VERSION}`,
|
|
70
|
+
);
|
|
71
|
+
const finalBinaryPath = path.join(destDir, FINAL_BINARY_NAME);
|
|
72
|
+
|
|
73
|
+
// Rename the extracted file to midnight-proof-server
|
|
74
|
+
if (fs.existsSync(extractedBinaryPath)) {
|
|
75
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
76
|
+
fs.unlinkSync(finalBinaryPath);
|
|
77
|
+
}
|
|
78
|
+
fs.renameSync(extractedBinaryPath, finalBinaryPath);
|
|
79
|
+
} else {
|
|
80
|
+
throw new Error(`Extracted binary not found at: ${extractedBinaryPath}`);
|
|
72
81
|
}
|
|
82
|
+
|
|
83
|
+
// Clean up any other extracted files (e.g., readme.md)
|
|
84
|
+
const files = fs.readdirSync(destDir);
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
const filePath = path.join(destDir, file);
|
|
87
|
+
if (filePath !== finalBinaryPath && fs.statSync(filePath).isFile()) {
|
|
88
|
+
fs.unlinkSync(filePath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!fs.existsSync(finalBinaryPath)) {
|
|
93
|
+
throw new Error(`Expected binary not found: ${finalBinaryPath}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fs.chmodSync(finalBinaryPath, 0o755);
|
|
97
|
+
|
|
73
98
|
fs.unlinkSync(zipPath);
|
|
74
99
|
}
|
|
75
100
|
|
|
@@ -78,4 +103,31 @@ async function binary() {
|
|
|
78
103
|
await unzipBinary();
|
|
79
104
|
}
|
|
80
105
|
|
|
81
|
-
|
|
106
|
+
async function cleanBinaries() {
|
|
107
|
+
const binaryDir = path.join(__dirname, "proof-server");
|
|
108
|
+
const zipPath = path.join(__dirname, "proof-server.zip");
|
|
109
|
+
|
|
110
|
+
let deletedFiles = [];
|
|
111
|
+
|
|
112
|
+
if (fs.existsSync(binaryDir)) {
|
|
113
|
+
try {
|
|
114
|
+
fs.rmSync(binaryDir, { recursive: true, force: true });
|
|
115
|
+
deletedFiles.push(binaryDir);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(`Error removing directory ${binaryDir}:`, error.message);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (fs.existsSync(zipPath)) {
|
|
122
|
+
try {
|
|
123
|
+
fs.unlinkSync(zipPath);
|
|
124
|
+
deletedFiles.push(zipPath);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(`Error removing file ${zipPath}:`, error.message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return deletedFiles;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = { binary, getPlatform, cleanBinaries };
|
package/index.js
CHANGED
|
@@ -3,16 +3,18 @@ const fs = require("fs");
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const os = require("os");
|
|
5
5
|
|
|
6
|
-
const { binary, getPlatform } = require("./binary.js");
|
|
6
|
+
const { binary, getPlatform, cleanBinaries } = require("./binary.js");
|
|
7
7
|
const { runMidnightProofServer } = require("./run_midnight_proof_server.js");
|
|
8
8
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
return fs.existsSync(
|
|
16
|
+
path.join(__dirname, "proof-server", FINAL_BINARY_NAME),
|
|
17
|
+
);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
function isBinarySupported() {
|
|
@@ -23,30 +25,40 @@ function isBinarySupported() {
|
|
|
23
25
|
function showUsage() {
|
|
24
26
|
console.log(`\nUsage: npm-midnight-proof-server [options] [args...]\n
|
|
25
27
|
Options:
|
|
26
|
-
--docker
|
|
27
|
-
--binary
|
|
28
|
-
--
|
|
28
|
+
--docker Force use of Docker container
|
|
29
|
+
--binary Force binary execution (Linux only)
|
|
30
|
+
--clean-binaries Delete downloaded binaries and download them again
|
|
31
|
+
--only-clean Only delete downloaded binaries without downloading them again
|
|
32
|
+
--help, -h Show this help message\n`);
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
function parseFlags(argv) {
|
|
32
36
|
const flags = {
|
|
33
37
|
useDocker: false,
|
|
34
38
|
useBinary: false,
|
|
39
|
+
cleanBinaries: false,
|
|
40
|
+
onlyClean: false,
|
|
35
41
|
showHelp: false,
|
|
36
42
|
remaining: [],
|
|
37
43
|
};
|
|
38
44
|
for (const arg of argv) {
|
|
39
45
|
if (arg === "--docker") flags.useDocker = true;
|
|
40
46
|
else if (arg === "--binary") flags.useBinary = true;
|
|
47
|
+
else if (arg === "--clean-binaries") flags.cleanBinaries = true;
|
|
48
|
+
else if (arg === "--only-clean") flags.onlyClean = true;
|
|
41
49
|
else if (arg === "--help" || arg === "-h") flags.showHelp = true;
|
|
42
50
|
else flags.remaining.push(arg);
|
|
43
51
|
}
|
|
44
52
|
return flags;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
async function runWithBinary(env, args) {
|
|
48
|
-
if (!checkIfBinaryExists()) {
|
|
49
|
-
|
|
55
|
+
async function runWithBinary(env, args, forceClean = false) {
|
|
56
|
+
if (forceClean || !checkIfBinaryExists()) {
|
|
57
|
+
if (forceClean) {
|
|
58
|
+
console.log("Cleaning downloaded binaries...");
|
|
59
|
+
await cleanBinaries();
|
|
60
|
+
}
|
|
61
|
+
console.log("Downloading binary...");
|
|
50
62
|
await binary();
|
|
51
63
|
} else {
|
|
52
64
|
console.log("Using existing binary found in proof-server directory");
|
|
@@ -72,11 +84,31 @@ async function runWithDocker(env, args) {
|
|
|
72
84
|
process.exit(0);
|
|
73
85
|
}
|
|
74
86
|
|
|
87
|
+
// Handle --only-clean flag
|
|
88
|
+
if (flags.onlyClean) {
|
|
89
|
+
console.log("Cleaning downloaded binaries...");
|
|
90
|
+
const deletedFiles = await cleanBinaries();
|
|
91
|
+
if (deletedFiles.length > 0) {
|
|
92
|
+
console.log("Deleted:", deletedFiles.join(", "));
|
|
93
|
+
} else {
|
|
94
|
+
console.log("No downloaded binaries found to delete.");
|
|
95
|
+
}
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
|
|
75
99
|
if (flags.useDocker && flags.useBinary) {
|
|
76
100
|
console.error("Cannot use both --docker and --binary flags simultaneously");
|
|
77
101
|
process.exit(1);
|
|
78
102
|
}
|
|
79
103
|
|
|
104
|
+
// Validate clean flag usage
|
|
105
|
+
if (flags.cleanBinaries && flags.useDocker) {
|
|
106
|
+
console.error(
|
|
107
|
+
"Error: --clean-binaries flag cannot be used with --docker flag",
|
|
108
|
+
);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
80
112
|
if (flags.useDocker) {
|
|
81
113
|
await runWithDocker(env, flags.remaining);
|
|
82
114
|
return;
|
|
@@ -89,13 +121,13 @@ async function runWithDocker(env, args) {
|
|
|
89
121
|
);
|
|
90
122
|
process.exit(1);
|
|
91
123
|
}
|
|
92
|
-
await runWithBinary(env, flags.remaining);
|
|
124
|
+
await runWithBinary(env, flags.remaining, flags.cleanBinaries);
|
|
93
125
|
return;
|
|
94
126
|
}
|
|
95
127
|
|
|
96
128
|
// Automatic selection
|
|
97
129
|
if (isBinarySupported()) {
|
|
98
|
-
await runWithBinary(env, flags.remaining);
|
|
130
|
+
await runWithBinary(env, flags.remaining, flags.cleanBinaries);
|
|
99
131
|
} else {
|
|
100
132
|
console.log(
|
|
101
133
|
"Binary not supported on this platform, falling back to Docker...",
|
|
@@ -103,3 +135,7 @@ async function runWithDocker(env, args) {
|
|
|
103
135
|
await runWithDocker(env, flags.remaining);
|
|
104
136
|
}
|
|
105
137
|
})();
|
|
138
|
+
|
|
139
|
+
module.exports = {
|
|
140
|
+
cleanBinaries,
|
|
141
|
+
};
|
package/package.json
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"name": "@effectstream/npm-midnight-proof-server",
|
|
3
|
+
"version": "0.100.9",
|
|
4
|
+
"description": "A wrapper for the Midnight proof server binary",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"npm-midnight-proof-server": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node index.js",
|
|
11
|
+
"clean": "node index.js --clean-binaries",
|
|
12
|
+
"clean-only": "node index.js --only-clean"
|
|
13
|
+
},
|
|
14
|
+
"supportedPlatforms": [
|
|
15
|
+
"linux-amd64",
|
|
16
|
+
"linux-arm64",
|
|
17
|
+
"macos-arm64"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"axios": "^1.6.8",
|
|
21
|
+
"extract-zip": "^2.0.1"
|
|
22
|
+
},
|
|
23
|
+
"type": "commonjs",
|
|
24
|
+
"author": "Paima Studios",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"homepage": "https://effectstream.github.io/docs/",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/PaimaStudios/paima-engine",
|
|
30
|
+
"directory": "packages/binaries/midnight-proof-server"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/PaimaStudios/paima-engine/issues"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { spawn } = require("child_process");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
|
|
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
|
|
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
|
|
package/proof-server/readme.md
DELETED
|
File without changes
|