@vrtmrz/livesync-commonlib 0.4.1 → 0.4.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 +16 -2
- package/dist/API/DirectFileManipulatorV2.d.ts +1 -0
- package/dist/API/DirectFileManipulatorV2.js +3 -1
- package/dist/API/processSetting.d.ts +1 -0
- package/dist/API/processSetting.js +3 -0
- package/dist/common/models/setting.const.defaults.js +1 -0
- package/dist/common/models/setting.const.qr.js +2 -1
- package/dist/common/models/setting.encryption.d.ts +2 -0
- package/dist/common/models/setting.encryption.js +6 -0
- package/dist/common/models/setting.lifecycle.js +7 -2
- package/dist/common/models/setting.policy.d.ts +4 -0
- package/dist/common/models/setting.policy.js +9 -0
- package/dist/common/models/setting.type.d.ts +2 -0
- package/dist/common/models/shared.definition.configNames.js +5 -0
- package/dist/common/models/tweak.definition.d.ts +1 -0
- package/dist/common/settingConstants.d.ts +1 -0
- package/dist/common/utils.js +5 -4
- package/dist/diagnostics/couchdb.js +4 -2
- package/dist/interfaces/FileHandler.d.ts +59 -0
- package/dist/interfaces/FileReflectionProvenance.d.ts +15 -1
- package/dist/interfaces/FileReflectionProvenance.js +11 -1
- package/dist/managers/ChunkFetcher.js +27 -4
- package/dist/managers/chunkFetcher.helper.js +1 -1
- package/dist/pouchdb/StreamingFetch.d.ts +1 -2
- package/dist/pouchdb/encryption.d.ts +5 -10
- package/dist/pouchdb/encryption.eden.d.ts +11 -0
- package/dist/pouchdb/encryption.eden.js +37 -0
- package/dist/pouchdb/encryption.js +67 -63
- package/dist/pouchdb/encryption.policy.d.ts +9 -0
- package/dist/pouchdb/encryption.policy.js +125 -0
- package/dist/replication/UnencryptedContentRejectedError.d.ts +16 -0
- package/dist/replication/UnencryptedContentRejectedError.js +44 -0
- package/dist/replication/couchdb/LiveSyncReplicator.js +41 -4
- package/dist/replication/index.d.ts +2 -0
- package/dist/replication/index.js +3 -0
- package/dist/replication/trystero/TrysteroReplicator.d.ts +2 -0
- package/dist/replication/unencryptedContentMessages.d.ts +8 -0
- package/dist/replication/unencryptedContentMessages.js +12 -0
- package/dist/serviceFeatures/offlineScanner/fileStatus.d.ts +61 -0
- package/dist/serviceFeatures/offlineScanner/fileStatus.js +85 -0
- package/dist/serviceFeatures/offlineScanner/files.d.ts +47 -0
- package/dist/serviceFeatures/offlineScanner/files.js +218 -0
- package/dist/serviceFeatures/offlineScanner/metadata.d.ts +56 -0
- package/dist/serviceFeatures/offlineScanner/metadata.js +320 -0
- package/dist/serviceFeatures/offlineScanner/paths.d.ts +20 -0
- package/dist/serviceFeatures/offlineScanner/paths.js +16 -0
- package/dist/serviceFeatures/offlineScanner/scan.d.ts +35 -0
- package/dist/serviceFeatures/offlineScanner/scan.js +358 -0
- package/dist/serviceFeatures/offlineScanner/types.d.ts +134 -0
- package/dist/serviceFeatures/offlineScanner/types.js +66 -0
- package/dist/serviceFeatures/offlineScanner.d.ts +25 -251
- package/dist/serviceFeatures/offlineScanner.js +36 -860
- package/dist/serviceModules/Rebuilder.js +28 -4
- package/dist/serviceModules/ServiceFileHandlerBase/deletionRecovery.d.ts +13 -0
- package/dist/serviceModules/ServiceFileHandlerBase/deletionRecovery.js +194 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +22 -1
- package/dist/serviceModules/ServiceFileHandlerBase.js +29 -0
- package/dist/services/base/KeyValueDBService.d.ts +9 -0
- package/dist/services/base/KeyValueDBService.js +11 -1
- package/dist/services/base/RemoteConnection.d.ts +2 -0
- package/dist/services/base/RemoteService.js +2 -1
- package/dist/services/base/SettingService.js +2 -0
- package/dist/settings.d.ts +2 -1
- package/dist/settings.js +2 -0
- package/dist/worker/bgWorker.js +1 -1
- package/docs/development.md +4 -0
- package/docs/offline-scanner.md +22 -0
- package/docs/settings-lifecycle.md +4 -0
- package/docs/storage-events-and-reflection.md +16 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,8 +14,11 @@ This package is primarily for maintainers of those clients and for integrations
|
|
|
14
14
|
|
|
15
15
|
## Status and versioning
|
|
16
16
|
|
|
17
|
-
Commonlib [0.
|
|
18
|
-
is published on npm
|
|
17
|
+
Commonlib [0.4.2](https://www.npmjs.com/package/@vrtmrz/livesync-commonlib/v/0.4.2)
|
|
18
|
+
is published on npm through `latest` and `next`
|
|
19
|
+
([release notes](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.4.2)).
|
|
20
|
+
|
|
21
|
+
Self-hosted LiveSync
|
|
19
22
|
[1.0.44](https://github.com/vrtmrz/obsidian-livesync/releases/tag/1.0.44)
|
|
20
23
|
uses Commonlib 0.2.3. The [0.2.3 release notes](updates.md#023) record its
|
|
21
24
|
handler-setter source compatibility change and positive-infinity formatting
|
|
@@ -269,6 +272,17 @@ standardIo.writeStdout("ready\n");
|
|
|
269
272
|
|
|
270
273
|
See [the standard-I/O contract](docs/platform-standard-io.md) for host composition and test-double examples.
|
|
271
274
|
|
|
275
|
+
<a id="ordinary-deletion-recovery-unreleased"></a>
|
|
276
|
+
|
|
277
|
+
## Ordinary deletion recovery
|
|
278
|
+
|
|
279
|
+
Available in Commonlib 0.4.2. Hosts using the ordinary file handler can opt in to
|
|
280
|
+
recovery of retained logical deletions by supplying provenance key enumeration. Recovery preserves edited or
|
|
281
|
+
unproven files, uses existing Chunk delivery policy, and reports physical removal
|
|
282
|
+
and interrupted bookkeeping separately. Hosts which do not opt in retain their
|
|
283
|
+
existing scanner policy. See [the recovery contract](docs/deletion-recovery.md)
|
|
284
|
+
for capability composition, concurrency, runtime costs, and verification limits.
|
|
285
|
+
|
|
272
286
|
## Settings lifecycle
|
|
273
287
|
|
|
274
288
|
New-Vault recommendations are deliberately separate from the conservative values used to complete older stored settings. The focused settings entry also reports migrations and safety-review requirements without changing a user's synchronisation choices or persisting a device-local acknowledgement.
|
|
@@ -17,6 +17,7 @@ export type DirectFileManipulatorOptions = {
|
|
|
17
17
|
idDerivationKey?: string;
|
|
18
18
|
pathNormalizationVersion?: 0 | 1;
|
|
19
19
|
encryptInternalMetadata?: boolean;
|
|
20
|
+
acceptUnencryptedContent?: boolean;
|
|
20
21
|
useDynamicIterationCount?: boolean;
|
|
21
22
|
customChunkSize?: number;
|
|
22
23
|
minimumChunkSize?: number;
|
|
@@ -195,7 +195,8 @@ class DirectFileManipulator {
|
|
|
195
195
|
false,
|
|
196
196
|
async () => await this.getReplicationPBKDF2Salt(this.getSettings()),
|
|
197
197
|
this.options.E2EEAlgorithm ?? E2EEAlgorithms.V2,
|
|
198
|
-
usesEncryptedInternalMetadata(this.settings)
|
|
198
|
+
usesEncryptedInternalMetadata(this.settings),
|
|
199
|
+
this.options.acceptUnencryptedContent ?? false
|
|
199
200
|
);
|
|
200
201
|
}
|
|
201
202
|
return Promise.resolve(true);
|
|
@@ -249,6 +250,7 @@ class DirectFileManipulator {
|
|
|
249
250
|
handleFilenameCaseSensitive: this.options.handleFilenameCaseSensitive ?? DEFAULT_SETTINGS.handleFilenameCaseSensitive,
|
|
250
251
|
usePathObfuscation: !!this.options.obfuscatePassphrase,
|
|
251
252
|
encryptInternalMetadata: this.options.encryptInternalMetadata ?? false,
|
|
253
|
+
acceptUnencryptedContent: this.options.acceptUnencryptedContent ?? DEFAULT_SETTINGS.acceptUnencryptedContent,
|
|
252
254
|
syncInternalFiles: this.options.syncInternalFiles ?? DEFAULT_SETTINGS.syncInternalFiles,
|
|
253
255
|
E2EEAlgorithm: this.options.E2EEAlgorithm ?? E2EEAlgorithms.V2
|
|
254
256
|
}
|
|
@@ -54,6 +54,7 @@ export declare function encodeSettingsToSetupURI(settingString: ObsidianLiveSync
|
|
|
54
54
|
/** Generate a Setup URI for the current UTC window or in the existing persistent format. */
|
|
55
55
|
export declare function encodeTimeBoundSetupURI(settingString: ObsidianLiveSyncSettings, passphrase: string, options?: TimeBoundSetupURIOptions): Promise<TimeBoundSetupURIResult>;
|
|
56
56
|
export declare function decodeSettingsFromSetupURI(uri: string, passphrase: string): Promise<false | Omit<{
|
|
57
|
+
acceptUnencryptedContent: boolean;
|
|
57
58
|
encryptInternalMetadata: boolean;
|
|
58
59
|
idDerivationVersion: 0 | 1;
|
|
59
60
|
idDerivationKey: string;
|
|
@@ -11,6 +11,7 @@ import { decryptString, encryptString } from "../encryption/stringEncryption.js"
|
|
|
11
11
|
import { LOG_LEVEL_VERBOSE, Logger } from "octagonal-wheels/common/logger";
|
|
12
12
|
import { configuredIdKey } from "../common/idDerivation.js";
|
|
13
13
|
import { assertSupportedPathNormalizationVersion, getPathNormalizationVersion } from "../common/pathNormalization.js";
|
|
14
|
+
import { normaliseAcceptUnencryptedContent } from "../common/models/setting.encryption.js";
|
|
14
15
|
function encodeSettingsToQRCodeData(settings) {
|
|
15
16
|
settings = omitP2PRuntimeSettings(settings);
|
|
16
17
|
configuredIdKey(settings);
|
|
@@ -54,6 +55,7 @@ function decodeSettingsFromQRCodeData(qr) {
|
|
|
54
55
|
LOG_LEVEL_VERBOSE
|
|
55
56
|
);
|
|
56
57
|
}
|
|
58
|
+
newSettings.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(newSettings.acceptUnencryptedContent);
|
|
57
59
|
configuredIdKey(newSettings);
|
|
58
60
|
newSettings.pathNormalizationVersion = getPathNormalizationVersion(newSettings);
|
|
59
61
|
return omitP2PRuntimeSettings(newSettings);
|
|
@@ -213,6 +215,7 @@ async function decodeSettingsFromSetupURI(uri, passphrase) {
|
|
|
213
215
|
const imported = JSON.parse(decrypted);
|
|
214
216
|
const settings = {
|
|
215
217
|
...imported,
|
|
218
|
+
acceptUnencryptedContent: normaliseAcceptUnencryptedContent(imported.acceptUnencryptedContent),
|
|
216
219
|
encryptInternalMetadata: typeof imported.encryptInternalMetadata === "boolean" ? imported.encryptInternalMetadata : false,
|
|
217
220
|
idDerivationVersion: imported.idDerivationVersion ?? 0,
|
|
218
221
|
idDerivationKey: imported.idDerivationKey ?? "",
|
|
@@ -185,7 +185,8 @@ const KeyIndexOfSettings = {
|
|
|
185
185
|
pathNormalizationVersion: 168,
|
|
186
186
|
batchSaveInLiveSync: 169,
|
|
187
187
|
useCouchDBCacheControlHeadersOnly: 170,
|
|
188
|
-
encryptedIdDerivationKey: -1
|
|
188
|
+
encryptedIdDerivationKey: -1,
|
|
189
|
+
acceptUnencryptedContent: 171
|
|
189
190
|
};
|
|
190
191
|
export {
|
|
191
192
|
KeyIndexOfSettings
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
SETTING_VERSION_SUPPORT_CASE_INSENSITIVE
|
|
6
6
|
} from "./setting.const.js";
|
|
7
7
|
import { omitP2PRuntimeSettings } from "./setting.p2p.js";
|
|
8
|
+
import { normaliseAcceptUnencryptedContent } from "./setting.encryption.js";
|
|
8
9
|
const SettingsMigrationReviewCodes = {
|
|
9
10
|
LegacyUpdatePending: "legacy-update-review-pending",
|
|
10
11
|
FutureSchema: "settings-schema-newer-than-runtime",
|
|
@@ -73,8 +74,10 @@ function prepareSettingsForLoad(storedSettings) {
|
|
|
73
74
|
toVersion: CURRENT_SETTING_VERSION
|
|
74
75
|
}
|
|
75
76
|
];
|
|
77
|
+
const settings = cloneSettings(source, SETTINGS_SCHEMA_DEFAULTS);
|
|
78
|
+
settings.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(source.acceptUnencryptedContent);
|
|
76
79
|
return {
|
|
77
|
-
settings
|
|
80
|
+
settings,
|
|
78
81
|
sourceVersion,
|
|
79
82
|
targetVersion: sourceVersion,
|
|
80
83
|
isNewVault: false,
|
|
@@ -108,13 +111,15 @@ function prepareSettingsForLoad(storedSettings) {
|
|
|
108
111
|
if (normalisedFilenameCase) migrated = { ...migrated, handleFilenameCaseSensitive: false };
|
|
109
112
|
const normalisedInternalMetadata = typeof migrated.encryptInternalMetadata !== "boolean";
|
|
110
113
|
if (normalisedInternalMetadata) migrated = { ...migrated, encryptInternalMetadata: false };
|
|
114
|
+
const normalisedAcceptUnencryptedContent = typeof migrated.acceptUnencryptedContent !== "boolean";
|
|
115
|
+
if (normalisedAcceptUnencryptedContent) migrated = { ...migrated, acceptUnencryptedContent: false };
|
|
111
116
|
return {
|
|
112
117
|
settings: cloneSettings(migrated, SETTINGS_SCHEMA_DEFAULTS),
|
|
113
118
|
sourceVersion,
|
|
114
119
|
targetVersion,
|
|
115
120
|
isNewVault: false,
|
|
116
121
|
isFromFutureSchema: false,
|
|
117
|
-
changed: sourceVersion !== targetVersion || normalisedConfiguredState || normalisedFilenameCase || normalisedInternalMetadata,
|
|
122
|
+
changed: sourceVersion !== targetVersion || normalisedConfiguredState || normalisedFilenameCase || normalisedInternalMetadata || normalisedAcceptUnencryptedContent,
|
|
118
123
|
requiresSyncReview: reviewReasons.length > 0,
|
|
119
124
|
reviewReasons
|
|
120
125
|
};
|
|
@@ -489,6 +489,10 @@ export declare const SETTINGS_PROPERTY_POLICY: {
|
|
|
489
489
|
readonly markdown: "include";
|
|
490
490
|
readonly persistence: "include";
|
|
491
491
|
};
|
|
492
|
+
readonly acceptUnencryptedContent: {
|
|
493
|
+
readonly markdown: "include";
|
|
494
|
+
readonly persistence: "include";
|
|
495
|
+
};
|
|
492
496
|
readonly passphrase: {
|
|
493
497
|
readonly markdown: "credentials";
|
|
494
498
|
readonly persistence: "passphrase";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_SETTINGS } from "./setting.const.defaults.js";
|
|
2
|
+
import { normaliseAcceptUnencryptedContent } from "./setting.encryption.js";
|
|
2
3
|
const SettingPolicies = {
|
|
3
4
|
Default: { markdown: "include", persistence: "include" },
|
|
4
5
|
LocalOnly: { markdown: "omit", persistence: "include" },
|
|
@@ -123,6 +124,7 @@ const SETTINGS_PROPERTY_POLICY = {
|
|
|
123
124
|
forcePathStyle: SettingPolicies.Default,
|
|
124
125
|
remoteType: SettingPolicies.Default,
|
|
125
126
|
encrypt: SettingPolicies.Default,
|
|
127
|
+
acceptUnencryptedContent: SettingPolicies.Default,
|
|
126
128
|
passphrase: SettingPolicies.E2EEPassphrase,
|
|
127
129
|
idDerivationVersion: SettingPolicies.MarkdownCredentials,
|
|
128
130
|
pathNormalizationVersion: SettingPolicies.MarkdownCredentials,
|
|
@@ -230,6 +232,9 @@ function createMarkdownSettings(settings, includeCredentials = settings.writeCre
|
|
|
230
232
|
copySetting(output, settings, key);
|
|
231
233
|
}
|
|
232
234
|
if (output.remoteConfigurations) output.remoteConfigurations = cloneProfiles(output);
|
|
235
|
+
if ("acceptUnencryptedContent" in output) {
|
|
236
|
+
output.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(output.acceptUnencryptedContent);
|
|
237
|
+
}
|
|
233
238
|
return output;
|
|
234
239
|
}
|
|
235
240
|
function mergeMarkdownSettings(incoming, current) {
|
|
@@ -241,6 +246,9 @@ function mergeMarkdownSettings(incoming, current) {
|
|
|
241
246
|
}
|
|
242
247
|
}
|
|
243
248
|
merged.remoteConfigurations = cloneProfiles(merged);
|
|
249
|
+
merged.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(
|
|
250
|
+
Object.prototype.hasOwnProperty.call(incoming, "acceptUnencryptedContent") ? incoming.acceptUnencryptedContent : current.acceptUnencryptedContent
|
|
251
|
+
);
|
|
244
252
|
return merged;
|
|
245
253
|
}
|
|
246
254
|
function selectConnectionSettings(settings) {
|
|
@@ -271,6 +279,7 @@ function requireConfigurationCiphertext(value) {
|
|
|
271
279
|
return value;
|
|
272
280
|
}
|
|
273
281
|
function prepareSettingsForPersistence(settings) {
|
|
282
|
+
settings.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(settings.acceptUnencryptedContent);
|
|
274
283
|
if (hasConnectionSettings(settings)) throw new Error("Connection settings were not prepared for persistence.");
|
|
275
284
|
if (settings.encrypt && settings.passphrase !== "")
|
|
276
285
|
throw new Error("The passphrase was not prepared for persistence.");
|
|
@@ -598,6 +598,8 @@ export interface EncryptionSettings {
|
|
|
598
598
|
* Indicates whether E2EE is enabled.
|
|
599
599
|
*/
|
|
600
600
|
encrypt: boolean;
|
|
601
|
+
/** Accept plaintext file content from the remote while E2EE is enabled. */
|
|
602
|
+
acceptUnencryptedContent: boolean;
|
|
601
603
|
/**
|
|
602
604
|
* The passphrase used for E2EE.
|
|
603
605
|
*/
|
|
@@ -20,6 +20,11 @@ const configurationNames = {
|
|
|
20
20
|
name: "Encrypt internal file Properties",
|
|
21
21
|
desc: "Encrypt file properties (paths, times, sizes, and Chunk references) used by Hidden File Sync and Customisation Sync. This affects future writes; manually rebuild the remote database to protect existing properties. Requires E2EE V2, Property Encryption, and compatible clients on every device."
|
|
22
22
|
},
|
|
23
|
+
acceptUnencryptedContent: {
|
|
24
|
+
name: "Accept unencrypted content",
|
|
25
|
+
desc: "When E2EE is enabled, accept unencrypted content written by third-party tools which do not use the E2EE passphrase. Anyone with write access to the database can inject plaintext. Content sent by this plug-in remains encrypted.",
|
|
26
|
+
isAdvanced: true
|
|
27
|
+
},
|
|
23
28
|
enableCompression: {
|
|
24
29
|
name: "Data Compression",
|
|
25
30
|
level: LEVEL_ADVANCED
|
|
@@ -249,6 +249,7 @@ export declare const TweakValuesTemplate: {
|
|
|
249
249
|
bucketPrefix?: string;
|
|
250
250
|
forcePathStyle?: boolean;
|
|
251
251
|
remoteType?: import("./setting.type.js").RemoteType;
|
|
252
|
+
acceptUnencryptedContent?: boolean;
|
|
252
253
|
passphrase?: string;
|
|
253
254
|
idDerivationKey?: string;
|
|
254
255
|
doNotUseFixedRevisionForChunks?: boolean;
|
|
@@ -139,6 +139,7 @@ export declare const AllSettingDefault: {
|
|
|
139
139
|
remoteType: import("./types.js").RemoteType;
|
|
140
140
|
pathNormalizationVersion: import("./models/setting.type.js").PathNormalizationVersion;
|
|
141
141
|
encrypt: boolean;
|
|
142
|
+
acceptUnencryptedContent: boolean;
|
|
142
143
|
passphrase: string;
|
|
143
144
|
idDerivationVersion: 0 | 1;
|
|
144
145
|
idDerivationKey: string;
|
package/dist/common/utils.js
CHANGED
|
@@ -3,11 +3,11 @@ import { isPlainText } from "../string_and_binary/path.js";
|
|
|
3
3
|
import { Semaphore } from "octagonal-wheels/concurrency/semaphore";
|
|
4
4
|
import { arrayBufferToBase64Single, decodeBinary, writeString } from "../string_and_binary/convert.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
PREFIX_OBFUSCATED,
|
|
6
|
+
IDPrefixes,
|
|
8
7
|
SYNCINFO_ID
|
|
9
8
|
} from "./types.js";
|
|
10
9
|
import { normaliseP2PConnectionPath, normaliseP2PMaxWirePayloadBytes } from "./models/setting.p2p.js";
|
|
10
|
+
import { normaliseAcceptUnencryptedContent } from "./models/setting.encryption.js";
|
|
11
11
|
import { isErrorOfMissingDoc } from "../pouchdb/utils_couchdb.js";
|
|
12
12
|
import { joinDelimitedList, replaceAll, replaceAllPairs, splitDelimitedList } from "octagonal-wheels/string";
|
|
13
13
|
import { formatDuration } from "octagonal-wheels/notation/duration";
|
|
@@ -94,13 +94,13 @@ async function isDocContentSame(docA, docB) {
|
|
|
94
94
|
return isBlobContentEqual(blob1, blob2, isArrayBufferContentEqual);
|
|
95
95
|
}
|
|
96
96
|
function isObfuscatedEntry(doc) {
|
|
97
|
-
if (doc._id.startsWith(
|
|
97
|
+
if (doc._id.startsWith(IDPrefixes.Obfuscated)) {
|
|
98
98
|
return true;
|
|
99
99
|
}
|
|
100
100
|
return false;
|
|
101
101
|
}
|
|
102
102
|
function isEncryptedChunkEntry(doc) {
|
|
103
|
-
if (doc._id.startsWith(
|
|
103
|
+
if (doc._id.startsWith(IDPrefixes.EncryptedChunk)) {
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
106
|
return false;
|
|
@@ -418,6 +418,7 @@ function pickEncryptionSettings(setting) {
|
|
|
418
418
|
passphrase: setting.passphrase,
|
|
419
419
|
usePathObfuscation: setting.usePathObfuscation,
|
|
420
420
|
encryptInternalMetadata: setting.encryptInternalMetadata,
|
|
421
|
+
acceptUnencryptedContent: normaliseAcceptUnencryptedContent(setting.acceptUnencryptedContent),
|
|
421
422
|
idDerivationVersion: setting.idDerivationVersion,
|
|
422
423
|
idDerivationKey: setting.idDerivationKey
|
|
423
424
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DOCID_SYNC_PARAMETERS } from "../common/types.js";
|
|
2
2
|
import { isObfuscatedEntry, parseHeaderValues } from "../common/utils.js";
|
|
3
3
|
import { getConfiguredFunctionsForEncryption, isEncryptedMeta } from "../pouchdb/encryption.js";
|
|
4
|
+
import { isUnencryptedContentRejectedError } from "../replication/UnencryptedContentRejectedError.js";
|
|
4
5
|
import { isPathProbablyObfuscated } from "octagonal-wheels/encryption/encryption";
|
|
5
6
|
import { decompressDoc } from "../pouchdb/compress.js";
|
|
6
7
|
import { AuthorizationHeaderGenerator, generateCredentialObject } from "../replication/httplib.js";
|
|
@@ -76,7 +77,8 @@ function createCouchDBDiagnosticSource({
|
|
|
76
77
|
settings.E2EEAlgorithm,
|
|
77
78
|
false,
|
|
78
79
|
() => {
|
|
79
|
-
}
|
|
80
|
+
},
|
|
81
|
+
settings.acceptUnencryptedContent
|
|
80
82
|
).outgoing : async (doc) => doc;
|
|
81
83
|
const decode = async (id, value) => {
|
|
82
84
|
if (!value || typeof value !== "object" || !("_id" in value) || value._id !== id || !("_rev" in value) || typeof value._rev !== "string") {
|
|
@@ -157,7 +159,7 @@ function createCouchDBDiagnosticSource({
|
|
|
157
159
|
checkCancelled();
|
|
158
160
|
return {
|
|
159
161
|
id,
|
|
160
|
-
error: error instanceof DiagnosticReadError ? error : new DiagnosticReadError("document-unreadable")
|
|
162
|
+
error: error instanceof DiagnosticReadError || isUnencryptedContentRejectedError(error) ? error : new DiagnosticReadError("document-unreadable")
|
|
161
163
|
};
|
|
162
164
|
}
|
|
163
165
|
})
|
|
@@ -4,6 +4,45 @@ export interface StoreFileOptions {
|
|
|
4
4
|
/** Recheck storage and provenance, with bounded retries for recovery scans. */
|
|
5
5
|
revalidateStorage?: boolean;
|
|
6
6
|
}
|
|
7
|
+
/** Diagnostic context shared by each observed deletion-recovery outcome. */
|
|
8
|
+
interface DeletionRecoveryDiagnostics {
|
|
9
|
+
reason: string;
|
|
10
|
+
phase?: string;
|
|
11
|
+
warning?: string;
|
|
12
|
+
error?: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** No provenance was cleared; edits and unknown content remain protected. */
|
|
15
|
+
export interface DeletionRecoveryUnchangedResult extends DeletionRecoveryDiagnostics {
|
|
16
|
+
status: "deferred" | "failed";
|
|
17
|
+
file: "present" | "absent" | "unknown";
|
|
18
|
+
provenance: "unchanged";
|
|
19
|
+
}
|
|
20
|
+
/** Absence was observed, but remaining bookkeeping must be rediscovered on a later scan. */
|
|
21
|
+
export interface DeletionRecoveryCleanupPendingResult extends DeletionRecoveryDiagnostics {
|
|
22
|
+
status: "deferred" | "failed";
|
|
23
|
+
file: "absent";
|
|
24
|
+
provenance: "pending";
|
|
25
|
+
}
|
|
26
|
+
/** Removal was attempted, but its effect could not be read; retain evidence until the next observation. */
|
|
27
|
+
export interface DeletionRecoveryRemovalUnconfirmedResult extends DeletionRecoveryDiagnostics {
|
|
28
|
+
status: "failed";
|
|
29
|
+
file: "unknown";
|
|
30
|
+
provenance: "pending";
|
|
31
|
+
}
|
|
32
|
+
/** Both effects were confirmed; a subsequent lock or permit failure can still fail the operation. */
|
|
33
|
+
export interface DeletionRecoveryClearedResult extends DeletionRecoveryDiagnostics {
|
|
34
|
+
status: "applied" | "failed";
|
|
35
|
+
file: "absent";
|
|
36
|
+
provenance: "cleared";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Coherent observed effects of one guarded deletion-recovery attempt.
|
|
40
|
+
* @remarks The `applied` status requires observed absence and cleared provenance.
|
|
41
|
+
* Unchanged refers to provenance operations, not proof that a file still exists.
|
|
42
|
+
* Pending and unconfirmed effects retain retry evidence. A deferred protected
|
|
43
|
+
* file may require user reconciliation; automatic convergence is not guaranteed.
|
|
44
|
+
*/
|
|
45
|
+
export type DeletionRecoveryResult = DeletionRecoveryUnchangedResult | DeletionRecoveryCleanupPendingResult | DeletionRecoveryRemovalUnconfirmedResult | DeletionRecoveryClearedResult;
|
|
7
46
|
export interface IFileHandler {
|
|
8
47
|
readFileFromStub(file: UXFileInfoStub | UXFileInfo): Promise<UXFileInfo>;
|
|
9
48
|
/**
|
|
@@ -14,6 +53,25 @@ export interface IFileHandler {
|
|
|
14
53
|
tryRecordUntrackedFileRevision(info: UXFileInfoStub | UXFileInfo, expectedRevision: string): Promise<boolean>;
|
|
15
54
|
/** Metadata-only scan hint; never certifies content equality or changes provenance. */
|
|
16
55
|
canSkipUnchangedFile?(info: UXFileInfoStub, expected: MetaEntry): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Report whether complete provenance-key discovery is configured.
|
|
58
|
+
* @returns A composition capability, rather than a store-readiness or health check.
|
|
59
|
+
*/
|
|
60
|
+
supportsDeletionRecovery?(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Enumerate existing provenance paths without loading record values or bodies.
|
|
63
|
+
* @returns Complete namespaced keys; unsupported or unavailable stores may reject.
|
|
64
|
+
*/
|
|
65
|
+
listDeletionRecoveryPaths?(): Promise<FilePathWithPrefix[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Recover one exact retained deletion without adding revision history.
|
|
68
|
+
* @param expected - The selected logical deletion whose identity and revision must remain current.
|
|
69
|
+
* @param cleanupOnly - Permit bookkeeping for an absent file only; never remove a present file.
|
|
70
|
+
* @returns Observed effects and completion status, including conservative deferral or failure.
|
|
71
|
+
* @remarks A failed result can retain confirmed absence or completed cleanup.
|
|
72
|
+
* Callers must use those effects when preserving retry evidence.
|
|
73
|
+
*/
|
|
74
|
+
recoverDatabaseDeletion?(expected: MetaEntry, cleanupOnly?: boolean): Promise<DeletionRecoveryResult>;
|
|
17
75
|
storeFileToDB(info: UXFileInfoStub | UXFileInfo | UXInternalFileInfoStub | FilePathWithPrefix, force?: boolean, onlyChunks?: boolean, options?: StoreFileOptions): Promise<boolean>;
|
|
18
76
|
/**
|
|
19
77
|
* Store the current storage content as a child of an exact live database revision.
|
|
@@ -39,3 +97,4 @@ export interface IFileHandler {
|
|
|
39
97
|
dbToStorage(entryInfo: MetaEntry | FilePathWithPrefix, info: UXFileInfoStub | UXFileInfo | FilePath | null, force?: boolean): Promise<boolean>;
|
|
40
98
|
createAllChunks(showingNotice?: boolean): Promise<void>;
|
|
41
99
|
}
|
|
100
|
+
export {};
|
|
@@ -15,6 +15,12 @@ export interface FileReflectionProvenance {
|
|
|
15
15
|
set(path: FilePathWithPrefix, record: FileReflectionProvenanceRecord): Promise<void>;
|
|
16
16
|
delete(path: FilePathWithPrefix): Promise<void>;
|
|
17
17
|
move(from: FilePathWithPrefix, to: FilePathWithPrefix): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Enumerate the complete provenance namespace without reading record values.
|
|
20
|
+
* @returns Existing paths; backing-store failures reject the promise.
|
|
21
|
+
* @remarks Absence of this optional method means that enumeration is unsupported.
|
|
22
|
+
*/
|
|
23
|
+
listPaths?: () => Promise<FilePathWithPrefix[]>;
|
|
18
24
|
}
|
|
19
25
|
/**
|
|
20
26
|
* Device-local provenance backed by an existing host-owned key-value store.
|
|
@@ -28,7 +34,15 @@ export interface FileReflectionProvenance {
|
|
|
28
34
|
*/
|
|
29
35
|
export declare class StoredFileReflectionProvenance implements FileReflectionProvenance {
|
|
30
36
|
private readonly store;
|
|
31
|
-
|
|
37
|
+
listPaths?: () => Promise<FilePathWithPrefix[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a provenance view without opening or reading its backing store.
|
|
40
|
+
* @param store - The host-owned, namespaced store used by later operations.
|
|
41
|
+
* @param enableEnumeration - Advertise keys-only enumeration when true; defaults to false.
|
|
42
|
+
* @remarks Registering the optional capability performs no I/O. The host must
|
|
43
|
+
* complete its normal store lifecycle before invoking any provenance operation.
|
|
44
|
+
*/
|
|
45
|
+
constructor(store: SimpleStore<FileReflectionProvenanceRecord>, enableEnumeration?: boolean);
|
|
32
46
|
get(path: FilePathWithPrefix): Promise<FileReflectionProvenanceRecord | undefined>;
|
|
33
47
|
set(path: FilePathWithPrefix, record: FileReflectionProvenanceRecord): Promise<void>;
|
|
34
48
|
delete(path: FilePathWithPrefix): Promise<void>;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
class StoredFileReflectionProvenance {
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Create a provenance view without opening or reading its backing store.
|
|
4
|
+
* @param store - The host-owned, namespaced store used by later operations.
|
|
5
|
+
* @param enableEnumeration - Advertise keys-only enumeration when true; defaults to false.
|
|
6
|
+
* @remarks Registering the optional capability performs no I/O. The host must
|
|
7
|
+
* complete its normal store lifecycle before invoking any provenance operation.
|
|
8
|
+
*/
|
|
9
|
+
constructor(store, enableEnumeration = false) {
|
|
3
10
|
this.store = store;
|
|
11
|
+
if (enableEnumeration) {
|
|
12
|
+
this.listPaths = async () => (await this.store.keys(void 0, void 0)).map((path) => path);
|
|
13
|
+
}
|
|
4
14
|
}
|
|
5
15
|
store;
|
|
6
16
|
async get(path) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { getUnencryptedContentRejectionMessage } from "../replication/unencryptedContentMessages.js";
|
|
2
|
+
import {
|
|
3
|
+
getUnencryptedContentRejection,
|
|
4
|
+
isUnencryptedContentRejectedError
|
|
5
|
+
} from "../replication/UnencryptedContentRejectedError.js";
|
|
1
6
|
import { delay, promiseWithResolvers } from "octagonal-wheels/promises";
|
|
2
7
|
import { unique } from "octagonal-wheels/collection";
|
|
3
|
-
import { LOG_LEVEL_VERBOSE, Logger } from "../common/logger.js";
|
|
8
|
+
import { LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, Logger } from "../common/logger.js";
|
|
4
9
|
import { DEFAULT_SETTINGS } from "../common/types.js";
|
|
5
10
|
import {} from "./ChunkManager.js";
|
|
6
11
|
import { compatGlobal } from "../common/coreEnvFunctions.js";
|
|
@@ -251,7 +256,11 @@ class ChunkFetcher {
|
|
|
251
256
|
LOG_LEVEL_VERBOSE
|
|
252
257
|
);
|
|
253
258
|
for (const chunk of invalidChunks) {
|
|
254
|
-
|
|
259
|
+
const id = typeof chunk === "object" && chunk !== null && "_id" in chunk && typeof chunk._id === "string" ? chunk._id : void 0;
|
|
260
|
+
Logger(
|
|
261
|
+
id === void 0 ? "Invalid chunk without a string document ID." : `Invalid chunk document: ${JSON.stringify(id)}`,
|
|
262
|
+
LOG_LEVEL_VERBOSE
|
|
263
|
+
);
|
|
255
264
|
}
|
|
256
265
|
}
|
|
257
266
|
if (chunks.length === 0) {
|
|
@@ -397,8 +406,22 @@ class ChunkFetcher {
|
|
|
397
406
|
}
|
|
398
407
|
this.applyMissingChunkResults(missingIds, requestClaims, requestCompletionVersion);
|
|
399
408
|
} catch (error) {
|
|
400
|
-
|
|
401
|
-
|
|
409
|
+
if (isUnencryptedContentRejectedError(error)) {
|
|
410
|
+
Logger(
|
|
411
|
+
getUnencryptedContentRejectionMessage("on-demand"),
|
|
412
|
+
LOG_LEVEL_NOTICE,
|
|
413
|
+
"unencrypted-content-rejected"
|
|
414
|
+
);
|
|
415
|
+
const rejection = getUnencryptedContentRejection(error);
|
|
416
|
+
const identifiers = rejection ? [rejection.documentId] : requestIDs;
|
|
417
|
+
Logger(
|
|
418
|
+
`On-demand retrieval rejected unencrypted content: ${identifiers.join(", ")}`,
|
|
419
|
+
LOG_LEVEL_VERBOSE
|
|
420
|
+
);
|
|
421
|
+
} else {
|
|
422
|
+
Logger("An error occurred while fetching remote chunks.", LOG_LEVEL_VERBOSE);
|
|
423
|
+
Logger(error, LOG_LEVEL_VERBOSE);
|
|
424
|
+
}
|
|
402
425
|
} finally {
|
|
403
426
|
for (const [id, pending] of requestClaims) {
|
|
404
427
|
if (pending.inFlight) this.settleClaim(id, pending);
|
|
@@ -17,7 +17,7 @@ function decideMissingChunkAction({
|
|
|
17
17
|
}
|
|
18
18
|
function isValidChunk(chunk) {
|
|
19
19
|
const candidate = chunk;
|
|
20
|
-
return !!candidate && typeof candidate._id === "string" && typeof candidate.data === "string";
|
|
20
|
+
return !!candidate && candidate.type === "leaf" && typeof candidate._id === "string" && !candidate._id.startsWith("_local/") && typeof candidate.data === "string";
|
|
21
21
|
}
|
|
22
22
|
function classifyFetchedChunks(requestedIds, fetched) {
|
|
23
23
|
const chunks = [];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { EntryDoc } from "../common/models/db.definition.js";
|
|
2
|
-
import type { AnyEntry, EntryLeaf } from "../common/models/db.type.js";
|
|
3
2
|
type DBSequence = number | string;
|
|
4
3
|
/**
|
|
5
4
|
* Identifies the boundary at which Fast Fetch stopped.
|
|
@@ -56,7 +55,7 @@ export type FetchChangesForInitialSyncProgress = {
|
|
|
56
55
|
* @param customHeaders Additional request headers required by the CouchDB endpoint or its reverse proxy.
|
|
57
56
|
* @param onStoredRevisions Observes revision identities after their complete local batch is persisted.
|
|
58
57
|
*/
|
|
59
|
-
export declare function fetchChangesForInitialSync(downloadToDB: PouchDB.Database, remoteDbUrl: string, authHeader: string, decryptFunction: (doc: EntryDoc) => Promise<
|
|
58
|
+
export declare function fetchChangesForInitialSync(downloadToDB: PouchDB.Database, remoteDbUrl: string, authHeader: string, decryptFunction: (doc: EntryDoc) => Promise<EntryDoc>, since?: number | string, onProgress?: (progress: FetchChangesForInitialSyncProgress) => void, onCheckpoint?: (sequence: DBSequence) => void | Promise<void>, customHeaders?: Record<string, string>, onStoredRevisions?: (revisions: readonly {
|
|
60
59
|
id: string;
|
|
61
60
|
rev: string;
|
|
62
61
|
}[]) => void | Promise<void>): Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type EntryDoc, type AnyEntry, type EntryLeaf, type DocumentID, type E2EEAlgorithm } from "../common/types.js";
|
|
1
|
+
import { type EntryDoc, type AnyEntry, type EntryLeaf, type E2EEAlgorithm } from "../common/types.js";
|
|
3
2
|
import { encryptWorker, decryptWorker, encryptHKDFWorker, decryptHKDFWorker } from "#worker";
|
|
3
|
+
import type { LogFunction } from "../services/lib/logUtils.js";
|
|
4
|
+
export { EDEN_ENCRYPTED_KEY, EDEN_ENCRYPTED_KEY_HKDF, shouldEncryptEden, shouldEncryptEdenHKDF, shouldDecryptEden, shouldDecryptEdenHKDF, } from "./encryption.eden.js";
|
|
4
5
|
export declare const encrypt: typeof encryptWorker;
|
|
5
6
|
export declare const decrypt: typeof decryptWorker;
|
|
6
7
|
export declare const encryptHKDF: typeof encryptHKDFWorker;
|
|
@@ -8,15 +9,9 @@ export declare const decryptHKDF: typeof decryptHKDFWorker;
|
|
|
8
9
|
export declare function isEncryptedMeta<T extends AnyEntry>(doc: T): boolean;
|
|
9
10
|
export declare let preprocessOutgoing: (doc: AnyEntry | EntryLeaf) => Promise<AnyEntry | EntryLeaf>;
|
|
10
11
|
export declare let preprocessIncoming: (doc: EntryDoc) => Promise<EntryDoc>;
|
|
11
|
-
export declare function getConfiguredFunctionsForEncryption(passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean, log?:
|
|
12
|
+
export declare function getConfiguredFunctionsForEncryption(passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean, log?: LogFunction, acceptUnencryptedContent?: boolean): {
|
|
12
13
|
incoming: (doc: AnyEntry | EntryLeaf) => Promise<AnyEntry | EntryLeaf>;
|
|
13
14
|
outgoing: (doc: EntryDoc) => Promise<AnyEntry | EntryLeaf>;
|
|
14
15
|
};
|
|
15
|
-
export declare const enableEncryption: (db: PouchDB.Database<EntryDoc>, passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean) => void;
|
|
16
|
+
export declare const enableEncryption: (db: PouchDB.Database<EntryDoc>, passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean, acceptUnencryptedContent?: boolean) => void;
|
|
16
17
|
export declare function disableEncryption(): void;
|
|
17
|
-
export declare const EDEN_ENCRYPTED_KEY: DocumentID;
|
|
18
|
-
export declare const EDEN_ENCRYPTED_KEY_HKDF: DocumentID;
|
|
19
|
-
export declare function shouldEncryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
20
|
-
export declare function shouldEncryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
21
|
-
export declare function shouldDecryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
22
|
-
export declare function shouldDecryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eden is being phased out. Avoid proactive refactoring or enhancements;
|
|
3
|
+
* limit changes to necessary fixes and compatibility maintenance.
|
|
4
|
+
*/
|
|
5
|
+
import type { AnyEntry, EntryLeaf, DocumentID } from "../common/types.js";
|
|
6
|
+
export declare const EDEN_ENCRYPTED_KEY: DocumentID;
|
|
7
|
+
export declare const EDEN_ENCRYPTED_KEY_HKDF: DocumentID;
|
|
8
|
+
export declare function shouldEncryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
9
|
+
export declare function shouldEncryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
10
|
+
export declare function shouldDecryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
11
|
+
export declare function shouldDecryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const EDEN_ENCRYPTED_KEY = "h:++encrypted";
|
|
2
|
+
const EDEN_ENCRYPTED_KEY_HKDF = "h:++encrypted-hkdf";
|
|
3
|
+
function shouldEncryptEden(doc) {
|
|
4
|
+
if ("eden" in doc && !(EDEN_ENCRYPTED_KEY in doc.eden)) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
function shouldEncryptEdenHKDF(doc) {
|
|
10
|
+
if ("eden" in doc && !(EDEN_ENCRYPTED_KEY_HKDF in doc.eden)) {
|
|
11
|
+
if (Object.keys(doc.eden).length === 0) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
function shouldDecryptEden(doc) {
|
|
19
|
+
if ("eden" in doc && EDEN_ENCRYPTED_KEY in doc.eden) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
function shouldDecryptEdenHKDF(doc) {
|
|
25
|
+
if ("eden" in doc && EDEN_ENCRYPTED_KEY_HKDF in doc.eden) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
EDEN_ENCRYPTED_KEY,
|
|
32
|
+
EDEN_ENCRYPTED_KEY_HKDF,
|
|
33
|
+
shouldDecryptEden,
|
|
34
|
+
shouldDecryptEdenHKDF,
|
|
35
|
+
shouldEncryptEden,
|
|
36
|
+
shouldEncryptEdenHKDF
|
|
37
|
+
};
|