@dsh-mobile/mobile-remote 3.3.0 → 3.4.0
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/FAQ.md +2 -2
- package/LICENSE +0 -0
- package/README.md +13 -8
- package/docs/PRIVACY-POLICY.en.md +26 -18
- package/docs/PRIVACY-POLICY.md +26 -18
- package/docs/SUPPORT.md +1 -1
- package/docs/TERMS-OF-SERVICE.en.md +5 -3
- package/docs/TERMS-OF-SERVICE.md +5 -3
- package/docs/USER-GUIDE.zh-CN.md +7 -6
- package/lib/account-usage-query.js +60 -60
- package/lib/account-usage.js +10 -10
- package/lib/api-helpers.js +114 -110
- package/lib/assistant-prefs.js +119 -76
- package/lib/auto-config.js +65 -65
- package/lib/backup.js +159 -123
- package/lib/break-reminder.js +45 -45
- package/lib/client.js +336 -138
- package/lib/config.js +234 -218
- package/lib/git-read-bundled-provider.js +27 -7
- package/lib/git-read-service.js +5 -5
- package/lib/host-compat.js +84 -84
- package/lib/http-util.js +17 -17
- package/lib/index.js +1670 -1511
- package/lib/memory/context.js +45 -40
- package/lib/memory/decay.js +93 -93
- package/lib/memory/extract.js +77 -77
- package/lib/memory/routes.js +33 -33
- package/lib/memory/store.js +239 -192
- package/lib/notify-copy.js +93 -93
- package/lib/permission-guide.js +86 -86
- package/lib/persona-cards.js +73 -61
- package/lib/phone-action-args.js +175 -0
- package/lib/phone-actions.js +227 -0
- package/lib/phone-announce.js +58 -0
- package/lib/proactive-material.js +42 -42
- package/lib/proactive.js +122 -119
- package/lib/protected-paths.js +205 -45
- package/lib/protocol.js +62 -23
- package/lib/push.js +29 -29
- package/lib/rate-limit.js +16 -16
- package/lib/relay/connector.js +334 -81
- package/lib/relay/crypto.js +15 -15
- package/lib/relay/devices.js +64 -32
- package/lib/relay/fingerprint.js +34 -34
- package/lib/relay/identity.js +26 -26
- package/lib/relay/mux.js +60 -46
- package/lib/relay/noise.js +40 -40
- package/lib/relay/on-demand.js +36 -31
- package/lib/relay/p2p.js +239 -0
- package/lib/relay/pairing.js +54 -15
- package/lib/relay/phone.js +63 -39
- package/lib/relay/serve.js +21 -21
- package/lib/relay/signal.js +69 -0
- package/lib/relay/ws-server.js +245 -0
- package/lib/reminders.js +15 -15
- package/lib/rpc-adapter.js +43 -43
- package/lib/session-list.js +31 -31
- package/lib/session-rotation.js +95 -95
- package/lib/session-title-cache.js +35 -35
- package/lib/session-title-refresh.js +51 -51
- package/lib/timeline.js +140 -140
- package/lib/turn-outline.js +104 -104
- package/package.json +11 -18
package/lib/auto-config.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
15
|
import { randomBytes } from "node:crypto";
|
|
16
16
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
17
17
|
import { homedir } from "node:os";
|
|
18
18
|
import { join } from "node:path";
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
export const AUTO = "@auto";
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
const SAVED_TOKEN_RE = /^[A-Za-z0-9_-]{24,128}$/;
|
|
25
25
|
|
|
26
26
|
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
export function mobileRemoteStateDir(env = process.env, home = homedir()) {
|
|
30
30
|
const base = typeof env.DSH_HOME === "string" && env.DSH_HOME.trim() !== "" ? env.DSH_HOME : join(home, ".dsh");
|
|
31
31
|
return join(base, "mobile-remote");
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
41
|
export function resolveAuthToken(configured, { dir = mobileRemoteStateDir(), generate = () => randomBytes(24).toString("base64url") } = {}) {
|
|
42
42
|
if (configured !== AUTO) return { token: configured ?? "", auto: false };
|
|
43
43
|
const file = join(dir, "auth-token");
|
|
@@ -47,7 +47,7 @@ export function resolveAuthToken(configured, { dir = mobileRemoteStateDir(), gen
|
|
|
47
47
|
if (SAVED_TOKEN_RE.test(saved)) return { token: saved, auto: true, generated: false, file };
|
|
48
48
|
}
|
|
49
49
|
} catch {
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
}
|
|
52
52
|
const token = generate();
|
|
53
53
|
try {
|
|
@@ -61,39 +61,39 @@ export function resolveAuthToken(configured, { dir = mobileRemoteStateDir(), gen
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
72
|
export function isLoopbackOnly({ webHost, lanBridgeEnabled = false, trustedHosts = [], relayEnabled = false } = {}) {
|
|
73
73
|
if (typeof webHost !== "string" || !LOOPBACK_HOSTS.has(webHost.trim().toLowerCase())) return false;
|
|
74
74
|
if (lanBridgeEnabled || relayEnabled) return false;
|
|
75
75
|
return !(Array.isArray(trustedHosts) && trustedHosts.length > 0);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
87
|
export function effectiveAuthSetting(configured, reach = {}) {
|
|
88
88
|
if (typeof configured === "string" && configured !== "") return configured;
|
|
89
89
|
return isLoopbackOnly(reach) ? "" : AUTO;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
97
|
export function rotateAuthToken({ dir = mobileRemoteStateDir(), generate = () => randomBytes(24).toString("base64url") } = {}) {
|
|
98
98
|
const file = join(dir, "auth-token");
|
|
99
99
|
const token = generate();
|
|
@@ -104,35 +104,35 @@ export function rotateAuthToken({ dir = mobileRemoteStateDir(), generate = () =>
|
|
|
104
104
|
return { token, file };
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
112
|
export function resolveLanBridgeEnabled(setting, { webHost, webPort, bridgePort } = {}) {
|
|
113
113
|
if (setting !== "auto") return Boolean(setting);
|
|
114
114
|
if (typeof webHost === "string" && webHost !== "") return LOOPBACK_HOSTS.has(webHost.toLowerCase());
|
|
115
115
|
return !(webPort !== undefined && bridgePort === webPort);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
123
|
export function resolveLanBridgePort(setting, port, webPort) {
|
|
124
124
|
if (setting === "auto" && webPort !== undefined && port === webPort) return port < 65535 ? port + 1 : port - 1;
|
|
125
125
|
return port;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
136
|
export function formatConnectionBanner({ addresses, token, tokenIsAuto, tokenNew = true, tokenFile, persistError, authEnabled = true }) {
|
|
137
137
|
const [first, ...rest] = addresses;
|
|
138
138
|
const lines = ["mobile-remote ▶ 手机 App 连接信息 / Phone app connection"];
|
package/lib/backup.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import { createCipheriv, createDecipheriv, randomBytes,
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
import { createCipheriv, createDecipheriv, randomBytes, scrypt } from "node:crypto";
|
|
24
24
|
import { SCOPES } from "./memory/store.js";
|
|
25
25
|
import { parseHm } from "./notify-copy.js";
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
export const BACKUP_FORMAT = "dsh-mobile-backup";
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
export const BACKUP_VERSION = 1;
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
const MAX_TEXT = 4000;
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
export const MAX_RESTORE_ITEMS = 5000;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
44
|
export const MAX_RESTORE_BODY_BYTES = 32 * 1024 * 1024;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
50
|
export const BACKUP_EXCLUDES = [
|
|
51
51
|
"auth-token(连接口令)",
|
|
52
52
|
"relay/(中继身份私钥与设备名单)",
|
|
@@ -55,22 +55,22 @@ export const BACKUP_EXCLUDES = [
|
|
|
55
55
|
"session-titles / session-activity / session-message-time(与本机会话 id 绑定)",
|
|
56
56
|
];
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
66
|
export function buildBackup({ store, prefs, now = () => Date.now() }) {
|
|
67
67
|
const memories = store ? store.exportAll() : [];
|
|
68
68
|
return {
|
|
69
69
|
format: BACKUP_FORMAT,
|
|
70
70
|
version: BACKUP_VERSION,
|
|
71
71
|
createdAt: new Date(now()).toISOString(),
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
|
|
73
|
+
|
|
74
74
|
excludes: BACKUP_EXCLUDES,
|
|
75
75
|
assistant: prefs?.get?.() ?? null,
|
|
76
76
|
memories: memories.map((m) => ({
|
|
@@ -79,55 +79,91 @@ export function buildBackup({ store, prefs, now = () => Date.now() }) {
|
|
|
79
79
|
source: m.source === "manual" ? "manual" : "conversation",
|
|
80
80
|
origin: m.origin ?? null,
|
|
81
81
|
pinned: Boolean(m.pinned),
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
|
|
83
|
+
|
|
84
84
|
stability: typeof m.stability === "number" ? m.stability : undefined,
|
|
85
85
|
difficulty: typeof m.difficulty === "number" ? m.difficulty : undefined,
|
|
86
86
|
lastRecalledAt:
|
|
87
87
|
typeof m.lastRecalledAt === "number" ? m.lastRecalledAt : undefined,
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
|
|
89
|
+
|
|
90
90
|
})),
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
// ── 备份口令(T-63,可选)────────────────────────────────────────────────
|
|
95
|
-
//
|
|
96
|
-
// 不设口令时备份是明文 JSON(原样可读,便于用户自己检查)。设了口令时整份备份用
|
|
97
|
-
// scrypt 派生的密钥做 AES-256-GCM 加密,文件里只剩格式标记与密文:拿到文件但不知道
|
|
98
|
-
// 口令的人读不到任何一条记忆。口令只在请求里出现一次,插件不保存它。
|
|
99
|
-
|
|
100
|
-
/** 口令最短长度。太短的口令配上离线暴力破解等于没设。 */
|
|
101
|
-
export const MIN_BACKUP_PASSPHRASE = 8;
|
|
102
|
-
|
|
103
|
-
const KDF = { name: "scrypt", N: 1 << 15, r: 8, p: 1, keyLen: 32 };
|
|
104
|
-
const deriveKey = (passphrase, salt, kdf = KDF) =>
|
|
105
|
-
scryptSync(String(passphrase).normalize("NFC"), salt, kdf.keyLen ?? 32, {
|
|
106
|
-
N: kdf.N,
|
|
107
|
-
r: kdf.r,
|
|
108
|
-
p: kdf.p,
|
|
109
|
-
maxmem: 256 * kdf.N * kdf.r + 1024 * 1024,
|
|
110
|
-
});
|
|
111
94
|
|
|
112
|
-
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
export const MIN_BACKUP_PASSPHRASE = 15;
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
const COMMON_PASSPHRASES = new Set([
|
|
109
|
+
"passwordpassword", "password1234567", "123456789012345", "1234567890123456", "qwertyuiopasdfg",
|
|
110
|
+
"qwertyuiopasdfgh", "1q2w3e4r5t6y7u8i", "iloveyouiloveyou", "abcdefghijklmno", "abcdefghijklmnop",
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
export function passphraseProblem(passphrase) {
|
|
115
|
+
if (typeof passphrase !== "string") return `口令至少 ${MIN_BACKUP_PASSPHRASE} 个字符 / the passphrase needs at least ${MIN_BACKUP_PASSPHRASE} characters`;
|
|
116
|
+
const chars = [...passphrase.normalize("NFC")];
|
|
117
|
+
if (chars.length < MIN_BACKUP_PASSPHRASE) return `口令至少 ${MIN_BACKUP_PASSPHRASE} 个字符 / the passphrase needs at least ${MIN_BACKUP_PASSPHRASE} characters`;
|
|
118
|
+
const folded = chars.join("").toLowerCase();
|
|
119
|
+
if (new Set(chars.filter((c) => c.trim() !== "")).size < 5 || /^(.+?)\1+$/su.test(folded) || COMMON_PASSPHRASES.has(folded.replace(/\s+/g, ""))) {
|
|
120
|
+
return "这个口令太容易猜 / this passphrase is too easy to guess: use a few unrelated words";
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
const KDF = { name: "scrypt", N: 1 << 17, r: 8, p: 1, keyLen: 32 };
|
|
131
|
+
const ACCEPTED_KDF = [KDF, { name: "scrypt", N: 1 << 15, r: 8, p: 1, keyLen: 32 }];
|
|
132
|
+
export const BACKUP_KDF = Object.freeze({ ...KDF });
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
let kdfQueue = Promise.resolve();
|
|
136
|
+
const deriveKey = (passphrase, salt, kdf = KDF) => {
|
|
137
|
+
const run = () =>
|
|
138
|
+
new Promise((resolve, reject) =>
|
|
139
|
+
scrypt(String(passphrase).normalize("NFC"), salt, kdf.keyLen ?? 32, { N: kdf.N, r: kdf.r, p: kdf.p, maxmem: 256 * kdf.N * kdf.r + 1024 * 1024 }, (err, key) =>
|
|
140
|
+
err ? reject(err) : resolve(key),
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
const next = kdfQueue.then(run, run);
|
|
144
|
+
kdfQueue = next.catch(() => {});
|
|
145
|
+
return next;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
|
|
113
149
|
export function isEncryptedBackup(payload) {
|
|
114
150
|
return Boolean(payload && typeof payload === "object" && payload.encrypted && typeof payload.encrypted === "object");
|
|
115
151
|
}
|
|
116
152
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
export async function encryptBackup(backup, passphrase) {
|
|
160
|
+
const problem = passphraseProblem(passphrase);
|
|
161
|
+
if (problem) throw Object.assign(new Error(problem), { code: "weak-passphrase" });
|
|
126
162
|
const salt = randomBytes(16);
|
|
127
163
|
const iv = randomBytes(12);
|
|
128
|
-
const key = deriveKey(passphrase, salt);
|
|
164
|
+
const key = await deriveKey(passphrase, salt);
|
|
129
165
|
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
130
|
-
|
|
166
|
+
|
|
131
167
|
cipher.setAAD(Buffer.from(`${BACKUP_FORMAT}/${BACKUP_VERSION}`));
|
|
132
168
|
const data = Buffer.concat([cipher.update(JSON.stringify(backup), "utf8"), cipher.final()]);
|
|
133
169
|
return {
|
|
@@ -143,11 +179,11 @@ export function encryptBackup(backup, passphrase) {
|
|
|
143
179
|
};
|
|
144
180
|
}
|
|
145
181
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
export function decryptBackup(envelope, passphrase) {
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
export async function decryptBackup(envelope, passphrase) {
|
|
151
187
|
const e = envelope?.encrypted;
|
|
152
188
|
if (!e || e.cipher !== "aes-256-gcm" || e.kdf?.name !== "scrypt") {
|
|
153
189
|
throw Object.assign(new Error("不认识的加密格式 / unknown encryption format"), { code: "bad-backup" });
|
|
@@ -155,12 +191,12 @@ export function decryptBackup(envelope, passphrase) {
|
|
|
155
191
|
if (typeof passphrase !== "string" || passphrase === "") {
|
|
156
192
|
throw Object.assign(new Error("这份备份设了口令 / this backup needs its passphrase"), { code: "passphrase-required" });
|
|
157
193
|
}
|
|
158
|
-
|
|
159
|
-
|
|
194
|
+
|
|
195
|
+
|
|
160
196
|
const N = Number(e.kdf.N);
|
|
161
197
|
const r = Number(e.kdf.r);
|
|
162
198
|
const p = Number(e.kdf.p);
|
|
163
|
-
if (
|
|
199
|
+
if (!ACCEPTED_KDF.some((k) => k.N === N && k.r === r && k.p === p)) {
|
|
164
200
|
throw Object.assign(new Error("加密参数不是本插件写的 / encryption parameters not written by this plugin"), { code: "bad-backup" });
|
|
165
201
|
}
|
|
166
202
|
const tag = Buffer.from(String(e.tag), "base64");
|
|
@@ -168,8 +204,8 @@ export function decryptBackup(envelope, passphrase) {
|
|
|
168
204
|
throw Object.assign(new Error("口令不对,或文件已损坏 / wrong passphrase, or the file is damaged"), { code: "bad-passphrase" });
|
|
169
205
|
}
|
|
170
206
|
try {
|
|
171
|
-
const key = deriveKey(passphrase, Buffer.from(String(e.kdf.salt), "base64"), { N, r, p, keyLen: 32 });
|
|
172
|
-
|
|
207
|
+
const key = await deriveKey(passphrase, Buffer.from(String(e.kdf.salt), "base64"), { N, r, p, keyLen: 32 });
|
|
208
|
+
|
|
173
209
|
const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(String(e.iv), "base64"), { authTagLength: 16 });
|
|
174
210
|
decipher.setAAD(Buffer.from(`${envelope.format}/${envelope.version}`));
|
|
175
211
|
decipher.setAuthTag(tag);
|
|
@@ -180,11 +216,11 @@ export function decryptBackup(envelope, passphrase) {
|
|
|
180
216
|
}
|
|
181
217
|
}
|
|
182
218
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
188
224
|
function validateMemory(raw, index) {
|
|
189
225
|
if (!raw || typeof raw !== "object") {
|
|
190
226
|
return { ok: false, reason: "不是对象", index };
|
|
@@ -202,7 +238,7 @@ function validateMemory(raw, index) {
|
|
|
202
238
|
return { ok: false, reason: `text 超过 ${MAX_TEXT} 字符`, index };
|
|
203
239
|
}
|
|
204
240
|
if (raw.deleted === true) {
|
|
205
|
-
|
|
241
|
+
|
|
206
242
|
return { ok: false, reason: "备份里这条已删除", index };
|
|
207
243
|
}
|
|
208
244
|
return {
|
|
@@ -218,15 +254,15 @@ function validateMemory(raw, index) {
|
|
|
218
254
|
};
|
|
219
255
|
}
|
|
220
256
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
230
266
|
export function planRestore(payload, { store, prefs }) {
|
|
231
267
|
const empty = {
|
|
232
268
|
ok: false,
|
|
@@ -249,8 +285,8 @@ export function planRestore(payload, { store, prefs }) {
|
|
|
249
285
|
return { ...empty, error: "备份版本号缺失或非法" };
|
|
250
286
|
}
|
|
251
287
|
if (payload.version > BACKUP_VERSION) {
|
|
252
|
-
|
|
253
|
-
|
|
288
|
+
|
|
289
|
+
|
|
254
290
|
return {
|
|
255
291
|
...empty,
|
|
256
292
|
error: `备份来自更新的版本(v${payload.version}),请先升级插件`,
|
|
@@ -268,8 +304,8 @@ export function planRestore(payload, { store, prefs }) {
|
|
|
268
304
|
};
|
|
269
305
|
}
|
|
270
306
|
|
|
271
|
-
|
|
272
|
-
|
|
307
|
+
|
|
308
|
+
|
|
273
309
|
const existing = new Set();
|
|
274
310
|
if (store) {
|
|
275
311
|
for (const mode of ["work", "life"]) {
|
|
@@ -305,8 +341,8 @@ export function planRestore(payload, { store, prefs }) {
|
|
|
305
341
|
items.push(v.item);
|
|
306
342
|
});
|
|
307
343
|
|
|
308
|
-
|
|
309
|
-
|
|
344
|
+
|
|
345
|
+
|
|
310
346
|
let assistant = null;
|
|
311
347
|
const a = payload.assistant;
|
|
312
348
|
if (a && typeof a === "object") {
|
|
@@ -316,9 +352,9 @@ export function planRestore(payload, { store, prefs }) {
|
|
|
316
352
|
next.persona = a.persona;
|
|
317
353
|
}
|
|
318
354
|
const q = a.quietHours;
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
322
358
|
if (
|
|
323
359
|
q &&
|
|
324
360
|
typeof q === "object" &&
|
|
@@ -348,13 +384,13 @@ export function planRestore(payload, { store, prefs }) {
|
|
|
348
384
|
};
|
|
349
385
|
}
|
|
350
386
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
358
394
|
export function applyRestore(payload, { store, prefs }) {
|
|
359
395
|
const plan = planRestore(payload, { store, prefs });
|
|
360
396
|
if (!plan.ok) {
|
|
@@ -380,7 +416,7 @@ export function applyRestore(payload, { store, prefs }) {
|
|
|
380
416
|
});
|
|
381
417
|
added += 1;
|
|
382
418
|
} catch (err) {
|
|
383
|
-
|
|
419
|
+
|
|
384
420
|
plan.skipped.push({ index: -1, reason: err?.message ?? "写入失败" });
|
|
385
421
|
}
|
|
386
422
|
}
|
|
@@ -391,13 +427,13 @@ export function applyRestore(payload, { store, prefs }) {
|
|
|
391
427
|
prefs.set(plan.assistant);
|
|
392
428
|
assistant = true;
|
|
393
429
|
} catch {
|
|
394
|
-
|
|
430
|
+
|
|
395
431
|
}
|
|
396
432
|
}
|
|
397
433
|
return {
|
|
398
434
|
ok: true,
|
|
399
435
|
added,
|
|
400
|
-
|
|
436
|
+
|
|
401
437
|
skipped: plan.skipped.length,
|
|
402
438
|
invalid: plan.counts.invalid,
|
|
403
439
|
assistant,
|