mindoodb 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 +97 -24
- package/dist/__mocks__/expo-standard-web-crypto.d.ts +10 -0
- package/dist/__mocks__/expo-standard-web-crypto.d.ts.map +1 -0
- package/dist/__mocks__/expo-standard-web-crypto.js +22 -0
- package/dist/__mocks__/expo-standard-web-crypto.js.map +1 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.d.ts +8 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.d.ts.map +1 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.js +16 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.js.map +1 -0
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts +1 -1
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts.map +1 -1
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js +2 -2
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +19 -2
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +133 -22
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.d.ts +20 -3
- package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.js +136 -21
- package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +33 -3
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +148 -27
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/index.d.ts +1 -1
- package/dist/appendonlystores/network/index.d.ts.map +1 -1
- package/dist/appendonlystores/network/index.js.map +1 -1
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts +61 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js +685 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.d.ts +25 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.d.ts.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.js +41 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.js.map +1 -0
- package/dist/browser/index.d.ts +5 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +13 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/core/BaseMindooDB.d.ts +38 -4
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +810 -329
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/BaseMindooTenant.d.ts +42 -6
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +259 -93
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts +3 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +50 -40
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
- package/dist/core/BaseMindooTenantFactory.d.ts +25 -29
- package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantFactory.js +175 -73
- package/dist/core/BaseMindooTenantFactory.js.map +1 -1
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.d.ts +68 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.d.ts.map +1 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.js +659 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.js.map +1 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +50 -4
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -1
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +204 -39
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -1
- package/dist/core/appendonlystores/bloom.d.ts +85 -0
- package/dist/core/appendonlystores/bloom.d.ts.map +1 -0
- package/dist/core/appendonlystores/bloom.js +228 -0
- package/dist/core/appendonlystores/bloom.js.map +1 -0
- package/dist/core/appendonlystores/network/AuthenticationService.d.ts +3 -0
- package/dist/core/appendonlystores/network/AuthenticationService.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/AuthenticationService.js +21 -17
- package/dist/core/appendonlystores/network/AuthenticationService.js.map +1 -1
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts +36 -2
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.d.ts +10 -0
- package/dist/core/appendonlystores/network/types.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.js.map +1 -1
- package/dist/core/appendonlystores/types.d.ts +137 -1
- package/dist/core/appendonlystores/types.d.ts.map +1 -1
- package/dist/core/automerge-adapter.d.ts +15 -0
- package/dist/core/automerge-adapter.d.ts.map +1 -0
- package/dist/core/automerge-adapter.js +73 -0
- package/dist/core/automerge-adapter.js.map +1 -0
- package/dist/core/crypto/MindooDocSigner.d.ts +3 -1
- package/dist/core/crypto/MindooDocSigner.d.ts.map +1 -1
- package/dist/core/crypto/MindooDocSigner.js +9 -5
- package/dist/core/crypto/MindooDocSigner.js.map +1 -1
- package/dist/core/crypto/RSAEncryption.d.ts +3 -1
- package/dist/core/crypto/RSAEncryption.d.ts.map +1 -1
- package/dist/core/crypto/RSAEncryption.js +13 -9
- package/dist/core/crypto/RSAEncryption.js.map +1 -1
- package/dist/core/crypto/pbkdf2Iterations.d.ts +12 -0
- package/dist/core/crypto/pbkdf2Iterations.d.ts.map +1 -0
- package/dist/core/crypto/pbkdf2Iterations.js +55 -0
- package/dist/core/crypto/pbkdf2Iterations.js.map +1 -0
- package/dist/core/index.d.ts +7 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +30 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts +1 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +2 -2
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -1
- package/dist/core/indexing/virtualviews/index.d.ts +1 -1
- package/dist/core/indexing/virtualviews/index.js +1 -1
- package/dist/core/keys/KeyBag.d.ts +36 -13
- package/dist/core/keys/KeyBag.d.ts.map +1 -1
- package/dist/core/keys/KeyBag.js +96 -31
- package/dist/core/keys/KeyBag.js.map +1 -1
- package/dist/core/keys/KeyContext.d.ts +4 -0
- package/dist/core/keys/KeyContext.d.ts.map +1 -0
- package/dist/core/keys/KeyContext.js +11 -0
- package/dist/core/keys/KeyContext.js.map +1 -0
- package/dist/core/logging/LogLevel.d.ts +21 -0
- package/dist/core/logging/LogLevel.d.ts.map +1 -0
- package/dist/core/logging/LogLevel.js +56 -0
- package/dist/core/logging/LogLevel.js.map +1 -0
- package/dist/core/logging/Logger.d.ts +37 -0
- package/dist/core/logging/Logger.d.ts.map +1 -0
- package/dist/core/logging/Logger.js +3 -0
- package/dist/core/logging/Logger.js.map +1 -0
- package/dist/core/logging/MindooLogger.d.ts +28 -0
- package/dist/core/logging/MindooLogger.d.ts.map +1 -0
- package/dist/core/logging/MindooLogger.js +217 -0
- package/dist/core/logging/MindooLogger.js.map +1 -0
- package/dist/core/logging/index.d.ts +4 -0
- package/dist/core/logging/index.d.ts.map +1 -0
- package/dist/core/logging/index.js +10 -0
- package/dist/core/logging/index.js.map +1 -0
- package/dist/core/types.d.ts +313 -77
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/uri/MindooURI.d.ts +58 -0
- package/dist/core/uri/MindooURI.d.ts.map +1 -0
- package/dist/core/uri/MindooURI.js +169 -0
- package/dist/core/uri/MindooURI.js.map +1 -0
- package/dist/core/userid/index.d.ts +0 -10
- package/dist/core/userid/index.d.ts.map +1 -1
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts +541 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts.map +1 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js +1334 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js.map +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +5 -1
- package/dist/node/index.js.map +1 -1
- package/dist/reactnative/crypto/AESAdapter.d.ts +18 -0
- package/dist/reactnative/crypto/AESAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/AESAdapter.js +112 -0
- package/dist/reactnative/crypto/AESAdapter.js.map +1 -0
- package/dist/reactnative/crypto/Ed25519Adapter.d.ts +34 -0
- package/dist/reactnative/crypto/Ed25519Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/Ed25519Adapter.js +386 -0
- package/dist/reactnative/crypto/Ed25519Adapter.js.map +1 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.d.ts +23 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.js +51 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/HMACAdapter.d.ts +13 -0
- package/dist/reactnative/crypto/HMACAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/HMACAdapter.js +50 -0
- package/dist/reactnative/crypto/HMACAdapter.js.map +1 -0
- package/dist/reactnative/crypto/KeyFormatConverter.d.ts +21 -0
- package/dist/reactnative/crypto/KeyFormatConverter.d.ts.map +1 -0
- package/dist/reactnative/crypto/KeyFormatConverter.js +72 -0
- package/dist/reactnative/crypto/KeyFormatConverter.js.map +1 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.d.ts +19 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.js +67 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.js.map +1 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.d.ts +37 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.js +72 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/RSAAdapter.d.ts +38 -0
- package/dist/reactnative/crypto/RSAAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/RSAAdapter.js +184 -0
- package/dist/reactnative/crypto/RSAAdapter.js.map +1 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.d.ts +33 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.js +61 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/SHA256Adapter.d.ts +9 -0
- package/dist/reactnative/crypto/SHA256Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/SHA256Adapter.js +29 -0
- package/dist/reactnative/crypto/SHA256Adapter.js.map +1 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.d.ts +63 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.d.ts.map +1 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.js +350 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.js.map +1 -0
- package/dist/reactnative/index.d.ts +8 -0
- package/dist/reactnative/index.d.ts.map +1 -0
- package/dist/reactnative/index.js +38 -0
- package/dist/reactnative/index.js.map +1 -0
- package/package.json +51 -6
- package/patches/PATCHES.md +111 -0
- package/patches/react-native+0.76.9.patch +34 -0
- package/patches/react-native-quick-crypto+1.0.7.patch +42 -0
- package/scripts/cli.js +21 -0
- package/scripts/setup-react-native.js +228 -0
- package/templates/reactnative/App.js +252 -0
- package/templates/reactnative/app.json +29 -0
- package/templates/reactnative/babel.config.js +6 -0
- package/templates/reactnative/index.js +26 -0
- package/templates/reactnative/metro.config.snippet.js +39 -0
- package/templates/reactnative/mindoodb-polyfills.js +116 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bloom filter for compact set-membership summaries of store entry IDs.
|
|
3
|
+
*
|
|
4
|
+
* During network sync, a local store needs to determine which of its entry IDs
|
|
5
|
+
* are missing from a remote store. Naively this requires sending every local ID
|
|
6
|
+
* to the remote for an exact `hasEntries` check — an O(n) network round-trip
|
|
7
|
+
* that dominates sync latency for large stores.
|
|
8
|
+
*
|
|
9
|
+
* A bloom filter provides a probabilistic shortcut: the remote store serializes
|
|
10
|
+
* its full ID set into a compact bitset ({@link StoreIdBloomSummary}) and sends
|
|
11
|
+
* it to the local side in a single response. The local side then tests each of
|
|
12
|
+
* its own IDs against the bloom filter:
|
|
13
|
+
*
|
|
14
|
+
* - **Definite negative** — the ID is certainly absent on the remote; no
|
|
15
|
+
* round-trip needed, the entry can be pushed immediately.
|
|
16
|
+
* - **Probable positive** — the ID *might* exist on the remote (subject to a
|
|
17
|
+
* configurable false-positive rate, default 1 %). Only these IDs require a
|
|
18
|
+
* follow-up `hasEntries` call to confirm.
|
|
19
|
+
*
|
|
20
|
+
* This is used by {@link BasicOnDiskContentAddressedStore.getIdBloomSummary} and
|
|
21
|
+
* consumed by the sync loop in `BaseMindooDB` to partition IDs into
|
|
22
|
+
* "definitely missing" and "maybe existing" buckets before making any network
|
|
23
|
+
* calls.
|
|
24
|
+
*
|
|
25
|
+
* ### Implementation details
|
|
26
|
+
*
|
|
27
|
+
* - Uses **enhanced double hashing** (FNV-1a + DJB2) to derive `k` bit
|
|
28
|
+
* positions from a single ID string, avoiding the need for `k` independent
|
|
29
|
+
* hash functions.
|
|
30
|
+
* - Bit-array size and hash count are computed from the classic bloom filter
|
|
31
|
+
* formulas to satisfy the requested false-positive rate.
|
|
32
|
+
* - The filter is versioned (`"bloom-v1"`) so future changes to hashing or
|
|
33
|
+
* encoding remain backward-compatible.
|
|
34
|
+
*
|
|
35
|
+
* @module bloom
|
|
36
|
+
*/
|
|
37
|
+
import type { StoreIdBloomSummary } from "./types";
|
|
38
|
+
/**
|
|
39
|
+
* Build a bloom filter summary from a list of entry IDs.
|
|
40
|
+
*
|
|
41
|
+
* The resulting {@link StoreIdBloomSummary} is a compact, serializable
|
|
42
|
+
* representation that can be transferred over the network (e.g. in sync
|
|
43
|
+
* protocol responses) and later queried with {@link bloomMightContainId}.
|
|
44
|
+
*
|
|
45
|
+
* Typical usage in the on-disk store:
|
|
46
|
+
* ```ts
|
|
47
|
+
* const ids = await store.getAllIds();
|
|
48
|
+
* const summary = createIdBloomSummary(ids);
|
|
49
|
+
* // send summary to the syncing peer
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param ids Array of entry ID strings to include in the filter.
|
|
53
|
+
* @param falsePositiveRate Target false-positive probability (default 1 %).
|
|
54
|
+
* @returns A serializable bloom filter summary (base64-encoded bitset).
|
|
55
|
+
*/
|
|
56
|
+
export declare function createIdBloomSummary(ids: string[], falsePositiveRate?: number): StoreIdBloomSummary;
|
|
57
|
+
/**
|
|
58
|
+
* Test whether an entry ID *might* be present in a bloom filter summary.
|
|
59
|
+
*
|
|
60
|
+
* - Returns `false` only when the ID is **definitely absent** — at least one
|
|
61
|
+
* of its bit-positions is unset, so the ID was never inserted.
|
|
62
|
+
* - Returns `true` when the ID **might be present** — all bit-positions are
|
|
63
|
+
* set, but this could be a false positive (probability ≤ the configured
|
|
64
|
+
* false-positive rate).
|
|
65
|
+
*
|
|
66
|
+
* If the summary version is unrecognized, conservatively returns `true` to
|
|
67
|
+
* avoid incorrectly skipping entries during sync.
|
|
68
|
+
*
|
|
69
|
+
* Used in the sync loop to partition local IDs:
|
|
70
|
+
* ```ts
|
|
71
|
+
* for (const id of localIds) {
|
|
72
|
+
* if (bloomMightContainId(remoteBloom, id)) {
|
|
73
|
+
* maybeExisting.push(id); // needs exact hasEntries() check
|
|
74
|
+
* } else {
|
|
75
|
+
* definitelyMissing.push(id); // can push without round-trip
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param summary The bloom filter summary obtained from the remote store.
|
|
81
|
+
* @param id The entry ID to test.
|
|
82
|
+
* @returns `true` if the ID might be in the set; `false` if it is definitely not.
|
|
83
|
+
*/
|
|
84
|
+
export declare function bloomMightContainId(summary: StoreIdBloomSummary, id: string): boolean;
|
|
85
|
+
//# sourceMappingURL=bloom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloom.d.ts","sourceRoot":"","sources":["../../../src/core/appendonlystores/bloom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA+HnD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,iBAAiB,GAAE,MAAoC,GAAG,mBAAmB,CAmBhI;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAYrF"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bloom filter for compact set-membership summaries of store entry IDs.
|
|
4
|
+
*
|
|
5
|
+
* During network sync, a local store needs to determine which of its entry IDs
|
|
6
|
+
* are missing from a remote store. Naively this requires sending every local ID
|
|
7
|
+
* to the remote for an exact `hasEntries` check — an O(n) network round-trip
|
|
8
|
+
* that dominates sync latency for large stores.
|
|
9
|
+
*
|
|
10
|
+
* A bloom filter provides a probabilistic shortcut: the remote store serializes
|
|
11
|
+
* its full ID set into a compact bitset ({@link StoreIdBloomSummary}) and sends
|
|
12
|
+
* it to the local side in a single response. The local side then tests each of
|
|
13
|
+
* its own IDs against the bloom filter:
|
|
14
|
+
*
|
|
15
|
+
* - **Definite negative** — the ID is certainly absent on the remote; no
|
|
16
|
+
* round-trip needed, the entry can be pushed immediately.
|
|
17
|
+
* - **Probable positive** — the ID *might* exist on the remote (subject to a
|
|
18
|
+
* configurable false-positive rate, default 1 %). Only these IDs require a
|
|
19
|
+
* follow-up `hasEntries` call to confirm.
|
|
20
|
+
*
|
|
21
|
+
* This is used by {@link BasicOnDiskContentAddressedStore.getIdBloomSummary} and
|
|
22
|
+
* consumed by the sync loop in `BaseMindooDB` to partition IDs into
|
|
23
|
+
* "definitely missing" and "maybe existing" buckets before making any network
|
|
24
|
+
* calls.
|
|
25
|
+
*
|
|
26
|
+
* ### Implementation details
|
|
27
|
+
*
|
|
28
|
+
* - Uses **enhanced double hashing** (FNV-1a + DJB2) to derive `k` bit
|
|
29
|
+
* positions from a single ID string, avoiding the need for `k` independent
|
|
30
|
+
* hash functions.
|
|
31
|
+
* - Bit-array size and hash count are computed from the classic bloom filter
|
|
32
|
+
* formulas to satisfy the requested false-positive rate.
|
|
33
|
+
* - The filter is versioned (`"bloom-v1"`) so future changes to hashing or
|
|
34
|
+
* encoding remain backward-compatible.
|
|
35
|
+
*
|
|
36
|
+
* @module bloom
|
|
37
|
+
*/
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.createIdBloomSummary = createIdBloomSummary;
|
|
40
|
+
exports.bloomMightContainId = bloomMightContainId;
|
|
41
|
+
/** Cross-platform Uint8Array -> base64 string. */
|
|
42
|
+
function uint8ArrayToBase64(bytes) {
|
|
43
|
+
let binary = "";
|
|
44
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
45
|
+
binary += String.fromCharCode(bytes[i]);
|
|
46
|
+
}
|
|
47
|
+
return btoa(binary);
|
|
48
|
+
}
|
|
49
|
+
/** Cross-platform base64 string -> Uint8Array. */
|
|
50
|
+
function base64ToUint8Array(base64) {
|
|
51
|
+
const binary = atob(base64);
|
|
52
|
+
const bytes = new Uint8Array(binary.length);
|
|
53
|
+
for (let i = 0; i < binary.length; i++) {
|
|
54
|
+
bytes[i] = binary.charCodeAt(i);
|
|
55
|
+
}
|
|
56
|
+
return bytes;
|
|
57
|
+
}
|
|
58
|
+
/** Default probability of a false positive (1 %). */
|
|
59
|
+
const DEFAULT_FALSE_POSITIVE_RATE = 0.01;
|
|
60
|
+
/** Salt mixed into every hash to namespace this bloom filter version. */
|
|
61
|
+
const DEFAULT_SALT = "mindoodb-bloom-v1";
|
|
62
|
+
/**
|
|
63
|
+
* FNV-1a 32-bit hash.
|
|
64
|
+
*
|
|
65
|
+
* Used as the first of two independent hash bases for enhanced double hashing.
|
|
66
|
+
* FNV-1a is fast, has good avalanche properties, and is simple to implement
|
|
67
|
+
* without external dependencies.
|
|
68
|
+
*/
|
|
69
|
+
function fnv1a32(input) {
|
|
70
|
+
let hash = 0x811c9dc5;
|
|
71
|
+
for (let i = 0; i < input.length; i++) {
|
|
72
|
+
hash ^= input.charCodeAt(i);
|
|
73
|
+
hash = Math.imul(hash, 0x01000193);
|
|
74
|
+
}
|
|
75
|
+
return hash >>> 0;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* DJB2 32-bit hash (Daniel J. Bernstein).
|
|
79
|
+
*
|
|
80
|
+
* Used as the second hash base. Chosen for its simplicity and because it is
|
|
81
|
+
* sufficiently independent from FNV-1a to give good bit dispersion when
|
|
82
|
+
* combined via enhanced double hashing: h(i) = h1 + i * h2.
|
|
83
|
+
*/
|
|
84
|
+
function djb2_32(input) {
|
|
85
|
+
let hash = 5381;
|
|
86
|
+
for (let i = 0; i < input.length; i++) {
|
|
87
|
+
hash = ((hash << 5) + hash + input.charCodeAt(i)) >>> 0;
|
|
88
|
+
}
|
|
89
|
+
return hash >>> 0;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Compute the optimal bit-array size and number of hash functions for a bloom
|
|
93
|
+
* filter given the expected item count and desired false-positive rate.
|
|
94
|
+
*
|
|
95
|
+
* Uses the standard formulas:
|
|
96
|
+
* m = -(n * ln(p)) / (ln2)^2 (bit count)
|
|
97
|
+
* k = (m / n) * ln2 (hash count)
|
|
98
|
+
*
|
|
99
|
+
* A minimum of 64 bits and 1 hash is enforced so the filter remains valid
|
|
100
|
+
* even for very small or empty sets.
|
|
101
|
+
*
|
|
102
|
+
* @param itemCount Expected number of distinct IDs.
|
|
103
|
+
* @param falsePositiveRate Target false-positive probability (0 < p < 1).
|
|
104
|
+
* @returns Optimal `bitCount` and `hashCount`.
|
|
105
|
+
*/
|
|
106
|
+
function computeBloomShape(itemCount, falsePositiveRate) {
|
|
107
|
+
if (itemCount <= 0) {
|
|
108
|
+
return { bitCount: 64, hashCount: 2 };
|
|
109
|
+
}
|
|
110
|
+
const ln2 = Math.log(2);
|
|
111
|
+
const bitCount = Math.max(64, Math.ceil((-itemCount * Math.log(falsePositiveRate)) / (ln2 * ln2)));
|
|
112
|
+
const hashCount = Math.max(1, Math.round((bitCount / itemCount) * ln2));
|
|
113
|
+
return { bitCount, hashCount };
|
|
114
|
+
}
|
|
115
|
+
/** Set a single bit in a byte-packed bitset. */
|
|
116
|
+
function setBit(bitset, bitIndex) {
|
|
117
|
+
const byteIndex = Math.floor(bitIndex / 8);
|
|
118
|
+
const bitOffset = bitIndex % 8;
|
|
119
|
+
bitset[byteIndex] |= 1 << bitOffset;
|
|
120
|
+
}
|
|
121
|
+
/** Test whether a single bit is set in a byte-packed bitset. */
|
|
122
|
+
function getBit(bitset, bitIndex) {
|
|
123
|
+
const byteIndex = Math.floor(bitIndex / 8);
|
|
124
|
+
const bitOffset = bitIndex % 8;
|
|
125
|
+
return (bitset[byteIndex] & (1 << bitOffset)) !== 0;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Derive `hashCount` bit-positions for an ID using enhanced double hashing.
|
|
129
|
+
*
|
|
130
|
+
* Enhanced double hashing computes k positions as:
|
|
131
|
+
* index_i = (h1 + i * h2) mod bitCount
|
|
132
|
+
*
|
|
133
|
+
* where h1 = FNV-1a(salt + id) and h2 = DJB2(id + salt). The salt is
|
|
134
|
+
* prepended/appended in opposite order to reduce correlation between the two
|
|
135
|
+
* hash values.
|
|
136
|
+
*
|
|
137
|
+
* @param id The entry ID to hash.
|
|
138
|
+
* @param bitCount Total bits in the bloom filter.
|
|
139
|
+
* @param hashCount Number of bit positions to produce.
|
|
140
|
+
* @param salt Version-specific salt string.
|
|
141
|
+
* @returns Array of `hashCount` bit-positions in [0, bitCount).
|
|
142
|
+
*/
|
|
143
|
+
function bloomIndexes(id, bitCount, hashCount, salt) {
|
|
144
|
+
const h1 = fnv1a32(`${salt}:${id}`);
|
|
145
|
+
const h2 = djb2_32(`${id}:${salt}`) || 1;
|
|
146
|
+
const indexes = [];
|
|
147
|
+
for (let i = 0; i < hashCount; i++) {
|
|
148
|
+
indexes.push((h1 + i * h2) % bitCount);
|
|
149
|
+
}
|
|
150
|
+
return indexes;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Build a bloom filter summary from a list of entry IDs.
|
|
154
|
+
*
|
|
155
|
+
* The resulting {@link StoreIdBloomSummary} is a compact, serializable
|
|
156
|
+
* representation that can be transferred over the network (e.g. in sync
|
|
157
|
+
* protocol responses) and later queried with {@link bloomMightContainId}.
|
|
158
|
+
*
|
|
159
|
+
* Typical usage in the on-disk store:
|
|
160
|
+
* ```ts
|
|
161
|
+
* const ids = await store.getAllIds();
|
|
162
|
+
* const summary = createIdBloomSummary(ids);
|
|
163
|
+
* // send summary to the syncing peer
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param ids Array of entry ID strings to include in the filter.
|
|
167
|
+
* @param falsePositiveRate Target false-positive probability (default 1 %).
|
|
168
|
+
* @returns A serializable bloom filter summary (base64-encoded bitset).
|
|
169
|
+
*/
|
|
170
|
+
function createIdBloomSummary(ids, falsePositiveRate = DEFAULT_FALSE_POSITIVE_RATE) {
|
|
171
|
+
const { bitCount, hashCount } = computeBloomShape(ids.length, falsePositiveRate);
|
|
172
|
+
const bitset = new Uint8Array(Math.ceil(bitCount / 8));
|
|
173
|
+
for (const id of ids) {
|
|
174
|
+
const indexes = bloomIndexes(id, bitCount, hashCount, DEFAULT_SALT);
|
|
175
|
+
for (const idx of indexes) {
|
|
176
|
+
setBit(bitset, idx);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
version: "bloom-v1",
|
|
181
|
+
totalIds: ids.length,
|
|
182
|
+
bitCount,
|
|
183
|
+
hashCount,
|
|
184
|
+
salt: DEFAULT_SALT,
|
|
185
|
+
bitsetBase64: uint8ArrayToBase64(bitset),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Test whether an entry ID *might* be present in a bloom filter summary.
|
|
190
|
+
*
|
|
191
|
+
* - Returns `false` only when the ID is **definitely absent** — at least one
|
|
192
|
+
* of its bit-positions is unset, so the ID was never inserted.
|
|
193
|
+
* - Returns `true` when the ID **might be present** — all bit-positions are
|
|
194
|
+
* set, but this could be a false positive (probability ≤ the configured
|
|
195
|
+
* false-positive rate).
|
|
196
|
+
*
|
|
197
|
+
* If the summary version is unrecognized, conservatively returns `true` to
|
|
198
|
+
* avoid incorrectly skipping entries during sync.
|
|
199
|
+
*
|
|
200
|
+
* Used in the sync loop to partition local IDs:
|
|
201
|
+
* ```ts
|
|
202
|
+
* for (const id of localIds) {
|
|
203
|
+
* if (bloomMightContainId(remoteBloom, id)) {
|
|
204
|
+
* maybeExisting.push(id); // needs exact hasEntries() check
|
|
205
|
+
* } else {
|
|
206
|
+
* definitelyMissing.push(id); // can push without round-trip
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @param summary The bloom filter summary obtained from the remote store.
|
|
212
|
+
* @param id The entry ID to test.
|
|
213
|
+
* @returns `true` if the ID might be in the set; `false` if it is definitely not.
|
|
214
|
+
*/
|
|
215
|
+
function bloomMightContainId(summary, id) {
|
|
216
|
+
if (summary.version !== "bloom-v1") {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
const bitset = base64ToUint8Array(summary.bitsetBase64);
|
|
220
|
+
const indexes = bloomIndexes(id, summary.bitCount, summary.hashCount, summary.salt);
|
|
221
|
+
for (const idx of indexes) {
|
|
222
|
+
if (!getBit(bitset, idx)) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=bloom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloom.js","sourceRoot":"","sources":["../../../src/core/appendonlystores/bloom.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;;AAmJH,oDAmBC;AA6BD,kDAYC;AA3MD,kDAAkD;AAClD,SAAS,kBAAkB,CAAC,KAAiB;IAC3C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAC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Q,EAAE,GAAG,CAAC,MAAM;QACpB,QAAQ;QACR,SAAS;QACT,IAAI,EAAE,YAAY;QAClB,YAAY,EAAE,kBAAkB,CAAC,MAAM,CAAC;KACzC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,mBAAmB,CAAC,OAA4B,EAAE,EAAU;IAC1E,IAAI,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,OAAO,GAAG,YAAY,CAAC,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CryptoAdapter } from "../../crypto/CryptoAdapter";
|
|
2
2
|
import type { MindooTenantDirectory } from "../../types";
|
|
3
3
|
import type { AuthResult, NetworkAuthTokenPayload } from "./types";
|
|
4
|
+
import { Logger } from "../../logging";
|
|
4
5
|
/**
|
|
5
6
|
* Authentication service for network sync operations.
|
|
6
7
|
*
|
|
@@ -24,10 +25,12 @@ export declare class AuthenticationService {
|
|
|
24
25
|
private jwtSecret;
|
|
25
26
|
private challengeExpirationMs;
|
|
26
27
|
private tokenExpirationMs;
|
|
28
|
+
private logger;
|
|
27
29
|
constructor(cryptoAdapter: CryptoAdapter, directory: MindooTenantDirectory, tenantId: string, options?: {
|
|
28
30
|
jwtSecret?: Uint8Array;
|
|
29
31
|
challengeExpirationMs?: number;
|
|
30
32
|
tokenExpirationMs?: number;
|
|
33
|
+
logger?: Logger;
|
|
31
34
|
});
|
|
32
35
|
/**
|
|
33
36
|
* Generate a challenge for a user to sign.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationService.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/AuthenticationService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAEV,UAAU,EACV,uBAAuB,EACxB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthenticationService.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/AuthenticationService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAEV,UAAU,EACV,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,MAAM,EAAoC,MAAM,eAAe,CAAC;AAEzE;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,UAAU,CAAyC;IAG3D,OAAO,CAAC,SAAS,CAAa;IAG9B,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,MAAM,CAAS;gBAGrB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,qBAAqB,EAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,UAAU,CAAC;QACvB,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAiBH;;;;;;OAMG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoC1D;;;;;;OAMG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAwEjF;;;;;OAKG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;IAiC3E;;OAEG;YACW,eAAe;IAwC7B;;;OAGG;YACW,aAAa;IAgC3B;;OAEG;YACW,WAAW;IA6CzB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAWhC,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,kBAAkB;CAQ3B"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AuthenticationService = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const types_1 = require("./types");
|
|
6
|
+
const logging_1 = require("../../logging");
|
|
6
7
|
/**
|
|
7
8
|
* Authentication service for network sync operations.
|
|
8
9
|
*
|
|
@@ -30,6 +31,9 @@ class AuthenticationService {
|
|
|
30
31
|
// Default: 5 minutes for challenge, 1 hour for token
|
|
31
32
|
this.challengeExpirationMs = options?.challengeExpirationMs || 5 * 60 * 1000;
|
|
32
33
|
this.tokenExpirationMs = options?.tokenExpirationMs || 60 * 60 * 1000;
|
|
34
|
+
this.logger =
|
|
35
|
+
options?.logger ||
|
|
36
|
+
new logging_1.MindooLogger((0, logging_1.getDefaultLogLevel)(), `AuthenticationService:${tenantId}`, true);
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* Generate a challenge for a user to sign.
|
|
@@ -39,7 +43,7 @@ class AuthenticationService {
|
|
|
39
43
|
* @throws NetworkError if user not found or revoked
|
|
40
44
|
*/
|
|
41
45
|
async generateChallenge(username) {
|
|
42
|
-
|
|
46
|
+
this.logger.debug(`Generating challenge for user: ${username}`);
|
|
43
47
|
// Check if user exists and is not revoked
|
|
44
48
|
const userKeys = await this.directory.getUserPublicKeys(username);
|
|
45
49
|
if (!userKeys) {
|
|
@@ -64,7 +68,7 @@ class AuthenticationService {
|
|
|
64
68
|
this.challenges.set(challenge, authChallenge);
|
|
65
69
|
// Clean up expired challenges periodically
|
|
66
70
|
this.cleanupExpiredChallenges();
|
|
67
|
-
|
|
71
|
+
this.logger.debug(`Generated challenge for user ${username}: ${challenge}`);
|
|
68
72
|
return challenge;
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
@@ -75,11 +79,11 @@ class AuthenticationService {
|
|
|
75
79
|
* @returns AuthResult with success status and JWT token
|
|
76
80
|
*/
|
|
77
81
|
async authenticate(challenge, signature) {
|
|
78
|
-
|
|
82
|
+
this.logger.debug(`Authenticating challenge: ${challenge}`);
|
|
79
83
|
// Get and validate challenge
|
|
80
84
|
const authChallenge = this.challenges.get(challenge);
|
|
81
85
|
if (!authChallenge) {
|
|
82
|
-
|
|
86
|
+
this.logger.debug(`Challenge not found: ${challenge}`);
|
|
83
87
|
return {
|
|
84
88
|
success: false,
|
|
85
89
|
error: "Challenge not found or expired",
|
|
@@ -87,7 +91,7 @@ class AuthenticationService {
|
|
|
87
91
|
}
|
|
88
92
|
// Check if challenge is expired
|
|
89
93
|
if (Date.now() > authChallenge.expiresAt) {
|
|
90
|
-
|
|
94
|
+
this.logger.debug(`Challenge expired: ${challenge}`);
|
|
91
95
|
this.challenges.delete(challenge);
|
|
92
96
|
return {
|
|
93
97
|
success: false,
|
|
@@ -96,7 +100,7 @@ class AuthenticationService {
|
|
|
96
100
|
}
|
|
97
101
|
// Check if challenge was already used
|
|
98
102
|
if (authChallenge.used) {
|
|
99
|
-
|
|
103
|
+
this.logger.debug(`Challenge already used: ${challenge}`);
|
|
100
104
|
return {
|
|
101
105
|
success: false,
|
|
102
106
|
error: "Challenge already used",
|
|
@@ -108,7 +112,7 @@ class AuthenticationService {
|
|
|
108
112
|
// Get user's public signing key
|
|
109
113
|
const userKeys = await this.directory.getUserPublicKeys(username);
|
|
110
114
|
if (!userKeys) {
|
|
111
|
-
|
|
115
|
+
this.logger.debug(`User not found or revoked: ${username}`);
|
|
112
116
|
return {
|
|
113
117
|
success: false,
|
|
114
118
|
error: "User not found or revoked",
|
|
@@ -117,7 +121,7 @@ class AuthenticationService {
|
|
|
117
121
|
// Verify signature
|
|
118
122
|
const isValid = await this.verifySignature(challenge, signature, userKeys.signingPublicKey);
|
|
119
123
|
if (!isValid) {
|
|
120
|
-
|
|
124
|
+
this.logger.debug(`Invalid signature for user: ${username}`);
|
|
121
125
|
return {
|
|
122
126
|
success: false,
|
|
123
127
|
error: "Invalid signature",
|
|
@@ -125,7 +129,7 @@ class AuthenticationService {
|
|
|
125
129
|
}
|
|
126
130
|
// Generate JWT token
|
|
127
131
|
const token = await this.generateToken(username);
|
|
128
|
-
|
|
132
|
+
this.logger.info(`Authentication successful for user: ${username}`);
|
|
129
133
|
return {
|
|
130
134
|
success: true,
|
|
131
135
|
token,
|
|
@@ -138,30 +142,30 @@ class AuthenticationService {
|
|
|
138
142
|
* @returns The token payload if valid, null otherwise
|
|
139
143
|
*/
|
|
140
144
|
async validateToken(token) {
|
|
141
|
-
|
|
145
|
+
this.logger.debug(`Validating token`);
|
|
142
146
|
try {
|
|
143
147
|
const payload = await this.verifyToken(token);
|
|
144
148
|
if (!payload) {
|
|
145
|
-
|
|
149
|
+
this.logger.debug(`Invalid token signature`);
|
|
146
150
|
return null;
|
|
147
151
|
}
|
|
148
152
|
// Check expiration
|
|
149
153
|
const now = Math.floor(Date.now() / 1000);
|
|
150
154
|
if (payload.exp < now) {
|
|
151
|
-
|
|
155
|
+
this.logger.debug(`Token expired`);
|
|
152
156
|
return null;
|
|
153
157
|
}
|
|
154
158
|
// Check if user is still valid (not revoked)
|
|
155
159
|
const isRevoked = await this.directory.isUserRevoked(payload.sub);
|
|
156
160
|
if (isRevoked) {
|
|
157
|
-
|
|
161
|
+
this.logger.debug(`User revoked: ${payload.sub}`);
|
|
158
162
|
return null;
|
|
159
163
|
}
|
|
160
|
-
|
|
164
|
+
this.logger.debug(`Token valid for user: ${payload.sub}`);
|
|
161
165
|
return payload;
|
|
162
166
|
}
|
|
163
167
|
catch (error) {
|
|
164
|
-
|
|
168
|
+
this.logger.error(`Token validation error:`, error);
|
|
165
169
|
return null;
|
|
166
170
|
}
|
|
167
171
|
}
|
|
@@ -184,7 +188,7 @@ class AuthenticationService {
|
|
|
184
188
|
return isValid;
|
|
185
189
|
}
|
|
186
190
|
catch (error) {
|
|
187
|
-
|
|
191
|
+
this.logger.error(`Signature verification error:`, error);
|
|
188
192
|
return false;
|
|
189
193
|
}
|
|
190
194
|
}
|
|
@@ -237,7 +241,7 @@ class AuthenticationService {
|
|
|
237
241
|
return payload;
|
|
238
242
|
}
|
|
239
243
|
catch (error) {
|
|
240
|
-
|
|
244
|
+
this.logger.error(`Token verification error:`, error);
|
|
241
245
|
return null;
|
|
242
246
|
}
|
|
243
247
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationService.js","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/AuthenticationService.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAQpC,mCAAyD;
|
|
1
|
+
{"version":3,"file":"AuthenticationService.js","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/AuthenticationService.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAQpC,mCAAyD;AACzD,2CAAyE;AAEzE;;;;;;;;;;;;;;GAcG;AACH,MAAa,qBAAqB;IAgBhC,YACE,aAA4B,EAC5B,SAAgC,EAChC,QAAgB,EAChB,OAKC;QApBH,uEAAuE;QAC/D,e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1
|
-
import type { StoreEntry, StoreEntryMetadata } from "../../types";
|
|
2
|
-
import type { NetworkEncryptedEntry, AuthResult } from "./types";
|
|
1
|
+
import type { StoreEntry, StoreEntryMetadata, StoreEntryType, StoreScanCursor, StoreScanFilters, StoreScanResult, StoreIdBloomSummary, StoreCompactionStatus } from "../../types";
|
|
2
|
+
import type { NetworkEncryptedEntry, AuthResult, NetworkSyncCapabilities } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Abstract interface for network communication in MindooDB sync.
|
|
5
5
|
*
|
|
@@ -45,6 +45,11 @@ export interface NetworkTransport {
|
|
|
45
45
|
* @throws NetworkError with type USER_REVOKED if user has been revoked
|
|
46
46
|
*/
|
|
47
47
|
authenticate(challenge: string, signature: Uint8Array): Promise<AuthResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Get advertised sync capabilities from the remote endpoint.
|
|
50
|
+
* Optional for backward compatibility.
|
|
51
|
+
*/
|
|
52
|
+
getCapabilities?(token: string): Promise<NetworkSyncCapabilities>;
|
|
48
53
|
/**
|
|
49
54
|
* Find entries that the remote has which we don't have locally.
|
|
50
55
|
*
|
|
@@ -71,6 +76,35 @@ export interface NetworkTransport {
|
|
|
71
76
|
* @throws NetworkError with type USER_REVOKED if user has been revoked since token was issued
|
|
72
77
|
*/
|
|
73
78
|
findNewEntriesForDoc(token: string, haveIds: string[], docId: string): Promise<StoreEntryMetadata[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Find entries by type and creation date range from the remote store.
|
|
81
|
+
*
|
|
82
|
+
* This enables efficient server-side filtering for time-travel queries.
|
|
83
|
+
*
|
|
84
|
+
* @param token JWT access token from authenticate()
|
|
85
|
+
* @param type The entry type to filter by
|
|
86
|
+
* @param creationDateFrom Optional start timestamp (inclusive). If null, no lower bound.
|
|
87
|
+
* @param creationDateUntil Optional end timestamp (exclusive). If null, no upper bound.
|
|
88
|
+
* @returns List of entry metadata matching the criteria
|
|
89
|
+
* @throws NetworkError with type INVALID_TOKEN if token is invalid or expired
|
|
90
|
+
* @throws NetworkError with type USER_REVOKED if user has been revoked since token was issued
|
|
91
|
+
*/
|
|
92
|
+
findEntries(token: string, type: StoreEntryType, creationDateFrom: number | null, creationDateUntil: number | null): Promise<StoreEntryMetadata[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Cursor-based metadata scan from remote store.
|
|
95
|
+
*
|
|
96
|
+
* Optional transport capability. Implementations that do not support this
|
|
97
|
+
* can omit it; callers should fall back to findNewEntries/getAllIds paths.
|
|
98
|
+
*/
|
|
99
|
+
scanEntriesSince?(token: string, cursor: StoreScanCursor | null, limit?: number, filters?: StoreScanFilters): Promise<StoreScanResult>;
|
|
100
|
+
/**
|
|
101
|
+
* Optional probabilistic ID summary for sync optimization.
|
|
102
|
+
*/
|
|
103
|
+
getIdBloomSummary?(token: string): Promise<StoreIdBloomSummary>;
|
|
104
|
+
/**
|
|
105
|
+
* Optional compaction observability for remote store monitoring.
|
|
106
|
+
*/
|
|
107
|
+
getCompactionStatus?(token: string): Promise<StoreCompactionStatus>;
|
|
74
108
|
/**
|
|
75
109
|
* Get entries from the remote store.
|
|
76
110
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkTransport.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/NetworkTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"NetworkTransport.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/NetworkTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAE1F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,gBAAgB;IA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AU,CACR,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EAAE,GACZ,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAEpC;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE5D;;;;;;;;;;OAUG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE5C;;;;;;;;;;;;;;;OAeG;IACH,mBAAmB,CACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -106,6 +106,16 @@ export interface AuthResult {
|
|
|
106
106
|
*/
|
|
107
107
|
error?: string;
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Advertised sync capabilities for transport-level feature negotiation.
|
|
111
|
+
* Used by clients to choose fast paths while preserving compatibility.
|
|
112
|
+
*/
|
|
113
|
+
export interface NetworkSyncCapabilities {
|
|
114
|
+
protocolVersion: string;
|
|
115
|
+
supportsCursorScan: boolean;
|
|
116
|
+
supportsIdBloomSummary: boolean;
|
|
117
|
+
supportsCompactionStatus: boolean;
|
|
118
|
+
}
|
|
109
119
|
/**
|
|
110
120
|
* Network transport error types for error handling.
|
|
111
121
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D;;;;;;;;;;OAUG;IACH,mBAAmB,EAAE,UAAU,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,kCAAkC;IAClC,aAAa,kBAAkB;IAC/B,4BAA4B;IAC5B,YAAY,iBAAiB;IAC7B,oCAAoC;IACpC,iBAAiB,sBAAsB;IACvC,wCAAwC;IACxC,iBAAiB,sBAAsB;IACvC,kCAAkC;IAClC,aAAa,kBAAkB;IAC/B,wBAAwB;IACxB,YAAY,iBAAiB;IAC7B,kCAAkC;IAClC,cAAc,mBAAmB;CAClC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;aAEnB,IAAI,EAAE,gBAAgB;gBAAtB,IAAI,EAAE,gBAAgB,EACtC,OAAO,EAAE,MAAM;CAKlB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D;;;;;;;;;;OAUG;IACH,mBAAmB,EAAE,UAAU,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,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