@evolu/common 6.0.1-preview.24 → 6.0.1-preview.26
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/dist/src/Assert.d.ts +0 -13
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +0 -15
- package/dist/src/Cache.d.ts +44 -0
- package/dist/src/Cache.d.ts.map +1 -0
- package/dist/src/Cache.js +52 -0
- package/dist/src/Evolu/Db.d.ts +6 -6
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +4 -0
- package/dist/src/Evolu/LocalAuth.d.ts +2 -2
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.d.ts +116 -86
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +48 -45
- package/dist/src/Evolu/Relay.d.ts +6 -5
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +40 -39
- package/dist/src/Evolu/Storage.d.ts +6 -11
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +30 -9
- package/dist/src/Evolu/Sync.d.ts +5 -5
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +3 -5
- package/dist/src/Evolu/Timestamp.d.ts +24 -0
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +24 -0
- package/dist/src/Identicon.d.ts +35 -0
- package/dist/src/Identicon.d.ts.map +1 -0
- package/dist/src/Identicon.js +143 -0
- package/dist/src/ManyToManyMap.d.ts +0 -3
- package/dist/src/ManyToManyMap.d.ts.map +1 -1
- package/dist/src/Result.d.ts +13 -6
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Sqlite.d.ts +36 -1
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +56 -3
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +36 -0
- package/dist/src/Type.d.ts +73 -9
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +124 -22
- package/dist/src/Types.d.ts +1 -1
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +2 -7
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/package.json +1 -1
- package/src/Assert.ts +0 -19
- package/src/Cache.ts +85 -0
- package/src/Evolu/Db.ts +11 -7
- package/src/Evolu/LocalAuth.ts +19 -7
- package/src/Evolu/Owner.ts +140 -103
- package/src/Evolu/Relay.ts +52 -48
- package/src/Evolu/Storage.ts +47 -23
- package/src/Evolu/Sync.ts +11 -12
- package/src/Evolu/Timestamp.ts +24 -0
- package/src/Identicon.ts +197 -0
- package/src/ManyToManyMap.ts +0 -3
- package/src/Result.ts +13 -6
- package/src/Sqlite.ts +68 -5
- package/src/Task.ts +41 -0
- package/src/Type.ts +262 -27
- package/src/Types.ts +1 -1
- package/src/WebSocket.ts +6 -10
- package/src/index.ts +2 -0
package/dist/src/Assert.d.ts
CHANGED
|
@@ -55,17 +55,4 @@ export declare const assertNonEmptyArray: <T>(arr: Array<T>, message?: string) =
|
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
57
|
export declare const assertNonEmptyReadonlyArray: <T>(arr: ReadonlyArray<T>, message?: string) => asserts arr is readonly [T, ...Array<T>];
|
|
58
|
-
/**
|
|
59
|
-
* Asserts no error reaches a `.catch` block, throwing a developer error if it
|
|
60
|
-
* does. Used in Promise chains where errors indicate bugs to be fixed.
|
|
61
|
-
*
|
|
62
|
-
* ### Example
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* Promise.reject("test").catch((e) =>
|
|
66
|
-
* assertNoErrorInCatch("WebSocket retry", e),
|
|
67
|
-
* );
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export declare function assertNoErrorInCatch(context: string, error: unknown): never;
|
|
71
58
|
//# sourceMappingURL=Assert.d.ts.map
|
package/dist/src/Assert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Assert.d.ts","sourceRoot":"","sources":["../../src/Assert.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,MAAM,EAAE,CACnB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,KACZ,OAAO,CAAC,SAIZ,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,EAClC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EACb,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAKlC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,EAC1C,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAK3C,CAAC
|
|
1
|
+
{"version":3,"file":"Assert.d.ts","sourceRoot":"","sources":["../../src/Assert.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,MAAM,EAAE,CACnB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,KACZ,OAAO,CAAC,SAIZ,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,EAClC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EACb,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAKlC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,EAC1C,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAK3C,CAAC"}
|
package/dist/src/Assert.js
CHANGED
|
@@ -63,18 +63,3 @@ export const assertNonEmptyArray = (arr, message = "Expected a non-empty array."
|
|
|
63
63
|
export const assertNonEmptyReadonlyArray = (arr, message = "Expected a non-empty readonly array.") => {
|
|
64
64
|
assert(arr.length > 0, message);
|
|
65
65
|
};
|
|
66
|
-
/**
|
|
67
|
-
* Asserts no error reaches a `.catch` block, throwing a developer error if it
|
|
68
|
-
* does. Used in Promise chains where errors indicate bugs to be fixed.
|
|
69
|
-
*
|
|
70
|
-
* ### Example
|
|
71
|
-
*
|
|
72
|
-
* ```ts
|
|
73
|
-
* Promise.reject("test").catch((e) =>
|
|
74
|
-
* assertNoErrorInCatch("WebSocket retry", e),
|
|
75
|
-
* );
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export function assertNoErrorInCatch(context, error) {
|
|
79
|
-
throw new Error(`Error in ${context}: an unexpected error reached a catch block and requires a fix`, { cause: error });
|
|
80
|
-
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🗄️ Generic cache interface and LRU cache implementation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { PositiveInt } from "./Type.js";
|
|
7
|
+
/**
|
|
8
|
+
* Generic cache interface providing basic key-value storage operations.
|
|
9
|
+
*
|
|
10
|
+
* Keys are compared by reference (standard Map semantics).
|
|
11
|
+
*
|
|
12
|
+
* Note: Cache does not extend Map because eviction policies (like in LRU)
|
|
13
|
+
* violate the Liskov Substitution Principle.
|
|
14
|
+
*/
|
|
15
|
+
export interface Cache<K, V> {
|
|
16
|
+
/** Checks if a key exists in the cache. */
|
|
17
|
+
has: (key: K) => boolean;
|
|
18
|
+
/** Retrieves the value for a key, or undefined if not present. */
|
|
19
|
+
get: (key: K) => V | undefined;
|
|
20
|
+
/** Stores a key-value pair in the cache. */
|
|
21
|
+
set: (key: K, val: V) => void;
|
|
22
|
+
/** Removes a key from the cache. */
|
|
23
|
+
delete: (key: K) => void;
|
|
24
|
+
/** Returns a readonly view of the internal Map. */
|
|
25
|
+
readonly map: ReadonlyMap<K, V>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a Least Recently Used (LRU) cache with a maximum capacity.
|
|
29
|
+
*
|
|
30
|
+
* When the cache reaches capacity, the least recently used entry is evicted.
|
|
31
|
+
* Both `get` and `set` operations update the access order.
|
|
32
|
+
*
|
|
33
|
+
* ### Example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const cache = createLruCache<string, number>(2);
|
|
37
|
+
* cache.set("a", 1);
|
|
38
|
+
* cache.set("b", 2);
|
|
39
|
+
* cache.set("c", 3); // Evicts "a"
|
|
40
|
+
* cache.has("a"); // false
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const createLruCache: <K, V>(capacity: PositiveInt) => Cache<K, V>;
|
|
44
|
+
//# sourceMappingURL=Cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../src/Cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;IACzB,2CAA2C;IAC3C,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;IAEzB,kEAAkE;IAClE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAE/B,4CAA4C;IAC5C,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC;IAE9B,oCAAoC;IACpC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC;IAEzB,mDAAmD;IACnD,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,EAAE,UAAU,WAAW,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAmCtE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🗄️ Generic cache interface and LRU cache implementation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Least Recently Used (LRU) cache with a maximum capacity.
|
|
8
|
+
*
|
|
9
|
+
* When the cache reaches capacity, the least recently used entry is evicted.
|
|
10
|
+
* Both `get` and `set` operations update the access order.
|
|
11
|
+
*
|
|
12
|
+
* ### Example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const cache = createLruCache<string, number>(2);
|
|
16
|
+
* cache.set("a", 1);
|
|
17
|
+
* cache.set("b", 2);
|
|
18
|
+
* cache.set("c", 3); // Evicts "a"
|
|
19
|
+
* cache.has("a"); // false
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const createLruCache = (capacity) => {
|
|
23
|
+
const internalMap = new Map();
|
|
24
|
+
return {
|
|
25
|
+
has: (key) => internalMap.has(key),
|
|
26
|
+
get: (key) => {
|
|
27
|
+
const value = internalMap.get(key);
|
|
28
|
+
if (value === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
// Move to end (most recently used)
|
|
31
|
+
internalMap.delete(key);
|
|
32
|
+
internalMap.set(key, value);
|
|
33
|
+
return value;
|
|
34
|
+
},
|
|
35
|
+
set: (key, val) => {
|
|
36
|
+
// If key exists, delete it first to update order
|
|
37
|
+
if (internalMap.has(key)) {
|
|
38
|
+
internalMap.delete(key);
|
|
39
|
+
}
|
|
40
|
+
else if (internalMap.size === capacity) {
|
|
41
|
+
// Evict least recently used (first entry)
|
|
42
|
+
const firstKey = internalMap.keys().next().value;
|
|
43
|
+
internalMap.delete(firstKey);
|
|
44
|
+
}
|
|
45
|
+
internalMap.set(key, val);
|
|
46
|
+
},
|
|
47
|
+
delete: (key) => {
|
|
48
|
+
internalMap.delete(key);
|
|
49
|
+
},
|
|
50
|
+
map: internalMap,
|
|
51
|
+
};
|
|
52
|
+
};
|
package/dist/src/Evolu/Db.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { Id, Mnemonic, SimpleName } from "../Type.js";
|
|
|
10
10
|
import { CreateWebSocketDep } from "../WebSocket.js";
|
|
11
11
|
import { Worker } from "../Worker.js";
|
|
12
12
|
import { QueryPatches } from "./Diff.js";
|
|
13
|
-
import { AppOwner,
|
|
13
|
+
import { AppOwner, OwnerTransport } from "./Owner.js";
|
|
14
14
|
import { ProtocolError } from "./Protocol.js";
|
|
15
15
|
import { Query } from "./Query.js";
|
|
16
16
|
import { DbSchema, MutationChange } from "./Schema.js";
|
|
@@ -53,7 +53,7 @@ export interface DbConfig extends ConsoleConfig, TimestampConfig {
|
|
|
53
53
|
* added and removed for any owner (including {@link AppOwner}) via
|
|
54
54
|
* {@link Evolu#useOwner}.
|
|
55
55
|
*
|
|
56
|
-
* Use {@link
|
|
56
|
+
* Use {@link createOwnerWebSocketTransport} to create WebSocket transport
|
|
57
57
|
* configurations with proper URL formatting and {@link OwnerId} inclusion. The
|
|
58
58
|
* {@link OwnerId} in the URL enables relay authentication, allowing relay
|
|
59
59
|
* servers to control access (e.g., for paid tiers or private instances).
|
|
@@ -80,16 +80,16 @@ export interface DbConfig extends ConsoleConfig, TimestampConfig {
|
|
|
80
80
|
* // to work offline before the app connects
|
|
81
81
|
* transports: [];
|
|
82
82
|
*
|
|
83
|
-
* // Using
|
|
83
|
+
* // Using createOwnerWebSocketTransport helper for relay authentication
|
|
84
84
|
* transports: [
|
|
85
|
-
*
|
|
86
|
-
*
|
|
85
|
+
* createOwnerWebSocketTransport({
|
|
86
|
+
* url: "ws://localhost:4000",
|
|
87
87
|
* ownerId,
|
|
88
88
|
* }),
|
|
89
89
|
* ];
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
|
-
readonly transports: ReadonlyArray<
|
|
92
|
+
readonly transports: ReadonlyArray<OwnerTransport>;
|
|
93
93
|
/**
|
|
94
94
|
* External AppOwner to use when creating Evolu instance. Use this when you
|
|
95
95
|
* want to manage AppOwner creation and persistence externally (e.g., with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAEL,aAAa,EACb,cAAc,EACd,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAEL,qBAAqB,EAIrB,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAGL,MA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,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;CACnD,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;CACrB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAC3C,qBAAqB,GACrB,kBAAkB,GAClB,cAAc,GACd,SAAS,GACT,OAAO,CAAC;AAgBV,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CACzD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,eAAO,MAAM,yBAAyB,GACpC,cAAc,oBAAoB,KACjC,QAKsD,CAAC"}
|
package/dist/src/Evolu/Db.js
CHANGED
|
@@ -9,6 +9,7 @@ import { createAppOwner, createOwnerSecret, mnemonicToOwnerSecret, } from "./Own
|
|
|
9
9
|
import { protocolVersion } from "./Protocol.js";
|
|
10
10
|
import { createQueryRowsCache, deserializeQuery, emptyRows, } from "./Query.js";
|
|
11
11
|
import { ensureDbSchema, getDbSchema, } from "./Schema.js";
|
|
12
|
+
import { createBaseSqliteStorageTables } from "./Storage.js";
|
|
12
13
|
import { applyLocalOnlyChange, createClock, createSync, } from "./Sync.js";
|
|
13
14
|
import { timestampStringToTimestamp, timestampToTimestampString, } from "./Timestamp.js";
|
|
14
15
|
export const defaultDbConfig = {
|
|
@@ -209,6 +210,9 @@ const initializeDb = (deps) => (initialAppOwner, initialClock) => {
|
|
|
209
210
|
if (!result.ok)
|
|
210
211
|
return result;
|
|
211
212
|
}
|
|
213
|
+
const result = createBaseSqliteStorageTables(deps);
|
|
214
|
+
if (!result.ok)
|
|
215
|
+
return result;
|
|
212
216
|
return ok();
|
|
213
217
|
};
|
|
214
218
|
const handlers = {
|
|
@@ -2,8 +2,8 @@ import { RandomBytesDep } from "../Crypto.js";
|
|
|
2
2
|
import { Mnemonic } from "../Type.js";
|
|
3
3
|
import { AppOwner, OwnerId } from "./Owner.js";
|
|
4
4
|
/**
|
|
5
|
-
* Local authentication and authorization system for Evolu.
|
|
6
|
-
*
|
|
5
|
+
* Local authentication and authorization system for Evolu. This is API is
|
|
6
|
+
* subject to change and not recommended for production use.
|
|
7
7
|
*
|
|
8
8
|
* @experimental
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalAuth.d.ts","sourceRoot":"","sources":["../../../src/Evolu/LocalAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,QAAQ,EAKR,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,kFAAkF;IAClF,KAAK,EAAE,CACL,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAEhC,qDAAqD;IACrD,QAAQ,EAAE,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,gBAAgB,GAAG;QAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;KAAE,KACxD,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAEhC,oDAAoD;IACpD,UAAU,EAAE,CAAC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AC,YAAY,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,WAAW,GACX,UAAU,GACV,kBAAkB,GAClB,UAAU,CAAC;AAEf,4EAA4E;AAC5E,MAAM,MAAM,cAAc,GACtB,UAAU,GACV,iBAAiB,GACjB,4BAA4B,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,uBAAuB,GACvB,oBAAoB,GACpB,aAAa,GACb,gBAAgB,GAChB,MAAM,CAAC"}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { NonEmptyReadonlyArray } from "../Array.js";
|
|
2
2
|
import { EncryptionKey, RandomBytesDep } from "../Crypto.js";
|
|
3
|
-
import { Mnemonic, NonNegativeInt } from "../Type.js";
|
|
4
|
-
|
|
5
|
-
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
6
|
-
*
|
|
7
|
-
* Can be created using {@link createOwnerSecret} or converted from a
|
|
8
|
-
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
9
|
-
*/
|
|
10
|
-
export declare const OwnerSecret: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("../Type.js").LengthError<32>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "OwnerSecret", import("../Type.js").BrandWithoutRefineError<"OwnerSecret", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>, never>;
|
|
11
|
-
export type OwnerSecret = typeof OwnerSecret.Type;
|
|
12
|
-
/** Creates a {@link OwnerSecret}. */
|
|
13
|
-
export declare const createOwnerSecret: (deps: RandomBytesDep) => OwnerSecret;
|
|
14
|
-
/** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
|
|
15
|
-
export declare const ownerSecretToMnemonic: (secret: OwnerSecret) => Mnemonic;
|
|
16
|
-
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
17
|
-
export declare const mnemonicToOwnerSecret: (mnemonic: Mnemonic) => OwnerSecret;
|
|
3
|
+
import { Mnemonic, NonNegativeInt, PositiveInt } from "../Type.js";
|
|
4
|
+
import { TimestampBytes } from "./Timestamp.js";
|
|
18
5
|
/**
|
|
19
6
|
* The Owner represents ownership of data in Evolu. Every database change is
|
|
20
7
|
* assigned to an owner, enabling sync functionality and access control.
|
|
@@ -70,6 +57,20 @@ export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Type;
|
|
|
70
57
|
*/
|
|
71
58
|
export declare const OwnerWriteKey: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length16", import("../Type.js").LengthError<16>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "OwnerWriteKey", import("../Type.js").BrandWithoutRefineError<"OwnerWriteKey", import("../Type.js").LengthError<16> | import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, never>;
|
|
72
59
|
export type OwnerWriteKey = typeof OwnerWriteKey.Type;
|
|
60
|
+
/**
|
|
61
|
+
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
62
|
+
*
|
|
63
|
+
* Can be created using {@link createOwnerSecret} or converted from a
|
|
64
|
+
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
65
|
+
*/
|
|
66
|
+
export declare const OwnerSecret: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("../Type.js").LengthError<32>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "OwnerSecret", import("../Type.js").BrandWithoutRefineError<"OwnerSecret", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>, never>;
|
|
67
|
+
export type OwnerSecret = typeof OwnerSecret.Type;
|
|
68
|
+
/** Creates a {@link OwnerSecret}. */
|
|
69
|
+
export declare const createOwnerSecret: (deps: RandomBytesDep) => OwnerSecret;
|
|
70
|
+
/** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
|
|
71
|
+
export declare const ownerSecretToMnemonic: (secret: OwnerSecret) => Mnemonic;
|
|
72
|
+
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
73
|
+
export declare const mnemonicToOwnerSecret: (mnemonic: Mnemonic) => OwnerSecret;
|
|
73
74
|
/** Creates a randomly generated {@link OwnerWriteKey}. */
|
|
74
75
|
export declare const createOwnerWriteKey: (deps: RandomBytesDep) => OwnerWriteKey;
|
|
75
76
|
/**
|
|
@@ -115,71 +116,6 @@ export interface AppOwner extends Owner {
|
|
|
115
116
|
}
|
|
116
117
|
/** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
|
|
117
118
|
export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
|
|
118
|
-
/**
|
|
119
|
-
* Transport configuration for connecting to relays.
|
|
120
|
-
*
|
|
121
|
-
* Each {@link Owner} can specify one or more transports to connect to different
|
|
122
|
-
* relays for data synchronization. Currently supports WebSocket transport, with
|
|
123
|
-
* future support planned for Bluetooth, LocalNetwork, and other protocols.
|
|
124
|
-
*/
|
|
125
|
-
export type TransportConfig = WebSocketTransportConfig;
|
|
126
|
-
/**
|
|
127
|
-
* WebSocket transport configuration for relay connections.
|
|
128
|
-
*
|
|
129
|
-
* Use {@link createWebSocketTransportConfig} to create a properly formatted URL
|
|
130
|
-
* with {@link OwnerId}. The relay uses {@link parseOwnerIdFromUrl} to extract the
|
|
131
|
-
* OwnerId from the query string.
|
|
132
|
-
*
|
|
133
|
-
* ### Authentication and Error Handling
|
|
134
|
-
*
|
|
135
|
-
* When a relay rejects a connection (invalid OwnerId, unauthorized owner, or
|
|
136
|
-
* server error), the browser WebSocket API does not expose the specific HTTP
|
|
137
|
-
* status code or reason - it only reports a generic connection failure. The
|
|
138
|
-
* client automatically retries with exponential backoff and jitter, eventually
|
|
139
|
-
* succeeding once the configuration or server issue is resolved.
|
|
140
|
-
*
|
|
141
|
-
* Legitimate clients will be properly configured with valid credentials, so
|
|
142
|
-
* automatic retry is appropriate.
|
|
143
|
-
*
|
|
144
|
-
* @see {@link createWebSocketTransportConfig}
|
|
145
|
-
* @see {@link parseOwnerIdFromUrl}
|
|
146
|
-
*/
|
|
147
|
-
export interface WebSocketTransportConfig {
|
|
148
|
-
readonly type: "WebSocket";
|
|
149
|
-
readonly url: string;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Creates a {@link WebSocketTransportConfig} for the given relay URL and
|
|
153
|
-
* {@link OwnerId}.
|
|
154
|
-
*
|
|
155
|
-
* ### Example
|
|
156
|
-
*
|
|
157
|
-
* ```ts
|
|
158
|
-
* const transport = createWebSocketTransportConfig({
|
|
159
|
-
* relayUrl: "wss://relay.evolu.dev",
|
|
160
|
-
* ownerId: owner.id,
|
|
161
|
-
* });
|
|
162
|
-
* // Result: { type: "WebSocket", url: "wss://relay.evolu.dev?ownerId=..." }
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export declare const createWebSocketTransportConfig: ({ relayUrl, ownerId, }: {
|
|
166
|
-
readonly relayUrl: string;
|
|
167
|
-
readonly ownerId: OwnerId;
|
|
168
|
-
}) => WebSocketTransportConfig;
|
|
169
|
-
/**
|
|
170
|
-
* Extracts {@link OwnerId} from a URL query string.
|
|
171
|
-
*
|
|
172
|
-
* Parses the query string `?ownerId=...` and validates that the extracted value
|
|
173
|
-
* is a valid {@link OwnerId}.
|
|
174
|
-
*
|
|
175
|
-
* ### Example
|
|
176
|
-
*
|
|
177
|
-
* ```ts
|
|
178
|
-
* parseOwnerIdFromUrl("/sync?ownerId=_12345678abcdefgh");
|
|
179
|
-
* // Returns: OwnerId or null
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
export declare const parseOwnerIdFromUrl: (url: string | undefined) => OwnerId | null;
|
|
183
119
|
/**
|
|
184
120
|
* An {@link Owner} for sharding data.
|
|
185
121
|
*
|
|
@@ -193,10 +129,10 @@ export declare const parseOwnerIdFromUrl: (url: string | undefined) => OwnerId |
|
|
|
193
129
|
*/
|
|
194
130
|
export interface ShardOwner extends Owner {
|
|
195
131
|
readonly type: "ShardOwner";
|
|
196
|
-
readonly transports?: ReadonlyArray<
|
|
132
|
+
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
197
133
|
}
|
|
198
134
|
/** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
|
|
199
|
-
export declare const createShardOwner: (secret: OwnerSecret, transports?: ReadonlyArray<
|
|
135
|
+
export declare const createShardOwner: (secret: OwnerSecret, transports?: ReadonlyArray<OwnerTransport>) => ShardOwner;
|
|
200
136
|
/**
|
|
201
137
|
* Derives a {@link ShardOwner} from an {@link AppOwner} using the specified path.
|
|
202
138
|
*
|
|
@@ -215,11 +151,11 @@ export declare const createShardOwner: (secret: OwnerSecret, transports?: Readon
|
|
|
215
151
|
* - Use paths like `["project", "MyApp", 1]` for named partitions with versions
|
|
216
152
|
* - Each device can derive the same owners and set up initial structure
|
|
217
153
|
*/
|
|
218
|
-
export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number>, transports?: ReadonlyArray<
|
|
154
|
+
export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number>, transports?: ReadonlyArray<OwnerTransport>) => ShardOwner;
|
|
219
155
|
/** An {@link Owner} for collaborative data with write access. */
|
|
220
156
|
export interface SharedOwner extends Owner {
|
|
221
157
|
readonly type: "SharedOwner";
|
|
222
|
-
readonly transports?: ReadonlyArray<
|
|
158
|
+
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
223
159
|
}
|
|
224
160
|
/**
|
|
225
161
|
* Creates a {@link SharedOwner} from an {@link OwnerSecret} for collaborative
|
|
@@ -228,7 +164,7 @@ export interface SharedOwner extends Owner {
|
|
|
228
164
|
* Use {@link createSharedReadonlyOwner} to create a read-only version for
|
|
229
165
|
* sharing.
|
|
230
166
|
*/
|
|
231
|
-
export declare const createSharedOwner: (secret: OwnerSecret, transports?: ReadonlyArray<
|
|
167
|
+
export declare const createSharedOwner: (secret: OwnerSecret, transports?: ReadonlyArray<OwnerTransport>) => SharedOwner;
|
|
232
168
|
/**
|
|
233
169
|
* Read-only version of a {@link SharedOwner} for data sharing. Contains only the
|
|
234
170
|
* {@link OwnerId} and {@link EncryptionKey} needed for others to read the shared
|
|
@@ -238,8 +174,102 @@ export interface SharedReadonlyOwner {
|
|
|
238
174
|
readonly type: "SharedReadonlyOwner";
|
|
239
175
|
readonly id: OwnerId;
|
|
240
176
|
readonly encryptionKey: EncryptionKey;
|
|
241
|
-
readonly transports?: ReadonlyArray<
|
|
177
|
+
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
242
178
|
}
|
|
243
179
|
/** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
|
|
244
180
|
export declare const createSharedReadonlyOwner: (sharedOwner: SharedOwner) => SharedReadonlyOwner;
|
|
181
|
+
/**
|
|
182
|
+
* Transport configuration for connecting to relays.
|
|
183
|
+
*
|
|
184
|
+
* Currently only WebSocket, in the future Bluetooth, LocalNetwork, etc.
|
|
185
|
+
*/
|
|
186
|
+
export type OwnerTransport = OwnerWebSocketTransport;
|
|
187
|
+
/**
|
|
188
|
+
* WebSocket transport configuration.
|
|
189
|
+
*
|
|
190
|
+
* ### Authentication and Error Handling
|
|
191
|
+
*
|
|
192
|
+
* When a relay rejects a connection (invalid OwnerId, unauthorized owner, or
|
|
193
|
+
* server error), the browser WebSocket API does not expose the specific HTTP
|
|
194
|
+
* status code or reason - it only reports a generic connection failure. The
|
|
195
|
+
* client automatically retries with exponential backoff and jitter, eventually
|
|
196
|
+
* succeeding once the configuration or server issue is resolved.
|
|
197
|
+
*
|
|
198
|
+
* Legitimate clients will be properly configured with valid credentials, so
|
|
199
|
+
* automatic retry is OK.
|
|
200
|
+
*
|
|
201
|
+
* @see {@link createOwnerWebSocketTransport}
|
|
202
|
+
* @see {@link parseOwnerIdFromOwnerWebSocketTransportUrl}
|
|
203
|
+
*/
|
|
204
|
+
export interface OwnerWebSocketTransport {
|
|
205
|
+
readonly type: "WebSocket";
|
|
206
|
+
readonly url: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Creates an {@link OwnerWebSocketTransport} for the given relay URL and
|
|
210
|
+
* {@link OwnerId}.
|
|
211
|
+
*
|
|
212
|
+
* ### Example
|
|
213
|
+
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* const transport = createOwnerWebSocketTransport({
|
|
216
|
+
* url: "wss://relay.evolu.dev",
|
|
217
|
+
* ownerId: owner.id,
|
|
218
|
+
* });
|
|
219
|
+
* // Result: { type: "WebSocket", url: "wss://relay.evolu.dev?ownerId=..." }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export declare const createOwnerWebSocketTransport: (config: {
|
|
223
|
+
readonly url: string;
|
|
224
|
+
readonly ownerId: OwnerId;
|
|
225
|
+
}) => OwnerWebSocketTransport;
|
|
226
|
+
/**
|
|
227
|
+
* Extracts {@link OwnerId} from an {@link OwnerWebSocketTransport} URL query
|
|
228
|
+
* string.
|
|
229
|
+
*
|
|
230
|
+
* Parses the query string `?ownerId=...` and validates that the extracted value
|
|
231
|
+
* is a valid {@link OwnerId}.
|
|
232
|
+
*
|
|
233
|
+
* ### Example
|
|
234
|
+
*
|
|
235
|
+
* ```ts
|
|
236
|
+
* parseOwnerIdFromOwnerWebSocketTransportUrl(
|
|
237
|
+
* "/sync?ownerId=_12345678abcdefgh",
|
|
238
|
+
* );
|
|
239
|
+
* // Returns: OwnerId or null
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export declare const parseOwnerIdFromOwnerWebSocketTransportUrl: (url: string) => OwnerId | null;
|
|
243
|
+
/**
|
|
244
|
+
* Usage data for an {@link OwnerId}.
|
|
245
|
+
*
|
|
246
|
+
* Tracks data consumption to monitor usage patterns and enforce quotas if
|
|
247
|
+
* needed. Used by both relays and clients.
|
|
248
|
+
*
|
|
249
|
+
* Relays and clients must handle rate limiting, connection limits, and request
|
|
250
|
+
* throttling separately with in-memory state.
|
|
251
|
+
*/
|
|
252
|
+
export interface OwnerUsage {
|
|
253
|
+
/** The {@link Owner} this usage data belongs to. */
|
|
254
|
+
readonly ownerId: OwnerIdBytes;
|
|
255
|
+
/** Total bytes stored in the database. */
|
|
256
|
+
readonly storedBytes: PositiveInt;
|
|
257
|
+
/** Total bytes received. */
|
|
258
|
+
readonly receivedBytes: number;
|
|
259
|
+
/** Total bytes sent. */
|
|
260
|
+
readonly sentBytes: number;
|
|
261
|
+
/**
|
|
262
|
+
* The minimum {@link Timestamp}.
|
|
263
|
+
*
|
|
264
|
+
* Helps {@link Storage} choose faster algorithms.
|
|
265
|
+
*/
|
|
266
|
+
readonly firstTimestamp: TimestampBytes | null;
|
|
267
|
+
/**
|
|
268
|
+
* The maximum {@link Timestamp}.
|
|
269
|
+
*
|
|
270
|
+
* Helps {@link Storage} choose faster algorithms. Free relays can use it to
|
|
271
|
+
* identify inactive accounts for cleanup or archival.
|
|
272
|
+
*/
|
|
273
|
+
readonly lastTimestamp: TimestampBytes | null;
|
|
274
|
+
}
|
|
245
275
|
//# sourceMappingURL=Owner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Owner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAEL,aAAa,EAGb,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAML,QAAQ,EACR,cAAc,
|
|
1
|
+
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Owner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAEL,aAAa,EAGb,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAML,QAAQ,EACR,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,aAAa,EAAE,kBAAk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AAC,CAAC;CACrD;AAED,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,GACpC,aAAa,WAAW,KACvB,mBAKD,CAAC;AAEH;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAErD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,6BAA6B,GAAI,QAAQ;IACpD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,KAAG,uBAGF,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,0CAA0C,GACrD,KAAK,MAAM,KACV,OAAO,GAAG,IAAyD,CAAC;AAEvE;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAE/B,0CAA0C;IAC1C,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAElC,4BAA4B;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE/B,wBAAwB;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IAE/C;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,cAAc,GAAG,IAAI,CAAC;CAC/C"}
|
package/dist/src/Evolu/Owner.js
CHANGED
|
@@ -3,19 +3,6 @@ import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
|
3
3
|
import { createSlip21, EncryptionKey, Entropy16, Entropy32, } from "../Crypto.js";
|
|
4
4
|
import { brand, Id, IdBytes, idBytesToId, idToIdBytes, } from "../Type.js";
|
|
5
5
|
import { getOrNull } from "../Result.js";
|
|
6
|
-
/**
|
|
7
|
-
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
8
|
-
*
|
|
9
|
-
* Can be created using {@link createOwnerSecret} or converted from a
|
|
10
|
-
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
11
|
-
*/
|
|
12
|
-
export const OwnerSecret = brand("OwnerSecret", Entropy32);
|
|
13
|
-
/** Creates a {@link OwnerSecret}. */
|
|
14
|
-
export const createOwnerSecret = (deps) => deps.randomBytes.create(32);
|
|
15
|
-
/** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
|
|
16
|
-
export const ownerSecretToMnemonic = (secret) => bip39.entropyToMnemonic(secret, wordlist);
|
|
17
|
-
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
18
|
-
export const mnemonicToOwnerSecret = (mnemonic) => bip39.mnemonicToEntropy(mnemonic, wordlist);
|
|
19
6
|
/**
|
|
20
7
|
* OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}.
|
|
21
8
|
* Branded from {@link Id} to leverage existing helpers like {@link idToIdBytes}.
|
|
@@ -32,6 +19,19 @@ export const OwnerEncryptionKey = brand("OwnerEncryptionKey", EncryptionKey);
|
|
|
32
19
|
* default and can be rotated via {@link createOwnerWriteKey}.
|
|
33
20
|
*/
|
|
34
21
|
export const OwnerWriteKey = brand("OwnerWriteKey", Entropy16);
|
|
22
|
+
/**
|
|
23
|
+
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
24
|
+
*
|
|
25
|
+
* Can be created using {@link createOwnerSecret} or converted from a
|
|
26
|
+
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
27
|
+
*/
|
|
28
|
+
export const OwnerSecret = brand("OwnerSecret", Entropy32);
|
|
29
|
+
/** Creates a {@link OwnerSecret}. */
|
|
30
|
+
export const createOwnerSecret = (deps) => deps.randomBytes.create(32);
|
|
31
|
+
/** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
|
|
32
|
+
export const ownerSecretToMnemonic = (secret) => bip39.entropyToMnemonic(secret, wordlist);
|
|
33
|
+
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
34
|
+
export const mnemonicToOwnerSecret = (mnemonic) => bip39.mnemonicToEntropy(mnemonic, wordlist);
|
|
35
35
|
/** Creates a randomly generated {@link OwnerWriteKey}. */
|
|
36
36
|
export const createOwnerWriteKey = (deps) => deps.randomBytes.create(16);
|
|
37
37
|
/**
|
|
@@ -56,38 +56,6 @@ export const createAppOwner = (secret) => ({
|
|
|
56
56
|
mnemonic: ownerSecretToMnemonic(secret),
|
|
57
57
|
...createOwner(secret),
|
|
58
58
|
});
|
|
59
|
-
/**
|
|
60
|
-
* Creates a {@link WebSocketTransportConfig} for the given relay URL and
|
|
61
|
-
* {@link OwnerId}.
|
|
62
|
-
*
|
|
63
|
-
* ### Example
|
|
64
|
-
*
|
|
65
|
-
* ```ts
|
|
66
|
-
* const transport = createWebSocketTransportConfig({
|
|
67
|
-
* relayUrl: "wss://relay.evolu.dev",
|
|
68
|
-
* ownerId: owner.id,
|
|
69
|
-
* });
|
|
70
|
-
* // Result: { type: "WebSocket", url: "wss://relay.evolu.dev?ownerId=..." }
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export const createWebSocketTransportConfig = ({ relayUrl, ownerId, }) => ({
|
|
74
|
-
type: "WebSocket",
|
|
75
|
-
url: `${relayUrl}?ownerId=${ownerId}`,
|
|
76
|
-
});
|
|
77
|
-
/**
|
|
78
|
-
* Extracts {@link OwnerId} from a URL query string.
|
|
79
|
-
*
|
|
80
|
-
* Parses the query string `?ownerId=...` and validates that the extracted value
|
|
81
|
-
* is a valid {@link OwnerId}.
|
|
82
|
-
*
|
|
83
|
-
* ### Example
|
|
84
|
-
*
|
|
85
|
-
* ```ts
|
|
86
|
-
* parseOwnerIdFromUrl("/sync?ownerId=_12345678abcdefgh");
|
|
87
|
-
* // Returns: OwnerId or null
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
export const parseOwnerIdFromUrl = (url) => getOrNull(OwnerId.fromUnknown(url?.split("=")[1]));
|
|
91
59
|
/** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
|
|
92
60
|
export const createShardOwner = (secret, transports) => {
|
|
93
61
|
return {
|
|
@@ -143,3 +111,38 @@ export const createSharedReadonlyOwner = (sharedOwner) => ({
|
|
|
143
111
|
encryptionKey: sharedOwner.encryptionKey,
|
|
144
112
|
...(sharedOwner.transports && { transports: sharedOwner.transports }),
|
|
145
113
|
});
|
|
114
|
+
/**
|
|
115
|
+
* Creates an {@link OwnerWebSocketTransport} for the given relay URL and
|
|
116
|
+
* {@link OwnerId}.
|
|
117
|
+
*
|
|
118
|
+
* ### Example
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* const transport = createOwnerWebSocketTransport({
|
|
122
|
+
* url: "wss://relay.evolu.dev",
|
|
123
|
+
* ownerId: owner.id,
|
|
124
|
+
* });
|
|
125
|
+
* // Result: { type: "WebSocket", url: "wss://relay.evolu.dev?ownerId=..." }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export const createOwnerWebSocketTransport = (config) => ({
|
|
129
|
+
type: "WebSocket",
|
|
130
|
+
url: `${config.url}?ownerId=${config.ownerId}`,
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* Extracts {@link OwnerId} from an {@link OwnerWebSocketTransport} URL query
|
|
134
|
+
* string.
|
|
135
|
+
*
|
|
136
|
+
* Parses the query string `?ownerId=...` and validates that the extracted value
|
|
137
|
+
* is a valid {@link OwnerId}.
|
|
138
|
+
*
|
|
139
|
+
* ### Example
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* parseOwnerIdFromOwnerWebSocketTransportUrl(
|
|
143
|
+
* "/sync?ownerId=_12345678abcdefgh",
|
|
144
|
+
* );
|
|
145
|
+
* // Returns: OwnerId or null
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export const parseOwnerIdFromOwnerWebSocketTransportUrl = (url) => getOrNull(OwnerId.fromUnknown(url.split("=")[1]));
|