@paimaexample/npm-midnight-node 0.3.126 → 0.3.128

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
@@ -4,7 +4,7 @@ const axios = require("axios");
4
4
  const extract = require("extract-zip");
5
5
  const path = require("path");
6
6
 
7
- const CURRENT_BINARY_VERSION = "0.12.1";
7
+ const CURRENT_BINARY_VERSION = "0.18.0-rc.10";
8
8
  const FINAL_BINARY_NAME = "midnight-node";
9
9
 
10
10
  /*
@@ -65,57 +65,33 @@ async function downloadAndSaveBinary() {
65
65
  /*
66
66
  @returns {Promise<void>} Unzips the binary for the current platform.
67
67
  */
68
- function findExtractedBinary(binaryDir, platform) {
69
- const candidateNames = new Set([
70
- FINAL_BINARY_NAME,
71
- `midnight-node-${platform}`,
72
- `midnight-node-${platform}-${CURRENT_BINARY_VERSION}`,
73
- ]);
74
-
75
- const explore = (dir) => {
76
- for (const entry of fs.readdirSync(dir)) {
77
- const entryPath = path.join(dir, entry);
78
- const entryStats = fs.statSync(entryPath);
79
-
80
- if (entryStats.isFile() && candidateNames.has(entry)) {
81
- return entryPath;
82
- }
83
-
84
- if (entryStats.isDirectory()) {
85
- for (const candidate of candidateNames) {
86
- const nestedPath = path.join(entryPath, candidate);
87
- if (fs.existsSync(nestedPath) && fs.statSync(nestedPath).isFile()) {
88
- return nestedPath;
89
- }
90
- }
91
- const nestedResult = explore(entryPath);
92
- if (nestedResult) return nestedResult;
93
- }
94
- }
95
- return null;
96
- };
97
-
98
- return explore(binaryDir);
99
- }
100
-
101
68
  async function unzipBinary() {
102
69
  const binaryDir = path.join(__dirname, "midnight-node");
103
70
  await extract(path.join(__dirname, FILE_NAME), { dir: binaryDir });
104
71
  const platform = getPlatform();
72
+ const extractedBinaryPath = path.join(
73
+ binaryDir,
74
+ `midnight-node-${platform}-${CURRENT_BINARY_VERSION}`,
75
+ );
105
76
  const finalBinaryPath = path.join(binaryDir, FINAL_BINARY_NAME);
106
- const extractedBinaryPath = findExtractedBinary(binaryDir, platform);
107
77
 
108
- if (!extractedBinaryPath) {
109
- throw new Error(
110
- `Expected binary not found after extraction in ${binaryDir}`,
111
- );
112
- }
113
-
114
- if (extractedBinaryPath !== finalBinaryPath) {
78
+ // Rename the extracted file to midnight-node
79
+ if (fs.existsSync(extractedBinaryPath)) {
115
80
  if (fs.existsSync(finalBinaryPath)) {
116
81
  fs.unlinkSync(finalBinaryPath);
117
82
  }
118
83
  fs.renameSync(extractedBinaryPath, finalBinaryPath);
84
+ } else {
85
+ throw new Error(`Extracted binary not found at: ${extractedBinaryPath}`);
86
+ }
87
+
88
+ // Clean up any other extracted files (e.g., readme.md)
89
+ const files = fs.readdirSync(binaryDir);
90
+ for (const file of files) {
91
+ const filePath = path.join(binaryDir, file);
92
+ if (filePath !== finalBinaryPath && fs.statSync(filePath).isFile()) {
93
+ fs.unlinkSync(filePath);
94
+ }
119
95
  }
120
96
 
121
97
  if (!fs.existsSync(finalBinaryPath)) {
@@ -0,0 +1,36 @@
1
+ [
2
+ {
3
+ "registrations": [
4
+ {
5
+ "name": "LocalValidator1",
6
+ "aura_pub_key": "0xb606fc73f57f03cdb4c932d475ab426043e429cecc2ffff0d2672b0df8398c48",
7
+ "grandpa_pub_key": "0xbf3a763d817cee09bf785b9cc6118f58dab5c03f3ace6d524899bcb28ac74f27",
8
+ "sidechain_pub_key": "0x0333022898140662dfea847e3cbfe5e989845ac6766e83472f8b0c650d85e77bae",
9
+ "mainchain_pub_key": "0xd5f64925e8722583ab9f8bb633a6938780873cf59504b3d12527719d3310b0ff",
10
+ "mainchain_signature": "0x9e417ede1ab0d710ce3d5854627baef9b32d4dd69ec75f20d1f28234f167b3f679dadafce995fc63a05eefefa322ebe84b5ffccf526481710d086a16aef61506",
11
+ "sidechain_signature": "0x568e305af7f6d51668a76f3aaa72aa3f0f3554be20f150dcabb759f8bff66b484bf66cf248916a40bda649b3ce302ecaf689b9c7b4abd66b44b2aeb039ff85a5",
12
+ "registration_utxo": "ff428f8f916a832d146e58f3656c17c769a6bbc44bba1693fe2a4f9c605b8f16#0",
13
+ "status": "Active"
14
+ }
15
+ ],
16
+ "permissioned": [
17
+ {
18
+ "name": "LocalPermissioned1",
19
+ "aura_pub_key": "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d",
20
+ "grandpa_pub_key": "0x88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee",
21
+ "sidechain_pub_key": "0x020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1",
22
+ "mainchain_pub_key": "0xd5f64925e8722583ab9f8bb633a6938780873cf59504b3d12527719d3310b0ff",
23
+ "mainchain_signature": "0x9e417ede1ab0d710ce3d5854627baef9b32d4dd69ec75f20d1f28234f167b3f679dadafce995fc63a05eefefa322ebe84b5ffccf526481710d086a16aef61506",
24
+ "sidechain_signature": "0x568e305af7f6d51668a76f3aaa72aa3f0f3554be20f150dcabb759f8bff66b484bf66cf248916a40bda649b3ce302ecaf689b9c7b4abd66b44b2aeb039ff85a5",
25
+ "registration_utxo": "ff428f8f916a832d146e58f3656c17c769a6bbc44bba1693fe2a4f9c605b8f16#1",
26
+ "status": "Active"
27
+ }
28
+ ],
29
+ "nonce": "0x1234",
30
+ "d_parameter": {
31
+ "permissioned": 6,
32
+ "registered": 0
33
+ }
34
+ }
35
+ ]
36
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paimaexample/npm-midnight-node",
3
- "version": "0.3.126",
3
+ "version": "0.3.128",
4
4
  "description": "Downloads and starts the binary for Midnight Node",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,22 @@
1
1
  const { spawn } = require("child_process");
2
2
  const path = require("path");
3
3
 
4
- const BINARY_NAME = "midnight-node";
4
+ /**
5
+ * Applies default environment variables for midnight-node if not already set
6
+ * @param {Object} env - Environment variables object
7
+ * @returns {Object} Environment variables with defaults applied
8
+ */
9
+ function applyDefaultEnv(env) {
10
+ const newEnv = { ...env };
11
+ if (!("MC__SLOT_DURATION_MILLIS" in newEnv)) {
12
+ newEnv.MC__SLOT_DURATION_MILLIS = "1000";
13
+ }
14
+ if (!("MOCK_REGISTRATIONS_FILE" in newEnv)) {
15
+ newEnv.MOCK_REGISTRATIONS_FILE = path.join(__dirname, "local-mock.json");
16
+ }
17
+ return newEnv;
18
+ }
19
+
5
20
  /**
6
21
  * Executes the midnight-node binary as a child process
7
22
  * @param {Object} env - Environment variables to pass to the child process
@@ -9,14 +24,17 @@ const BINARY_NAME = "midnight-node";
9
24
  * @returns {ChildProcess} The spawned child process
10
25
  */
11
26
  function runMidnightNode(env = process.env, args = []) {
12
- const binaryPath = path.join(__dirname, "midnight-node", BINARY_NAME);
27
+ const newEnv = applyDefaultEnv(env);
28
+
29
+ const binaryName = "midnight-node";
30
+ const binaryPath = path.join(__dirname, "midnight-node", binaryName);
13
31
 
14
32
  console.log(
15
33
  `Starting midnight-node binary at: ${binaryPath} ${args.join(" ")}`,
16
34
  );
17
35
 
18
36
  const childProcess = spawn(binaryPath, args, {
19
- env: env,
37
+ env: newEnv,
20
38
  stdio: "inherit", // Inherit stdin, stdout, stderr from parent process
21
39
  cwd: path.join(__dirname, "midnight-node"), // Run from inside the midnight-node directory
22
40
  });