jbc-dssi 1.1.111 → 1.1.113
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/index.js +6 -1
- package/package.json +1 -1
- package/pairing/ensure.js +110 -22
- package/pairing/page.js +36 -1
- package/pairing/register.js +34 -1
- package/pairing/show.js +14 -2
- package/pairing/store.js +22 -0
package/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import fs from 'node:fs';
|
|
|
18
18
|
import { randomUUID } from 'node:crypto';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
20
|
import { join } from 'node:path';
|
|
21
|
-
import { homedir } from 'node:os';
|
|
21
|
+
import { homedir, hostname } from 'node:os';
|
|
22
22
|
import { watchUiConfig } from './lib/ui-config-push.js';
|
|
23
23
|
import { parseUiTuning, formatTuning, resolveRotateConfig } from './lib/ui-tuning.js';
|
|
24
24
|
import { createRestartAutocheck } from './lib/restart-autocheck.js';
|
|
@@ -1857,6 +1857,11 @@ class BridgeConnection {
|
|
|
1857
1857
|
*/
|
|
1858
1858
|
pluginVersion: LOADED_VERSION,
|
|
1859
1859
|
pluginInstalledVersion: pluginVersion(),
|
|
1860
|
+
/*
|
|
1861
|
+
* 电脑名(2026-11-13,只加字段):手机侧在"正在连接"状态里显示"正在连接:<电脑名>",
|
|
1862
|
+
* 这样扫错码/连到别的电脑一眼能看出来。老 App 不认识就忽略。
|
|
1863
|
+
*/
|
|
1864
|
+
computerName: hostname(),
|
|
1860
1865
|
/*
|
|
1861
1866
|
* 能力声明(只做加法,老 App 不认识就忽略)。
|
|
1862
1867
|
* 手机据此决定「团队」tab 是显示数据还是显示"电脑侧插件需更新"。
|
package/package.json
CHANGED
package/pairing/ensure.js
CHANGED
|
@@ -23,10 +23,23 @@
|
|
|
23
23
|
*
|
|
24
24
|
* 【每次调用都会显示一次码】
|
|
25
25
|
* 码本身不变(见上),显示只是为了让用户随时能拿到它。
|
|
26
|
+
*
|
|
27
|
+
* 【2026-11-13 加:本机校验(防"扫自己的码连到别人电脑")】
|
|
28
|
+
* ② 分支以前只要 relayUrl 对得上就直接沿用本地 pairing.json —— 但那份文件可能是
|
|
29
|
+
* 从别的电脑拷来的/残留的,里面是**别人的** pairId。沿用 = 把别人的码当本机码弹出来,
|
|
30
|
+
* 手机扫了就会连到别人的电脑(真机事故:新用户连到了负责人的电脑)。
|
|
31
|
+
*
|
|
32
|
+
* 现在 ② 必须同时满足两条才沿用:
|
|
33
|
+
* a) 文件里的本机指纹 == 本机的指纹(`localMachineKey()`,不随文件走);
|
|
34
|
+
* b) 中继核对通过(`/pair/probe`:这对 pairId+令牌真的在中继上有效)。
|
|
35
|
+
* 老版本文件(没有指纹)→ 视为可疑,统一重生成(一次性重扫码,代价明确)。
|
|
36
|
+
* 中继暂时不可达 → **不作废**本地配对(断网启动还得能用),只打日志。
|
|
26
37
|
*/
|
|
38
|
+
import os from 'node:os';
|
|
39
|
+
|
|
27
40
|
import { newPairingSecrets, buildPairingPayload } from '../lib/e2e.js';
|
|
28
|
-
import { loadPairing, savePairing, pairingFilePath } from './store.js';
|
|
29
|
-
import { registerWithRelay } from './register.js';
|
|
41
|
+
import { loadPairing, savePairing, pairingFilePath, localMachineKey } from './store.js';
|
|
42
|
+
import { registerWithRelay, probePairing } from './register.js';
|
|
30
43
|
import { showPairing } from './show.js';
|
|
31
44
|
|
|
32
45
|
/**
|
|
@@ -35,11 +48,25 @@ import { showPairing } from './show.js';
|
|
|
35
48
|
* @param {(line: string) => void} ctx.log
|
|
36
49
|
* @returns {Promise<object>} 补全了 pairId/deviceToken/preset 的 relay 配置
|
|
37
50
|
*/
|
|
38
|
-
export async function ensurePairing(relayCfg, { log }) {
|
|
51
|
+
export async function ensurePairing(relayCfg, { log, deps = {} } = {}) {
|
|
39
52
|
const relayUrl = String(relayCfg.url ?? '');
|
|
40
53
|
/** 是否端到端加密。默认开;显式 false 才走明文。 */
|
|
41
54
|
const e2ee = relayCfg.e2ee !== false;
|
|
42
55
|
|
|
56
|
+
/*
|
|
57
|
+
* 依赖注入(2026-11-13):单测要能模拟"本地文件是别人的""中继查不到""中继不可达"
|
|
58
|
+
* 这几种情况,而不能真的去动 ~/.dsh 和网络。默认值就是真实实现。
|
|
59
|
+
*/
|
|
60
|
+
const load = deps.loadPairing ?? loadPairing;
|
|
61
|
+
const save = deps.savePairing ?? savePairing;
|
|
62
|
+
const register = deps.registerWithRelay ?? registerWithRelay;
|
|
63
|
+
const probe = deps.probePairing ?? probePairing;
|
|
64
|
+
const machineKey = deps.localMachineKey ?? localMachineKey;
|
|
65
|
+
const show = deps.showPairing ?? showPairing;
|
|
66
|
+
const filePath = deps.pairingFilePath ?? pairingFilePath;
|
|
67
|
+
const machineName = os.hostname();
|
|
68
|
+
const hostname = deps.hostname ?? (() => machineName);
|
|
69
|
+
|
|
43
70
|
/**
|
|
44
71
|
* DSH Web 界面的端口,用来"等它先弹出来"。
|
|
45
72
|
*
|
|
@@ -49,7 +76,7 @@ export async function ensurePairing(relayCfg, { log }) {
|
|
|
49
76
|
*/
|
|
50
77
|
const dshPort = Number(relayCfg.dshWebPort ?? 3080);
|
|
51
78
|
|
|
52
|
-
const pngPath =
|
|
79
|
+
const pngPath = filePath().replace(/pairing\.json$/, 'pairing-qr.png');
|
|
53
80
|
|
|
54
81
|
// ---- ① 配置里显式给了 ----
|
|
55
82
|
if (relayCfg.pairId && relayCfg.deviceToken) {
|
|
@@ -62,23 +89,75 @@ export async function ensurePairing(relayCfg, { log }) {
|
|
|
62
89
|
e2ee,
|
|
63
90
|
});
|
|
64
91
|
log('配对信息来自插件配置(未使用自动生成的)');
|
|
65
|
-
|
|
92
|
+
log(`本机配对码:${String(relayCfg.pairId).slice(0, 8)}…(本机 ${hostname()})`);
|
|
93
|
+
await show(payload, {
|
|
94
|
+
log, pngPath, dshPort,
|
|
95
|
+
machine: { name: hostname(), pairId: String(relayCfg.pairId) },
|
|
96
|
+
});
|
|
66
97
|
return relayCfg;
|
|
67
98
|
}
|
|
68
99
|
|
|
69
|
-
// ---- ②
|
|
70
|
-
const saved =
|
|
100
|
+
// ---- ② 本地已存:必须"是本机的"且"中继认"才沿用 ----
|
|
101
|
+
const saved = load();
|
|
102
|
+
let regenerated = false;
|
|
71
103
|
if (saved && saved.relayUrl === relayUrl) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
104
|
+
const mine = saved.machineKey === machineKey();
|
|
105
|
+
if (!saved.machineKey) {
|
|
106
|
+
// 老版本插件写的文件:没有指纹,无法证明是本机的 —— 一律重生成
|
|
107
|
+
log('⚠ 本地配对是老版本格式(没有本机指纹),无法确认归属 → 作废重新生成');
|
|
108
|
+
} else if (!mine) {
|
|
109
|
+
// 指纹对不上 = 文件是从别的电脑拷来的/残留的。这是"连到别人电脑"的根因。
|
|
110
|
+
log('⚠ 本地配对不属于这台电脑(文件被拷贝或残留)→ 作废重新生成');
|
|
111
|
+
} else {
|
|
112
|
+
const check = await probe(relayUrl, {
|
|
113
|
+
pairId: saved.pairId,
|
|
114
|
+
deviceToken: saved.deviceToken,
|
|
115
|
+
});
|
|
116
|
+
if (check.ok) {
|
|
117
|
+
const payload = buildPairingPayload({
|
|
118
|
+
relayUrl,
|
|
119
|
+
pairId: saved.pairId,
|
|
120
|
+
deviceToken: saved.deviceToken,
|
|
121
|
+
preset: saved.preset,
|
|
122
|
+
e2ee,
|
|
123
|
+
});
|
|
124
|
+
log(`配对信息来自本地:${filePath()}(本机指纹与中继核对均通过)`);
|
|
125
|
+
log(`本机配对码:${saved.pairId.slice(0, 8)}…(本机 ${hostname()})`);
|
|
126
|
+
await show(payload, {
|
|
127
|
+
log, pngPath, dshPort,
|
|
128
|
+
machine: { name: hostname(), pairId: saved.pairId },
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
...relayCfg,
|
|
132
|
+
pairId: saved.pairId,
|
|
133
|
+
deviceToken: saved.deviceToken,
|
|
134
|
+
preset: saved.preset,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (check.offline) {
|
|
138
|
+
// 断网启动:不能因为核不了就把码作废(下次联网还要重扫,代价更大)
|
|
139
|
+
log(`⚠ 中继暂时不可达,无法核对本地配对(${check.reason ?? '网络问题'})→ 先沿用本机配对`);
|
|
140
|
+
const payload = buildPairingPayload({
|
|
141
|
+
relayUrl,
|
|
142
|
+
pairId: saved.pairId,
|
|
143
|
+
deviceToken: saved.deviceToken,
|
|
144
|
+
preset: saved.preset,
|
|
145
|
+
e2ee,
|
|
146
|
+
});
|
|
147
|
+
await show(payload, {
|
|
148
|
+
log, pngPath, dshPort,
|
|
149
|
+
machine: { name: hostname(), pairId: saved.pairId },
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
...relayCfg,
|
|
153
|
+
pairId: saved.pairId,
|
|
154
|
+
deviceToken: saved.deviceToken,
|
|
155
|
+
preset: saved.preset,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
log(`⚠ 中继上查不到这份配对(${check.reason ?? '未知原因'})→ 重新生成`);
|
|
159
|
+
}
|
|
160
|
+
regenerated = true;
|
|
82
161
|
}
|
|
83
162
|
|
|
84
163
|
// ---- ③ 现生成 ----
|
|
@@ -89,10 +168,14 @@ export async function ensurePairing(relayCfg, { log }) {
|
|
|
89
168
|
deviceToken: secrets.deviceToken,
|
|
90
169
|
// preset 以 hex 存:与配对码、与手机端解析规则一致
|
|
91
170
|
preset: secrets.preset.toString('hex'),
|
|
171
|
+
// 本机指纹 + 机器名(2026-11-13):启动时据此判断这份文件是不是本机生成的
|
|
172
|
+
machineKey: machineKey(),
|
|
173
|
+
machineName: hostname(),
|
|
174
|
+
createdAt: new Date().toISOString(),
|
|
92
175
|
};
|
|
93
176
|
|
|
94
|
-
log('还没有配对信息,正在生成并注册到中继…');
|
|
95
|
-
const reg = await
|
|
177
|
+
log(regenerated ? '正在为本机重新生成配对…' : '还没有配对信息,正在生成并注册到中继…');
|
|
178
|
+
const reg = await register(relayUrl, {
|
|
96
179
|
pairId: info.pairId,
|
|
97
180
|
deviceToken: info.deviceToken,
|
|
98
181
|
});
|
|
@@ -103,14 +186,19 @@ export async function ensurePairing(relayCfg, { log }) {
|
|
|
103
186
|
|
|
104
187
|
// 注册成功才落盘:反过来的话,注册失败会导致本地存了一份中继不认识的码,
|
|
105
188
|
// 下次启动读它、又不注册,就一直连不上。
|
|
106
|
-
|
|
107
|
-
log(`✓ 配对信息已保存:${
|
|
189
|
+
save(info);
|
|
190
|
+
log(`✓ 配对信息已保存:${filePath()}`);
|
|
191
|
+
log(`本机配对码:${info.pairId.slice(0, 8)}…(本机 ${hostname()})`);
|
|
108
192
|
|
|
109
193
|
const payload = buildPairingPayload({ ...info, e2ee });
|
|
110
194
|
// ★ 首次生成:自动把二维码图片打开给用户看。
|
|
111
195
|
// 这是"最需要看见码"的时刻 —— 用户刚装好插件,正等着配对。
|
|
112
196
|
// 之后启动就不弹了(码没变,弹了是骚扰)。
|
|
113
|
-
await
|
|
197
|
+
await show(payload, {
|
|
198
|
+
log, pngPath, dshPort,
|
|
199
|
+
machine: { name: hostname(), pairId: info.pairId },
|
|
200
|
+
regenerated,
|
|
201
|
+
});
|
|
114
202
|
|
|
115
203
|
return { ...relayCfg, pairId: info.pairId, deviceToken: info.deviceToken, preset: info.preset };
|
|
116
204
|
}
|
package/pairing/page.js
CHANGED
|
@@ -50,6 +50,12 @@ export const RESET_DEVICE_COMMAND = 'python3 scripts/reset-device-auth.py';
|
|
|
50
50
|
* 【为什么】:完整 deviceId 是这台手机的稳定标识,不需要整条出现在屏幕/截图里
|
|
51
51
|
* (用户经常把配对页截图发人问"这样对不对")。前 8 位足够他和设置页对上号。
|
|
52
52
|
*/
|
|
53
|
+
/** 配对码前 8 位(页面上给人核对用的短码,不暴露完整 pairId)。 */
|
|
54
|
+
export function shortPairId(pairId) {
|
|
55
|
+
const text = String(pairId ?? '');
|
|
56
|
+
return text.length > 8 ? `${text.slice(0, 8)}…` : text;
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
export function shortDeviceId(deviceId) {
|
|
54
60
|
const text = String(deviceId ?? '');
|
|
55
61
|
return text.length > 8 ? `${text.slice(0, 8)}…` : text;
|
|
@@ -85,9 +91,27 @@ export function formatAuthorizedAt(isoText) {
|
|
|
85
91
|
* @param {string} [opts.resetCommand] 重置命令(测试可覆盖,默认 RESET_DEVICE_COMMAND)
|
|
86
92
|
* @returns {string} 完整的 HTML 文档
|
|
87
93
|
*/
|
|
88
|
-
export function pairingPageHtml({
|
|
94
|
+
export function pairingPageHtml({
|
|
95
|
+
payload,
|
|
96
|
+
pngName,
|
|
97
|
+
device = null,
|
|
98
|
+
resetCommand = RESET_DEVICE_COMMAND,
|
|
99
|
+
machine = null,
|
|
100
|
+
regenerated = false,
|
|
101
|
+
}) {
|
|
89
102
|
const code = escapeHtml(payload);
|
|
90
103
|
|
|
104
|
+
/*
|
|
105
|
+
* 本机身份行(2026-11-13 加):
|
|
106
|
+
* 配对页必须能回答"这个码是哪台电脑的" —— 用户截图/扫码给客服核对时要能对上。
|
|
107
|
+
* 顺带在"重新生成"时明说一句,免得用户拿旧截图去扫(旧码已作废)。
|
|
108
|
+
*/
|
|
109
|
+
const machineHtml = machine
|
|
110
|
+
? `<p class="machine">本机:<b>${escapeHtml(machine.name)}</b> · 配对码 <b>${escapeHtml(
|
|
111
|
+
shortPairId(machine.pairId),
|
|
112
|
+
)}</b>${regenerated ? '<span class="regen">(本次已重新生成,旧截图/旧码已作废)</span>' : ''}</p>`
|
|
113
|
+
: '';
|
|
114
|
+
|
|
91
115
|
/*
|
|
92
116
|
* 设备授权那一段的两种样子。
|
|
93
117
|
*
|
|
@@ -164,6 +188,16 @@ export function pairingPageHtml({ payload, pngName, device = null, resetCommand
|
|
|
164
188
|
max-width: 560px;
|
|
165
189
|
text-align: center;
|
|
166
190
|
}
|
|
191
|
+
.machine {
|
|
192
|
+
margin: 10px 0 0;
|
|
193
|
+
font-size: 12px;
|
|
194
|
+
line-height: 1.6;
|
|
195
|
+
color: #6e6e73;
|
|
196
|
+
text-align: center;
|
|
197
|
+
word-break: break-all;
|
|
198
|
+
}
|
|
199
|
+
.machine b { color: #1c1c1e; font-weight: 600; }
|
|
200
|
+
.machine .regen { color: #c2410c; }
|
|
167
201
|
.fallback .hint {
|
|
168
202
|
margin: 0 0 10px;
|
|
169
203
|
font-size: 13px;
|
|
@@ -296,6 +330,7 @@ export function pairingPageHtml({ payload, pngName, device = null, resetCommand
|
|
|
296
330
|
<img class="qr" src="${escapeHtml(pngName)}" alt="配对二维码">
|
|
297
331
|
|
|
298
332
|
<p class="lead">用手机上的「鲸编程」App 扫下面这个二维码</p>
|
|
333
|
+
${machineHtml}
|
|
299
334
|
|
|
300
335
|
<div class="fallback">
|
|
301
336
|
<p class="hint">扫不出来?将下面的配对码复制粘贴到手机App的「手动输入框」</p>
|
package/pairing/register.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function registerWithRelay(relayUrl, { pairId, deviceToken }) {
|
|
|
40
40
|
});
|
|
41
41
|
const body = await res.json().catch(() => ({}));
|
|
42
42
|
if (res.ok && body.ok) {
|
|
43
|
-
return { ok: true, pairings: body.pairings };
|
|
43
|
+
return { ok: true, pairings: body.pairings, createdAt: body.createdAt ?? 0 };
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
46
|
ok: false,
|
|
@@ -79,3 +79,36 @@ function describeFetchError(err) {
|
|
|
79
79
|
return err?.cause?.message ? `${err.message}(${err.cause.message})` : String(err?.message ?? err);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 向中继**核对**一份本地配对还在不在(2026-11-13 加,只读)。
|
|
86
|
+
*
|
|
87
|
+
* 为什么需要:本地 pairing.json 可能被拷来/残留,里面的 pairId 可能属于别人;
|
|
88
|
+
* 光看文件看不出来。启动时拿 pairId+设备令牌问一次中继:
|
|
89
|
+
* · 200 → 这份配对在中继上有效,可以沿用;
|
|
90
|
+
* · 404 → 中继上查不到(被别人注销了/根本不是这台电脑注册的)→ 必须重新生成;
|
|
91
|
+
* · 网络失败 → `offline: true`,**不能因此作废本地配对**(断网启动还得能用)。
|
|
92
|
+
*
|
|
93
|
+
* @returns {Promise<{ok: boolean, offline?: boolean, registeredAt?: number, reason?: string}>}
|
|
94
|
+
*/
|
|
95
|
+
export async function probePairing(relayUrl, { pairId, deviceToken, timeoutMs = 5000 } = {}) {
|
|
96
|
+
const base = httpBase(relayUrl);
|
|
97
|
+
try {
|
|
98
|
+
const res = await fetch(`${base}/pair/probe`, {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers: { 'Content-Type': 'application/json' },
|
|
101
|
+
body: JSON.stringify({ pairId, deviceToken }),
|
|
102
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
103
|
+
});
|
|
104
|
+
if (res.ok) {
|
|
105
|
+
const body = await res.json().catch(() => ({}));
|
|
106
|
+
if (body && body.ok) return { ok: true, registeredAt: body.registeredAt ?? 0 };
|
|
107
|
+
return { ok: false, reason: '中继返回异常' };
|
|
108
|
+
}
|
|
109
|
+
if (res.status === 404) return { ok: false, reason: '中继上查不到这份配对' };
|
|
110
|
+
return { ok: false, reason: `中继核对失败(HTTP ${res.status})` };
|
|
111
|
+
} catch (err) {
|
|
112
|
+
return { ok: false, offline: true, reason: describeFetchError(err) };
|
|
113
|
+
}
|
|
114
|
+
}
|
package/pairing/show.js
CHANGED
|
@@ -70,7 +70,10 @@ function openWithSystem(filePath) {
|
|
|
70
70
|
* @param {number} [opts.dshPort] DSH Web 界面的端口(用于等它先弹出)
|
|
71
71
|
* @param {string} [opts.deviceAuthFile] 授权设备文件(默认 ~/.dsh/jbc-dssi/authorized-device.json,测试/多实例用)
|
|
72
72
|
*/
|
|
73
|
-
export async function showPairing(
|
|
73
|
+
export async function showPairing(
|
|
74
|
+
payload,
|
|
75
|
+
{ log, pngPath, dshPort, deviceAuthFile, machine = null, regenerated = false },
|
|
76
|
+
) {
|
|
74
77
|
const dir = path.dirname(pngPath);
|
|
75
78
|
const pngName = path.basename(pngPath);
|
|
76
79
|
const htmlPath = path.join(dir, 'pairing.html');
|
|
@@ -96,7 +99,11 @@ export async function showPairing(payload, { log, pngPath, dshPort, deviceAuthFi
|
|
|
96
99
|
try {
|
|
97
100
|
fs.mkdirSync(dir, { recursive: true });
|
|
98
101
|
fs.writeFileSync(pngPath, qrToPng(payload, { scale: 10, margin: 4 }));
|
|
99
|
-
fs.writeFileSync(
|
|
102
|
+
fs.writeFileSync(
|
|
103
|
+
htmlPath,
|
|
104
|
+
pairingPageHtml({ payload, pngName, device, machine, regenerated }),
|
|
105
|
+
'utf8',
|
|
106
|
+
);
|
|
100
107
|
pageOk = true;
|
|
101
108
|
} catch (err) {
|
|
102
109
|
log(` ⚠ 配对网页没能生成:${err?.message ?? err}`);
|
|
@@ -129,6 +136,11 @@ export async function showPairing(payload, { log, pngPath, dshPort, deviceAuthFi
|
|
|
129
136
|
log(' (访达里按 ⌘⇧G,把上面这行粘进去回车)');
|
|
130
137
|
}
|
|
131
138
|
|
|
139
|
+
if (machine) {
|
|
140
|
+
log(` 本机:${machine.name} · 配对码 ${String(machine.pairId).slice(0, 8)}…`);
|
|
141
|
+
if (regenerated) log(' ⚠ 本次是本机重新生成的新码,旧截图/旧码已作废,请用这个页面上的码。');
|
|
142
|
+
log('');
|
|
143
|
+
}
|
|
132
144
|
log('');
|
|
133
145
|
log(' 扫不出来?在 App 里点「手工输入配对码」,粘贴下面这一整行:');
|
|
134
146
|
log('');
|
package/pairing/store.js
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
import fs from 'node:fs';
|
|
25
25
|
import path from 'node:path';
|
|
26
26
|
import os from 'node:os';
|
|
27
|
+
import { createHash } from 'node:crypto';
|
|
27
28
|
|
|
28
29
|
/** 数据目录。放在 DSH 家目录下,与插件代码分离。 */
|
|
29
30
|
const DIR = path.join(os.homedir(), '.dsh', 'jbc-dssi');
|
|
@@ -36,6 +37,27 @@ export function pairingFilePath() {
|
|
|
36
37
|
return FILE;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* 本机身份指纹(2026-11-13 老谢真机事故后加)。
|
|
42
|
+
*
|
|
43
|
+
* 【它防的是什么】
|
|
44
|
+
* 配对文件里如果有别人的 pairId/令牌/密钥,插件却把它当"本机的码"弹出来,
|
|
45
|
+
* 用户扫码就会连到**别人的电脑**(真发生过:新用户扫"自己的码"连到了老谢的电脑,
|
|
46
|
+
* 因为那台电脑上的 ~/.dsh 是从别人那儿拷来的/残留的)。
|
|
47
|
+
*
|
|
48
|
+
* 【为什么用"主机名 + 家目录 + 平台"算,而不是存一个随机 id】
|
|
49
|
+
* 存随机 id 没用 —— 文件被拷到另一台电脑,id 跟着一起走,照样"匹配"。
|
|
50
|
+
* 必须用**不随文件走**的东西:主机名、家目录、平台都是本机环境固有的。
|
|
51
|
+
* 它们一起哈希后,同一台电脑稳定,拷到别的电脑必然不同。
|
|
52
|
+
*
|
|
53
|
+
* 注意:这台电脑上如果换过主机名/用户名,指纹会变 → 配对会被判为"外来"而重新生成,
|
|
54
|
+
* 用户需要重扫一次码。这是一次性的、可接受的代价(比连错电脑好得多)。
|
|
55
|
+
*/
|
|
56
|
+
export function localMachineKey() {
|
|
57
|
+
const raw = [os.hostname(), os.homedir(), process.platform].join('|');
|
|
58
|
+
return createHash('sha256').update(raw).digest('hex').slice(0, 32);
|
|
59
|
+
}
|
|
60
|
+
|
|
39
61
|
/**
|
|
40
62
|
* 读配对信息。
|
|
41
63
|
*
|