claudemesh-cli 1.34.16 → 1.34.18

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.
@@ -104,7 +104,7 @@ __export(exports_urls, {
104
104
  VERSION: () => VERSION,
105
105
  URLS: () => URLS
106
106
  });
107
- var URLS, VERSION = "1.34.16", env;
107
+ var URLS, VERSION = "1.34.18", env;
108
108
  var init_urls = __esm(() => {
109
109
  URLS = {
110
110
  BROKER: process.env.CLAUDEMESH_BROKER_URL ?? "wss://ic.claudemesh.com/ws",
@@ -12031,24 +12031,28 @@ var init_inbound = __esm(() => {
12031
12031
  // src/daemon/identity.ts
12032
12032
  var exports_identity = {};
12033
12033
  __export(exports_identity, {
12034
+ pickStableMacFromInterfaces: () => pickStableMacFromInterfaces,
12035
+ fingerprintV2: () => fingerprintV2,
12034
12036
  computeCurrentFingerprint: () => computeCurrentFingerprint,
12035
12037
  checkFingerprint: () => checkFingerprint,
12036
- acceptCurrentHost: () => acceptCurrentHost
12038
+ acceptCurrentHost: () => acceptCurrentHost,
12039
+ __resetHostIdCacheForTests: () => __resetHostIdCacheForTests,
12040
+ __computeV1FingerprintForTests: () => __computeV1FingerprintForTests
12037
12041
  });
12038
12042
  import { existsSync as existsSync11, readFileSync as readFileSync9, writeFileSync as writeFileSync10 } from "node:fs";
12039
12043
  import { join as join7 } from "node:path";
12040
12044
  import { createHash as createHash2 } from "node:crypto";
12045
+ import { execFileSync } from "node:child_process";
12041
12046
  import { networkInterfaces } from "node:os";
12042
12047
  function path() {
12043
12048
  return join7(DAEMON_PATHS.DAEMON_DIR, FILE_NAME);
12044
12049
  }
12045
12050
  function computeCurrentFingerprint() {
12046
- const host_id = readHostId() ?? "";
12047
- const stable_mac = pickStableMac() ?? "";
12048
- const fp = createHash2("sha256").update(host_id, "utf8").update("\x00").update(stable_mac, "utf8").digest("hex");
12051
+ const host_id = readHostIdV2() ?? "";
12052
+ const stable_mac = pickStableMacFromInterfaces(networkInterfaces()) ?? "";
12049
12053
  return {
12050
- schema_version: 1,
12051
- fingerprint: fp,
12054
+ schema_version: CURRENT_SCHEMA,
12055
+ fingerprint: fingerprintV2(host_id, stable_mac),
12052
12056
  host_id,
12053
12057
  stable_mac,
12054
12058
  written_at: new Date().toISOString()
@@ -12066,16 +12070,74 @@ function checkFingerprint() {
12066
12070
  } catch {
12067
12071
  return { result: "unavailable", current };
12068
12072
  }
12069
- if (stored.fingerprint === current.fingerprint)
12070
- return { result: "match", current, stored };
12071
- return { result: "mismatch", current, stored };
12073
+ if (stored.schema_version === 2) {
12074
+ if (stored.fingerprint === current.fingerprint)
12075
+ return { result: "match", current, stored };
12076
+ if (stored.host_id && stored.host_id === current.host_id) {
12077
+ writeFileSync10(path(), JSON.stringify(current, null, 2), { mode: 384 });
12078
+ return { result: "match", current, stored };
12079
+ }
12080
+ return { result: "mismatch", current, stored };
12081
+ }
12082
+ if (stored.schema_version === 1) {
12083
+ const v1 = computeCurrentFingerprintV1();
12084
+ if (stored.fingerprint === v1.fingerprint) {
12085
+ writeFileSync10(path(), JSON.stringify(current, null, 2), { mode: 384 });
12086
+ return { result: "match", current, stored };
12087
+ }
12088
+ return { result: "mismatch", current, stored };
12089
+ }
12090
+ return { result: "unavailable", current };
12072
12091
  }
12073
12092
  function acceptCurrentHost() {
12074
12093
  const current = computeCurrentFingerprint();
12075
12094
  writeFileSync10(path(), JSON.stringify(current, null, 2), { mode: 384 });
12076
12095
  return current;
12077
12096
  }
12078
- function readHostId() {
12097
+ function fingerprintV2(host_id, stable_mac) {
12098
+ return createHash2("sha256").update("v2", "utf8").update("\x00").update(host_id, "utf8").update("\x00").update(stable_mac, "utf8").digest("hex");
12099
+ }
12100
+ function pickStableMacFromInterfaces(ifs) {
12101
+ const hardware = [];
12102
+ const fallback = [];
12103
+ for (const [name, addrs] of Object.entries(ifs)) {
12104
+ if (!addrs)
12105
+ continue;
12106
+ if (isIgnoredInterface(name))
12107
+ continue;
12108
+ for (const a of addrs) {
12109
+ if (a.internal)
12110
+ continue;
12111
+ if (!a.mac || a.mac === "00:00:00:00:00:00")
12112
+ continue;
12113
+ const entry = { name, mac: a.mac };
12114
+ if (isLocallyAdministered(a.mac)) {
12115
+ fallback.push(entry);
12116
+ } else {
12117
+ hardware.push(entry);
12118
+ }
12119
+ break;
12120
+ }
12121
+ }
12122
+ const pool = hardware.length > 0 ? hardware : fallback;
12123
+ if (pool.length === 0)
12124
+ return null;
12125
+ pool.sort((a, b) => a.name.localeCompare(b.name));
12126
+ return pool[0].mac;
12127
+ }
12128
+ function computeCurrentFingerprintV1() {
12129
+ const host_id = readHostIdV1() ?? "";
12130
+ const stable_mac = pickStableMacV1() ?? "";
12131
+ const fp = createHash2("sha256").update(host_id, "utf8").update("\x00").update(stable_mac, "utf8").digest("hex");
12132
+ return {
12133
+ schema_version: 1,
12134
+ fingerprint: fp,
12135
+ host_id,
12136
+ stable_mac,
12137
+ written_at: new Date().toISOString()
12138
+ };
12139
+ }
12140
+ function readHostIdV1() {
12079
12141
  if (process.platform === "linux") {
12080
12142
  for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
12081
12143
  try {
@@ -12086,18 +12148,15 @@ function readHostId() {
12086
12148
  }
12087
12149
  return null;
12088
12150
  }
12089
- if (process.platform === "darwin") {
12090
- return null;
12091
- }
12092
12151
  return null;
12093
12152
  }
12094
- function pickStableMac() {
12153
+ function pickStableMacV1() {
12095
12154
  const ifs = networkInterfaces();
12096
12155
  const candidates = [];
12097
12156
  for (const [name, addrs] of Object.entries(ifs)) {
12098
12157
  if (!addrs)
12099
12158
  continue;
12100
- if (isIgnoredInterface(name))
12159
+ if (isIgnoredInterfaceV1(name))
12101
12160
  continue;
12102
12161
  for (const a of addrs) {
12103
12162
  if (a.internal)
@@ -12115,10 +12174,57 @@ function pickStableMac() {
12115
12174
  const idx = first.indexOf("::");
12116
12175
  return idx >= 0 ? first.slice(idx + 2) : first;
12117
12176
  }
12118
- function isIgnoredInterface(name) {
12177
+ function isIgnoredInterfaceV1(name) {
12119
12178
  return /^(lo|docker|br-|veth|tap|tun|tailscale|wg|utun|ppp|vboxnet|vmnet|awdl|llw)/i.test(name);
12120
12179
  }
12121
- var FILE_NAME = "host_fingerprint.json";
12180
+ function readHostIdV2() {
12181
+ if (cachedHostIdV2 !== undefined)
12182
+ return cachedHostIdV2;
12183
+ cachedHostIdV2 = readHostIdV2Uncached();
12184
+ return cachedHostIdV2;
12185
+ }
12186
+ function readHostIdV2Uncached() {
12187
+ if (process.platform === "linux") {
12188
+ for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
12189
+ try {
12190
+ const raw = readFileSync9(p, "utf8").trim();
12191
+ if (raw)
12192
+ return `linux:${raw}`;
12193
+ } catch {}
12194
+ }
12195
+ return null;
12196
+ }
12197
+ if (process.platform === "darwin") {
12198
+ try {
12199
+ const out = execFileSync("/usr/sbin/ioreg", ["-rd1", "-c", "IOPlatformExpertDevice"], {
12200
+ encoding: "utf8",
12201
+ timeout: 2000,
12202
+ stdio: ["ignore", "pipe", "ignore"]
12203
+ });
12204
+ const m = out.match(/"IOPlatformUUID"\s*=\s*"([0-9A-Fa-f-]+)"/);
12205
+ if (m && m[1])
12206
+ return `darwin:${m[1]}`;
12207
+ } catch {}
12208
+ return null;
12209
+ }
12210
+ return null;
12211
+ }
12212
+ function isLocallyAdministered(mac) {
12213
+ const firstByte = parseInt(mac.split(":")[0] ?? "0", 16);
12214
+ if (Number.isNaN(firstByte))
12215
+ return false;
12216
+ return (firstByte & 2) !== 0;
12217
+ }
12218
+ function isIgnoredInterface(name) {
12219
+ return /^(lo|docker|br-|bridge|veth|tap|tun|tailscale|wg|utun|ppp|vboxnet|vmnet|awdl|llw|anpi|ap\d)/i.test(name);
12220
+ }
12221
+ function __resetHostIdCacheForTests() {
12222
+ cachedHostIdV2 = undefined;
12223
+ }
12224
+ function __computeV1FingerprintForTests() {
12225
+ return computeCurrentFingerprintV1();
12226
+ }
12227
+ var FILE_NAME = "host_fingerprint.json", CURRENT_SCHEMA = 2, cachedHostIdV2;
12122
12228
  var init_identity = __esm(() => {
12123
12229
  init_paths2();
12124
12230
  });
@@ -21286,4 +21392,4 @@ main().catch((err) => {
21286
21392
  process.exit(EXIT.INTERNAL_ERROR);
21287
21393
  });
21288
21394
 
21289
- //# debugId=8D95F82FF933574E64756E2164756E21
21395
+ //# debugId=C8B9D377DC161E3E64756E2164756E21