native-machine-id 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -22,11 +22,13 @@ npx native-machine-id --raw
22
22
  ```javascript
23
23
  import { getMachineId } from 'native-machine-id';
24
24
 
25
- // Get the machine ID
26
- const hashedId = await getMachineId();
27
- console.log('SHA-256 Hashed Machine ID:', id);
28
- const id = await getMachineId({ raw: true });
29
- console.log('Raw Machine ID:', id);
25
+ // Get the machine ID, hashed with SHA-256
26
+ const hashedId = getMachineID();
27
+ console.log('Hashed Machine ID:', hashedId);
28
+
29
+ // Get the raw machine ID (should not be exposed in untrusted environments)
30
+ const rawId = getMachineID({ raw: true });
31
+ console.log('Original Machine ID:', rawId);
30
32
 
31
33
  // Or synchronously
32
34
  import { getMachineIdSync } from 'native-machine-id';
@@ -41,7 +43,7 @@ const id = getMachineIdSync();
41
43
 
42
44
  ## Comparison with `node-machine-id`
43
45
 
44
- This module provides similar functionality to [node-machine-id](https://www.npmjs.com/package/node-machine-id), but **using native access to system APIs without the need for child processes**, making it much faster and reliable.
46
+ This module provides similar functionality to [node-machine-id](https://www.npmjs.com/package/node-machine-id) while **using native access to system APIs without the need for child processes**, making it much faster and reliable.
45
47
 
46
48
  Here's a table of performance comparisons between the two libraries, based on the average runtime from 1000 iterations of the `getMachineIdSync` and `machineIdSync` functions, from `scripts/benchmark.ts`:
47
49
 
package/binding.cc CHANGED
@@ -4,6 +4,13 @@
4
4
  #ifdef __APPLE__
5
5
  #include <CoreFoundation/CoreFoundation.h>
6
6
  #include <IOKit/IOKitLib.h>
7
+ #include <AvailabilityMacros.h>
8
+ // kIOMainPortDefault is the replacement on macOS 12+ but is not available in older SDKs
9
+ #if (defined(MAC_OS_VERSION_MIN_REQUIRED) && MAC_OS_VERSION_MIN_REQUIRED >= 120000)
10
+ #define IO_PORT_DEFAULT kIOMainPortDefault
11
+ #else
12
+ #define IO_PORT_DEFAULT kIOMasterPortDefault
13
+ #endif
7
14
  #elif defined(__linux__)
8
15
  #include <fstream>
9
16
  #include <algorithm>
@@ -21,7 +28,7 @@ namespace
21
28
  std::string getMachineId() noexcept
22
29
  {
23
30
  std::string uuid;
24
- io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMainPortDefault, "IOService:/");
31
+ io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(IO_PORT_DEFAULT, "IOService:/");
25
32
 
26
33
  if (ioRegistryRoot == MACH_PORT_NULL)
27
34
  {
@@ -245,4 +252,4 @@ static Object InitModule(Env env, Object exports)
245
252
  return exports;
246
253
  }
247
254
 
248
- NODE_API_MODULE(machine_id, InitModule)
255
+ NODE_API_MODULE(native_machine_id, InitModule)
package/binding.gyp CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  'targets': [{
3
- 'target_name': 'machine_id',
3
+ 'target_name': 'native_machine_id',
4
4
  'sources': [ 'binding.cc' ],
5
5
  'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
6
6
  'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ exports.getMachineIdSync = exports.getMachineId = void 0;
7
7
  const bindings_1 = __importDefault(require("bindings"));
8
8
  const crypto_1 = require("crypto");
9
9
  const util_1 = require("util");
10
- const binding = (0, bindings_1.default)('machine_id');
10
+ const binding = (0, bindings_1.default)('native_machine_id');
11
11
  function getMachineIdFromBindingSync() {
12
12
  try {
13
13
  return binding.getMachineIdSync() || undefined;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,mCAAoC;AACpC,+BAAiC;AAEjC,MAAM,OAAO,GAAG,IAAA,kBAAQ,EAAC,YAAY,CAAC,CAAC;AAEvC,SAAS,2BAA2B;IAClC,IAAI;QACF,OAAO,OAAO,CAAC,gBAA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AgB,EAAE,IAAI,SAAS,CAAC;KAChD;IAAC,MAAM;QAEN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,KAAK,UAAU,4BAA4B;IACzC,IAAI;QACF,MAAM,QAAQ,GACZ,CAAC,MAAM,IAAA,gBAAS,EAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC;QAE9D,OAAO,QAAQ,CAAC;KACjB;IAAC,MAAM;QAEN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAWM,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,GAAG,KAAK,MACY,EAAE;IACzB,MAAM,SAAS,GAAG,MAAM,4BAA4B,EAAE,CAAC;IAEvD,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;QAC9B,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAVD,oCAUC;AAMD,SAAgB,gBAAgB,CAAC,EAAE,GAAG,GAAG,KAAK,KAA0B,EAAE;IAGxE,MAAM,SAAS,GAAG,2BAA2B,EAAE,CAAC;IAEhD,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;QAC9B,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAVD,4CAUC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-machine-id",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Native retrieval of a unique desktop machine ID without admin privileges or child processes. Faster and more reliable alternative to node-machine-id.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -58,5 +58,23 @@
58
58
  "node-machine-id": "^1.1.12",
59
59
  "typescript": "^5.0.4",
60
60
  "ts-node": "^10.9.2"
61
- }
61
+ },
62
+ "keywords": [
63
+ "machine id",
64
+ "node machine id",
65
+ "device identifier",
66
+ "node id",
67
+ "unique identifier",
68
+ "device id",
69
+ "machine identifier",
70
+ "unique id",
71
+ "platform id",
72
+ "electron id",
73
+ "node-machine-id",
74
+ "uuid",
75
+ "restrictions",
76
+ "native",
77
+ "telemetry",
78
+ "telemetry id"
79
+ ]
62
80
  }