@evolu/common 8.1.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Function.d.ts +1 -0
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Http.d.ts +9 -0
- package/dist/src/Http.d.ts.map +1 -1
- package/dist/src/Number.d.ts +66 -6
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +11 -3
- package/dist/src/Object.d.ts +1 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/RefCount.d.ts +1 -0
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/Relation.d.ts +2 -0
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Resource.d.ts +1 -0
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Result.d.ts +383 -548
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +296 -46
- package/dist/src/Schedule.d.ts +2 -2
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/StackTrace.d.ts +1 -0
- package/dist/src/StackTrace.d.ts.map +1 -1
- package/dist/src/Task.d.ts +978 -1061
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1010 -159
- package/dist/src/Time.d.ts +71 -34
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +77 -1
- package/dist/src/Type.d.ts +1740 -795
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1634 -211
- package/dist/src/Types.d.ts +0 -24
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/intl/_en.d.ts +126 -0
- package/dist/src/intl/_en.d.ts.map +1 -0
- package/dist/src/intl/_en.js +267 -0
- package/dist/src/intl/ar.d.ts +117 -0
- package/dist/src/intl/ar.d.ts.map +1 -0
- package/dist/src/intl/ar.js +245 -0
- package/dist/src/intl/bn.d.ts +117 -0
- package/dist/src/intl/bn.d.ts.map +1 -0
- package/dist/src/intl/bn.js +258 -0
- package/dist/src/intl/ca.d.ts +117 -0
- package/dist/src/intl/ca.d.ts.map +1 -0
- package/dist/src/intl/ca.js +258 -0
- package/dist/src/intl/cs.d.ts +30 -7
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +65 -28
- package/dist/src/intl/da.d.ts +117 -0
- package/dist/src/intl/da.d.ts.map +1 -0
- package/dist/src/intl/da.js +258 -0
- package/dist/src/intl/de.d.ts +117 -0
- package/dist/src/intl/de.d.ts.map +1 -0
- package/dist/src/intl/de.js +258 -0
- package/dist/src/intl/el.d.ts +117 -0
- package/dist/src/intl/el.d.ts.map +1 -0
- package/dist/src/intl/el.js +265 -0
- package/dist/src/intl/es.d.ts +117 -0
- package/dist/src/intl/es.d.ts.map +1 -0
- package/dist/src/intl/es.js +258 -0
- package/dist/src/intl/fa.d.ts +117 -0
- package/dist/src/intl/fa.d.ts.map +1 -0
- package/dist/src/intl/fa.js +258 -0
- package/dist/src/intl/fi.d.ts +117 -0
- package/dist/src/intl/fi.d.ts.map +1 -0
- package/dist/src/intl/fi.js +258 -0
- package/dist/src/intl/fil.d.ts +117 -0
- package/dist/src/intl/fil.d.ts.map +1 -0
- package/dist/src/intl/fil.js +258 -0
- package/dist/src/intl/fr.d.ts +117 -0
- package/dist/src/intl/fr.d.ts.map +1 -0
- package/dist/src/intl/fr.js +258 -0
- package/dist/src/intl/he.d.ts +117 -0
- package/dist/src/intl/he.d.ts.map +1 -0
- package/dist/src/intl/he.js +258 -0
- package/dist/src/intl/hi.d.ts +117 -0
- package/dist/src/intl/hi.d.ts.map +1 -0
- package/dist/src/intl/hi.js +258 -0
- package/dist/src/intl/hr.d.ts +117 -0
- package/dist/src/intl/hr.d.ts.map +1 -0
- package/dist/src/intl/hr.js +265 -0
- package/dist/src/intl/hu.d.ts +63 -0
- package/dist/src/intl/hu.d.ts.map +1 -0
- package/dist/src/intl/hu.js +204 -0
- package/dist/src/intl/id.d.ts +117 -0
- package/dist/src/intl/id.d.ts.map +1 -0
- package/dist/src/intl/id.js +258 -0
- package/dist/src/intl/index.d.ts +42 -0
- package/dist/src/intl/index.d.ts.map +1 -1
- package/dist/src/intl/index.js +42 -0
- package/dist/src/intl/it.d.ts +117 -0
- package/dist/src/intl/it.d.ts.map +1 -0
- package/dist/src/intl/it.js +258 -0
- package/dist/src/intl/ja.d.ts +117 -0
- package/dist/src/intl/ja.d.ts.map +1 -0
- package/dist/src/intl/ja.js +258 -0
- package/dist/src/intl/ko.d.ts +117 -0
- package/dist/src/intl/ko.d.ts.map +1 -0
- package/dist/src/intl/ko.js +258 -0
- package/dist/src/intl/ml.d.ts +117 -0
- package/dist/src/intl/ml.d.ts.map +1 -0
- package/dist/src/intl/ml.js +258 -0
- package/dist/src/intl/mr.d.ts +117 -0
- package/dist/src/intl/mr.d.ts.map +1 -0
- package/dist/src/intl/mr.js +258 -0
- package/dist/src/intl/ms.d.ts +117 -0
- package/dist/src/intl/ms.d.ts.map +1 -0
- package/dist/src/intl/ms.js +245 -0
- package/dist/src/intl/nb.d.ts +63 -0
- package/dist/src/intl/nb.d.ts.map +1 -0
- package/dist/src/intl/nb.js +191 -0
- package/dist/src/intl/nl.d.ts +117 -0
- package/dist/src/intl/nl.d.ts.map +1 -0
- package/dist/src/intl/nl.js +258 -0
- package/dist/src/intl/pa.d.ts +117 -0
- package/dist/src/intl/pa.d.ts.map +1 -0
- package/dist/src/intl/pa.js +258 -0
- package/dist/src/intl/pl.d.ts +117 -0
- package/dist/src/intl/pl.d.ts.map +1 -0
- package/dist/src/intl/pl.js +242 -0
- package/dist/src/intl/pt-BR.d.ts +117 -0
- package/dist/src/intl/pt-BR.d.ts.map +1 -0
- package/dist/src/intl/pt-BR.js +258 -0
- package/dist/src/intl/pt.d.ts +117 -0
- package/dist/src/intl/pt.d.ts.map +1 -0
- package/dist/src/intl/pt.js +246 -0
- package/dist/src/intl/ro.d.ts +117 -0
- package/dist/src/intl/ro.d.ts.map +1 -0
- package/dist/src/intl/ro.js +258 -0
- package/dist/src/intl/sk.d.ts +117 -0
- package/dist/src/intl/sk.d.ts.map +1 -0
- package/dist/src/intl/sk.js +244 -0
- package/dist/src/intl/sl.d.ts +117 -0
- package/dist/src/intl/sl.d.ts.map +1 -0
- package/dist/src/intl/sl.js +258 -0
- package/dist/src/intl/sv.d.ts +117 -0
- package/dist/src/intl/sv.d.ts.map +1 -0
- package/dist/src/intl/sv.js +258 -0
- package/dist/src/intl/sw.d.ts +63 -0
- package/dist/src/intl/sw.d.ts.map +1 -0
- package/dist/src/intl/sw.js +191 -0
- package/dist/src/intl/ta.d.ts +117 -0
- package/dist/src/intl/ta.d.ts.map +1 -0
- package/dist/src/intl/ta.js +258 -0
- package/dist/src/intl/te.d.ts +117 -0
- package/dist/src/intl/te.d.ts.map +1 -0
- package/dist/src/intl/te.js +258 -0
- package/dist/src/intl/th.d.ts +117 -0
- package/dist/src/intl/th.d.ts.map +1 -0
- package/dist/src/intl/th.js +258 -0
- package/dist/src/intl/tr.d.ts +117 -0
- package/dist/src/intl/tr.d.ts.map +1 -0
- package/dist/src/intl/tr.js +255 -0
- package/dist/src/intl/uk.d.ts +117 -0
- package/dist/src/intl/uk.d.ts.map +1 -0
- package/dist/src/intl/uk.js +258 -0
- package/dist/src/intl/ur.d.ts +117 -0
- package/dist/src/intl/ur.d.ts.map +1 -0
- package/dist/src/intl/ur.js +245 -0
- package/dist/src/intl/vi.d.ts +117 -0
- package/dist/src/intl/vi.d.ts.map +1 -0
- package/dist/src/intl/vi.js +255 -0
- package/dist/src/intl/zh-CN.d.ts +117 -0
- package/dist/src/intl/zh-CN.d.ts.map +1 -0
- package/dist/src/intl/zh-CN.js +258 -0
- package/dist/src/intl/zh-TW.d.ts +117 -0
- package/dist/src/intl/zh-TW.d.ts.map +1 -0
- package/dist/src/intl/zh-TW.js +258 -0
- package/dist/src/local-first/Owner.d.ts +156 -62
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +119 -20
- package/package.json +1 -1
- package/src/Function.ts +2 -0
- package/src/Http.ts +9 -0
- package/src/Number.ts +85 -14
- package/src/Object.ts +2 -0
- package/src/RefCount.ts +2 -0
- package/src/Relation.ts +4 -0
- package/src/Resource.ts +2 -0
- package/src/Result.ts +397 -560
- package/src/Schedule.ts +1 -1
- package/src/StackTrace.ts +2 -0
- package/src/Task.ts +1145 -1225
- package/src/Time.ts +110 -62
- package/src/Type.ts +2842 -835
- package/src/Types.ts +0 -49
- package/src/intl/_en.ts +497 -0
- package/src/intl/ar.ts +417 -0
- package/src/intl/bn.ts +486 -0
- package/src/intl/ca.ts +488 -0
- package/src/intl/cs.ts +131 -32
- package/src/intl/da.ts +488 -0
- package/src/intl/de.ts +488 -0
- package/src/intl/el.ts +494 -0
- package/src/intl/es.ts +488 -0
- package/src/intl/fa.ts +487 -0
- package/src/intl/fi.ts +487 -0
- package/src/intl/fil.ts +488 -0
- package/src/intl/fr.ts +488 -0
- package/src/intl/he.ts +486 -0
- package/src/intl/hi.ts +487 -0
- package/src/intl/hr.ts +494 -0
- package/src/intl/hu.ts +387 -0
- package/src/intl/id.ts +487 -0
- package/src/intl/index.ts +42 -0
- package/src/intl/it.ts +488 -0
- package/src/intl/ja.ts +488 -0
- package/src/intl/ko.ts +487 -0
- package/src/intl/ml.ts +487 -0
- package/src/intl/mr.ts +487 -0
- package/src/intl/ms.ts +410 -0
- package/src/intl/nb.ts +364 -0
- package/src/intl/nl.ts +488 -0
- package/src/intl/pa.ts +487 -0
- package/src/intl/pl.ts +450 -0
- package/src/intl/pt-BR.ts +487 -0
- package/src/intl/pt.ts +424 -0
- package/src/intl/ro.ts +488 -0
- package/src/intl/sk.ts +412 -0
- package/src/intl/sl.ts +487 -0
- package/src/intl/sv.ts +488 -0
- package/src/intl/sw.ts +324 -0
- package/src/intl/ta.ts +487 -0
- package/src/intl/te.ts +487 -0
- package/src/intl/th.ts +484 -0
- package/src/intl/tr.ts +487 -0
- package/src/intl/uk.ts +488 -0
- package/src/intl/ur.ts +410 -0
- package/src/intl/vi.ts +435 -0
- package/src/intl/zh-CN.ts +482 -0
- package/src/intl/zh-TW.ts +482 -0
- package/src/local-first/Owner.ts +156 -62
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* ## Intro
|
|
3
|
+
*
|
|
4
|
+
* Cryptographic identities that define ownership, encryption, sync, and
|
|
5
|
+
* deletion boundaries for Evolu data.
|
|
6
|
+
*
|
|
7
|
+
* Every database change belongs to an {@link Owner} and is encrypted with its
|
|
8
|
+
* {@link OwnerEncryptionKey}. Owners also make sync selective: only the
|
|
9
|
+
* {@link AppOwner} is synced by default, while other owners can be synced when
|
|
10
|
+
* needed.
|
|
11
|
+
*
|
|
12
|
+
* Individual changes in an append-only local-first history can only be marked
|
|
13
|
+
* as deleted. An entire owner, however, can be removed from devices and relays
|
|
14
|
+
* together with all of its data. The AppOwner must remain because it coordinates
|
|
15
|
+
* the deletion of other owners across devices.
|
|
16
|
+
*
|
|
17
|
+
* Choose an owner by how its data should live and be shared:
|
|
18
|
+
*
|
|
19
|
+
* - {@link AppOwner} coordinates sync and persists for the lifetime of the app
|
|
20
|
+
* identity.
|
|
21
|
+
* - {@link ShardOwner} partitions application data so it can be synced and
|
|
22
|
+
* deleted independently.
|
|
23
|
+
* - {@link SharedOwner} grants collaborative read and write access.
|
|
24
|
+
* - {@link SharedReadonlyOwner} grants read-only access to shared data.
|
|
25
|
+
*
|
|
26
|
+
* An {@link OwnerSecret} deterministically derives three independent values
|
|
27
|
+
* using SLIP-21:
|
|
28
|
+
*
|
|
29
|
+
* - {@link OwnerId}: the public identifier.
|
|
30
|
+
* - {@link OwnerEncryptionKey}: the symmetric key that protects the data.
|
|
31
|
+
* - {@link OwnerWriteKey}: the rotatable token that authorizes writes.
|
|
3
32
|
*
|
|
4
33
|
* @module
|
|
5
34
|
*/
|
|
@@ -11,6 +40,7 @@ import { TimestampBytes } from "./Timestamp.ts";
|
|
|
11
40
|
* {@link Owner} without a {@link OwnerWriteKey}.
|
|
12
41
|
*
|
|
13
42
|
* @see {@link createSharedReadonlyOwner}
|
|
43
|
+
* @group Core
|
|
14
44
|
*/
|
|
15
45
|
export interface ReadonlyOwner {
|
|
16
46
|
readonly id: OwnerId;
|
|
@@ -18,35 +48,11 @@ export interface ReadonlyOwner {
|
|
|
18
48
|
readonly encryptionKey: OwnerEncryptionKey;
|
|
19
49
|
}
|
|
20
50
|
/**
|
|
21
|
-
*
|
|
22
|
-
* assigned to an owner and encrypted with its {@link OwnerEncryptionKey}. Owners
|
|
23
|
-
* allow partial sync, only the {@link AppOwner} is synced by default.
|
|
24
|
-
*
|
|
25
|
-
* Owners can also provide real data deletion, while individual changes in
|
|
26
|
-
* local-first/distributed systems can only be soft deleted, entire owners can
|
|
27
|
-
* be completely deleted from both relays and devices (except for
|
|
28
|
-
* {@link AppOwner}, which must be preserved for sync coordination).
|
|
29
|
-
*
|
|
30
|
-
* Evolu provides different owner types depending on their use case:
|
|
31
|
-
*
|
|
32
|
-
* - **Coordination**: {@link AppOwner} for sync coordination and long-term
|
|
33
|
-
* persistence
|
|
34
|
-
* - **Data partitioning**: {@link ShardOwner} for partitioning application data
|
|
35
|
-
* - **Collaboration**: {@link SharedOwner} for collaborative write access
|
|
36
|
-
* - **Data sharing**: {@link SharedReadonlyOwner} for read-only access to shared
|
|
37
|
-
* data
|
|
51
|
+
* An {@link ReadonlyOwner} with an {@link OwnerWriteKey} for authorizing writes.
|
|
38
52
|
*
|
|
39
|
-
*
|
|
40
|
-
* SLIP-21, ensuring secure and deterministic key generation:
|
|
53
|
+
* See the {@link @evolu/common!"local-first/Owner" | Owners overview}.
|
|
41
54
|
*
|
|
42
|
-
*
|
|
43
|
-
* - {@link OwnerEncryptionKey}: Symmetric encryption key for data protection
|
|
44
|
-
* - {@link OwnerWriteKey}: Authentication token for write operations (rotatable)
|
|
45
|
-
*
|
|
46
|
-
* @see {@link createAppOwner}
|
|
47
|
-
* @see {@link createShardOwner}
|
|
48
|
-
* @see {@link createSharedOwner}
|
|
49
|
-
* @see {@link createSharedReadonlyOwner}
|
|
55
|
+
* @group Core
|
|
50
56
|
*/
|
|
51
57
|
export interface Owner extends ReadonlyOwner {
|
|
52
58
|
/** TODO: Wrap with `Redacted` in the next major version. */
|
|
@@ -55,37 +61,67 @@ export interface Owner extends ReadonlyOwner {
|
|
|
55
61
|
/**
|
|
56
62
|
* An {@link ReadonlyOwner} or {@link Owner} with non-empty {@link OwnerTransport}s
|
|
57
63
|
* so it can be synced.
|
|
64
|
+
*
|
|
65
|
+
* @group Transport
|
|
58
66
|
*/
|
|
59
67
|
export interface SyncOwner {
|
|
60
68
|
readonly owner: ReadonlyOwner | Owner;
|
|
61
69
|
readonly transports: NonEmptyReadonlyArray<OwnerTransport>;
|
|
62
70
|
}
|
|
63
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* A branded {@link Id} that uniquely identifies an {@link Owner}.
|
|
73
|
+
*
|
|
74
|
+
* @group Core
|
|
75
|
+
*/
|
|
64
76
|
export declare const OwnerId: import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").Type<"String", string, string, import("../Type.ts").TypeOfError<"String">, null, import("../Type.ts").TypeOfError<"String">, never, string, true>, "Id", import("../Type.ts").IdError>, "OwnerId", never>;
|
|
65
77
|
export type OwnerId = typeof OwnerId.Output;
|
|
66
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Binary representation of {@link OwnerId}.
|
|
80
|
+
*
|
|
81
|
+
* @group Core
|
|
82
|
+
*/
|
|
67
83
|
export declare const OwnerIdBytes: import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.ts").ObjectTagError<"Uint8Array">, null, import("../Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Length16", import("../Type.ts").LengthError<16>>, "IdBytes", never>, "OwnerIdBytes", never>;
|
|
68
84
|
export type OwnerIdBytes = typeof OwnerIdBytes.Output;
|
|
69
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Converts {@link OwnerId} to {@link OwnerIdBytes}.
|
|
87
|
+
*
|
|
88
|
+
* @group Core
|
|
89
|
+
*/
|
|
70
90
|
export declare const ownerIdToOwnerIdBytes: (ownerId: OwnerId) => OwnerIdBytes;
|
|
71
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Converts {@link OwnerIdBytes} to {@link OwnerId}.
|
|
93
|
+
*
|
|
94
|
+
* @group Core
|
|
95
|
+
*/
|
|
72
96
|
export declare const ownerIdBytesToOwnerId: (ownerIdBytes: OwnerIdBytes) => OwnerId;
|
|
97
|
+
/**
|
|
98
|
+
* Length of an {@link OwnerWriteKey} in bytes.
|
|
99
|
+
*
|
|
100
|
+
* @group Core
|
|
101
|
+
*/
|
|
73
102
|
export declare const ownerWriteKeyLength: number & import("../Brand.ts").Brand<"NonNaN"> & import("../Brand.ts").Brand<"Finite"> & import("../Brand.ts").Brand<"Int"> & import("../Brand.ts").Brand<"NonNegative">;
|
|
74
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Symmetric encryption key for {@link Owner} data protection.
|
|
105
|
+
*
|
|
106
|
+
* @group Core
|
|
107
|
+
*/
|
|
75
108
|
export declare const OwnerEncryptionKey: import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.ts").ObjectTagError<"Uint8Array">, null, import("../Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length32", import("../Type.ts").LengthError<32>>, "EncryptionKey", never>, "OwnerEncryptionKey", never>;
|
|
76
109
|
export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Output;
|
|
77
110
|
/**
|
|
78
|
-
* A
|
|
79
|
-
*
|
|
111
|
+
* A token that authorizes write operations for an {@link Owner}.
|
|
112
|
+
*
|
|
113
|
+
* The initial key is derived from {@link OwnerSecret}. Replace it with a random
|
|
114
|
+
* key from {@link createOwnerWriteKey} to rotate write access without changing
|
|
115
|
+
* the owner identity or encryption key.
|
|
116
|
+
*
|
|
117
|
+
* @group Core
|
|
80
118
|
*/
|
|
81
119
|
export declare const OwnerWriteKey: import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.ts").ObjectTagError<"Uint8Array">, null, import("../Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length16", import("../Type.ts").LengthError<16>>, "OwnerWriteKey", never>;
|
|
82
120
|
export type OwnerWriteKey = typeof OwnerWriteKey.Output;
|
|
83
121
|
/**
|
|
84
|
-
* Creates a
|
|
122
|
+
* Creates a random {@link OwnerWriteKey} for rotating write access.
|
|
85
123
|
*
|
|
86
|
-
*
|
|
87
|
-
* {@link OwnerSecret}. Use `createOwnerWriteKey` to rotate (replace) the write
|
|
88
|
-
* key without changing the owner identity.
|
|
124
|
+
* @group Core
|
|
89
125
|
*/
|
|
90
126
|
export declare const createOwnerWriteKey: (deps: RandomBytesDep) => OwnerWriteKey;
|
|
91
127
|
/**
|
|
@@ -93,16 +129,34 @@ export declare const createOwnerWriteKey: (deps: RandomBytesDep) => OwnerWriteKe
|
|
|
93
129
|
*
|
|
94
130
|
* Can be created using {@link createOwnerSecret} or converted from a
|
|
95
131
|
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
132
|
+
*
|
|
133
|
+
* @group Core
|
|
96
134
|
*/
|
|
97
135
|
export declare const OwnerSecret: import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").BrandType<import("../Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.ts").ObjectTagError<"Uint8Array">, null, import("../Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length32", import("../Type.ts").LengthError<32>>, "OwnerSecret", never>;
|
|
98
136
|
export type OwnerSecret = typeof OwnerSecret.Output;
|
|
99
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Creates a cryptographically random {@link OwnerSecret}.
|
|
139
|
+
*
|
|
140
|
+
* @group Core
|
|
141
|
+
*/
|
|
100
142
|
export declare const createOwnerSecret: (deps: RandomBytesDep) => OwnerSecret;
|
|
101
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Deterministic {@link OwnerSecret} for tests.
|
|
145
|
+
*
|
|
146
|
+
* @group Testing
|
|
147
|
+
*/
|
|
102
148
|
export declare const testOwnerSecret: Uint8Array<ArrayBufferLike> & import("../Brand.ts").Brand<"Entropy"> & import("../Brand.ts").Brand<"Length32"> & import("../Brand.ts").Brand<"OwnerSecret">;
|
|
103
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Converts an {@link OwnerSecret} to a {@link Mnemonic}.
|
|
151
|
+
*
|
|
152
|
+
* @group Core
|
|
153
|
+
*/
|
|
104
154
|
export declare const ownerSecretToMnemonic: (secret: OwnerSecret) => Mnemonic;
|
|
105
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Converts a {@link Mnemonic} to an {@link OwnerSecret}.
|
|
157
|
+
*
|
|
158
|
+
* @group Core
|
|
159
|
+
*/
|
|
106
160
|
export declare const mnemonicToOwnerSecret: (mnemonic: Mnemonic) => OwnerSecret;
|
|
107
161
|
/**
|
|
108
162
|
* The AppOwner represents the application owner. It's created using a
|
|
@@ -135,6 +189,8 @@ export declare const mnemonicToOwnerSecret: (mnemonic: Mnemonic) => OwnerSecret;
|
|
|
135
189
|
* For data sharing scenarios, use {@link SharedOwner} and
|
|
136
190
|
* {@link SharedReadonlyOwner} to make intent explicit and distinguish
|
|
137
191
|
* collaborative usage from {@link AppOwner} coordination.
|
|
192
|
+
*
|
|
193
|
+
* @group Variants
|
|
138
194
|
*/
|
|
139
195
|
export interface AppOwner extends Owner, Typed<"AppOwner"> {
|
|
140
196
|
/**
|
|
@@ -146,9 +202,17 @@ export interface AppOwner extends Owner, Typed<"AppOwner"> {
|
|
|
146
202
|
*/
|
|
147
203
|
readonly mnemonic: Mnemonic;
|
|
148
204
|
}
|
|
149
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Creates an {@link AppOwner} from an {@link OwnerSecret}.
|
|
207
|
+
*
|
|
208
|
+
* @group Variants
|
|
209
|
+
*/
|
|
150
210
|
export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
|
|
151
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* Deterministic {@link AppOwner} for tests.
|
|
213
|
+
*
|
|
214
|
+
* @group Testing
|
|
215
|
+
*/
|
|
152
216
|
export declare const testAppOwner: AppOwner;
|
|
153
217
|
/**
|
|
154
218
|
* An {@link Owner} for sharding data.
|
|
@@ -160,10 +224,16 @@ export declare const testAppOwner: AppOwner;
|
|
|
160
224
|
* Can be created from {@link OwnerSecret} via {@link createShardOwner} or
|
|
161
225
|
* deterministically derived from {@link AppOwner} using
|
|
162
226
|
* {@link deriveShardOwner}.
|
|
227
|
+
*
|
|
228
|
+
* @group Variants
|
|
163
229
|
*/
|
|
164
230
|
export interface ShardOwner extends Owner, Typed<"ShardOwner"> {
|
|
165
231
|
}
|
|
166
|
-
/**
|
|
232
|
+
/**
|
|
233
|
+
* Creates a {@link ShardOwner} from an {@link OwnerSecret}.
|
|
234
|
+
*
|
|
235
|
+
* @group Variants
|
|
236
|
+
*/
|
|
167
237
|
export declare const createShardOwner: (secret: OwnerSecret) => ShardOwner;
|
|
168
238
|
/**
|
|
169
239
|
* Derives a {@link ShardOwner} from an {@link AppOwner} using the specified path.
|
|
@@ -182,9 +252,15 @@ export declare const createShardOwner: (secret: OwnerSecret) => ShardOwner;
|
|
|
182
252
|
* - Use paths like `["shard", 1]` for versioned data lifecycle
|
|
183
253
|
* - Use paths like `["project", "MyApp", 1]` for named partitions with versions
|
|
184
254
|
* - Each device can derive the same owners and set up initial structure
|
|
255
|
+
*
|
|
256
|
+
* @group Variants
|
|
185
257
|
*/
|
|
186
258
|
export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number>) => ShardOwner;
|
|
187
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* An {@link Owner} for collaborative data with write access.
|
|
261
|
+
*
|
|
262
|
+
* @group Variants
|
|
263
|
+
*/
|
|
188
264
|
export interface SharedOwner extends Owner, Typed<"SharedOwner"> {
|
|
189
265
|
}
|
|
190
266
|
/**
|
|
@@ -193,21 +269,31 @@ export interface SharedOwner extends Owner, Typed<"SharedOwner"> {
|
|
|
193
269
|
*
|
|
194
270
|
* Use {@link createSharedReadonlyOwner} to create a read-only version for
|
|
195
271
|
* sharing.
|
|
272
|
+
*
|
|
273
|
+
* @group Variants
|
|
196
274
|
*/
|
|
197
275
|
export declare const createSharedOwner: (secret: OwnerSecret) => SharedOwner;
|
|
198
276
|
/**
|
|
199
277
|
* Read-only version of a {@link SharedOwner} for data sharing. Contains only the
|
|
200
278
|
* {@link OwnerId} and {@link EncryptionKey} needed for others to read the shared
|
|
201
279
|
* data without write access.
|
|
280
|
+
*
|
|
281
|
+
* @group Variants
|
|
202
282
|
*/
|
|
203
283
|
export interface SharedReadonlyOwner extends ReadonlyOwner, Typed<"SharedReadonlyOwner"> {
|
|
204
284
|
}
|
|
205
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
* Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}.
|
|
287
|
+
*
|
|
288
|
+
* @group Variants
|
|
289
|
+
*/
|
|
206
290
|
export declare const createSharedReadonlyOwner: (sharedOwner: SharedOwner) => SharedReadonlyOwner;
|
|
207
291
|
/**
|
|
208
292
|
* Transport configuration for connecting to relays.
|
|
209
293
|
*
|
|
210
294
|
* Currently only WebSocket, in the future Bluetooth, LocalNetwork, etc.
|
|
295
|
+
*
|
|
296
|
+
* @group Transport
|
|
211
297
|
*/
|
|
212
298
|
export type OwnerTransport = OwnerWebSocketTransport;
|
|
213
299
|
/**
|
|
@@ -236,6 +322,7 @@ export type OwnerTransport = OwnerWebSocketTransport;
|
|
|
236
322
|
*
|
|
237
323
|
* @see {@link createOwnerWebSocketTransport}
|
|
238
324
|
* @see {@link parseOwnerIdFromOwnerWebSocketTransportUrl}
|
|
325
|
+
* @group Transport
|
|
239
326
|
*/
|
|
240
327
|
export interface OwnerWebSocketTransport extends Typed<"WebSocket"> {
|
|
241
328
|
readonly url: string;
|
|
@@ -284,6 +371,8 @@ export interface OwnerWebSocketTransport extends Typed<"WebSocket"> {
|
|
|
284
371
|
* url: `wss://relay.evolu.dev?ownerId=${appOwner.id}`,
|
|
285
372
|
* });
|
|
286
373
|
* ```
|
|
374
|
+
*
|
|
375
|
+
* @group Transport
|
|
287
376
|
*/
|
|
288
377
|
export declare const createOwnerWebSocketTransport: (config: {
|
|
289
378
|
readonly url: string;
|
|
@@ -319,37 +408,40 @@ export declare const createOwnerWebSocketTransport: (config: {
|
|
|
319
408
|
* parseOwnerIdFromOwnerWebSocketTransportUrl("/sync?ownerId=invalid"),
|
|
320
409
|
* ).toBeNull();
|
|
321
410
|
* ```
|
|
411
|
+
*
|
|
412
|
+
* @group Transport
|
|
322
413
|
*/
|
|
323
414
|
export declare const parseOwnerIdFromOwnerWebSocketTransportUrl: (url: string) => OwnerId | null;
|
|
324
|
-
/**
|
|
415
|
+
/**
|
|
416
|
+
* Common interface implemented by all owner domain errors.
|
|
417
|
+
*
|
|
418
|
+
* @group Core
|
|
419
|
+
*/
|
|
325
420
|
export interface OwnerError {
|
|
326
421
|
readonly ownerId: OwnerId;
|
|
327
422
|
}
|
|
328
423
|
/**
|
|
329
|
-
*
|
|
424
|
+
* Storage usage and timestamp bounds for an {@link Owner}.
|
|
330
425
|
*
|
|
331
|
-
*
|
|
426
|
+
* Storage and relay implementations use this metadata for quota enforcement and
|
|
427
|
+
* timestamp insertion strategies.
|
|
332
428
|
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* - Add transferredBytes for billing and monitoring network usage.
|
|
429
|
+
* @group Core
|
|
336
430
|
*/
|
|
337
431
|
export interface OwnerUsage {
|
|
338
|
-
/**
|
|
432
|
+
/** Binary identifier of the {@link Owner} this usage belongs to. */
|
|
339
433
|
readonly ownerId: OwnerIdBytes;
|
|
340
434
|
/**
|
|
341
435
|
* Total logical data bytes stored.
|
|
342
436
|
*
|
|
343
|
-
* Measures
|
|
344
|
-
*
|
|
345
|
-
*
|
|
437
|
+
* Measures only {@link EncryptedDbChange} data and excludes {@link Storage}
|
|
438
|
+
* implementation overhead such as indexes and skip-list columns. This makes
|
|
439
|
+
* the measurement consistent across storage implementations and suitable for:
|
|
346
440
|
*
|
|
347
441
|
* - **Predictable measurement** - same data = same byte count across all
|
|
348
442
|
* instances
|
|
349
|
-
* - **Quota enforcement** -
|
|
350
|
-
*
|
|
351
|
-
* - **Overhead tracking** - actual Storage size can be compared against this to
|
|
352
|
-
* monitor efficiency
|
|
443
|
+
* - **Quota enforcement** - limits independent of storage implementation
|
|
444
|
+
* - **Overhead tracking** - comparison with actual storage size
|
|
353
445
|
*/
|
|
354
446
|
readonly storedBytes: NonNegativeInt;
|
|
355
447
|
/** Tracks the earliest timestamp for timestamp insertion strategies. */
|
|
@@ -390,6 +482,8 @@ export interface OwnerUsage {
|
|
|
390
482
|
*
|
|
391
483
|
* DeviceAppOwner Evolu instance is secure only when its data stays on the
|
|
392
484
|
* device.
|
|
485
|
+
*
|
|
486
|
+
* @group Variants
|
|
393
487
|
*/
|
|
394
488
|
export interface DeviceAppOwner extends AppOwner {
|
|
395
489
|
readonly source: "ExpoSecureStore" | "WebAuthnPrf" | "ElectronSafeStorage";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/local-first/Owner.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/local-first/Owner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAUnD,OAAO,EAML,QAAQ,EACR,cAAc,EACd,KAAK,KAAK,EACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,aAAa,EAAE,kBAAkB,CAAC;CAC5C;AAED;;;;;;GAMG;AACH,MAAM,WAAW,KAAM,SAAQ,aAAa;IAC1C,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;CAC5D;AAED;;;;GAIG;AACH,eAAO,MAAM,OAAO,8RAAqC,CAAC;AAC1D,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,YAAY,obAA+C,CAAC;AACzE,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,MAAM,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,YAAa,OAAO,KAAG,YACnB,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,iBAAkB,YAAY,KAAG,OAC7B,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,0KAA2C,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,kfAG9B,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,MAAM,CAAC;AAElE;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,qbAAkD,CAAC;AAC7E,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,SAAU,cAAc,KAAG,aACb,CAAC;AAE/C;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,mbAAgD,CAAC;AACzE,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC;AAEpD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,SAAU,cAAc,KAAG,WACb,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,eAAe,6JAI1B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,WAAY,WAAW,KAAG,QACL,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,aAAc,QAAQ,KAAG,WACC,CAAC;AAsB7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,QAAS,SAAQ,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC;IACxD;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,WAAY,WAAW,KAAG,QAInD,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,UAAgD,CAAC;AAE1E;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAW,SAAQ,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;CAAG;AAEjE;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,WAAY,WAAW,KAAG,UAGrD,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,gBAAgB,UACpB,QAAQ,QACT,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,KAC3C,UAOF,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,WAAY,SAAQ,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC;CAAG;AAEnE;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,WAAY,WAAW,KAAG,WAGtD,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,mBACf,SAAQ,aAAa,EAAE,KAAK,CAAC,qBAAqB,CAAC;CAAG;AAExD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,gBACvB,WAAW,KACvB,mBAID,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,uBAAwB,SAAQ,KAAK,CAAC,WAAW,CAAC;IACjE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,6BAA6B,WAAY;IACpD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,KAAG,uBAGF,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,0CAA0C,QAChD,MAAM,KACV,OAAO,GAAG,IAAyD,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAE/B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;IAErC,wEAAwE;IACxE,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,EAAE,cAAc,GAAG,IAAI,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,aAAa,GAAG,qBAAqB,CAAC;CAC5E"}
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* ## Intro
|
|
3
|
+
*
|
|
4
|
+
* Cryptographic identities that define ownership, encryption, sync, and
|
|
5
|
+
* deletion boundaries for Evolu data.
|
|
6
|
+
*
|
|
7
|
+
* Every database change belongs to an {@link Owner} and is encrypted with its
|
|
8
|
+
* {@link OwnerEncryptionKey}. Owners also make sync selective: only the
|
|
9
|
+
* {@link AppOwner} is synced by default, while other owners can be synced when
|
|
10
|
+
* needed.
|
|
11
|
+
*
|
|
12
|
+
* Individual changes in an append-only local-first history can only be marked
|
|
13
|
+
* as deleted. An entire owner, however, can be removed from devices and relays
|
|
14
|
+
* together with all of its data. The AppOwner must remain because it coordinates
|
|
15
|
+
* the deletion of other owners across devices.
|
|
16
|
+
*
|
|
17
|
+
* Choose an owner by how its data should live and be shared:
|
|
18
|
+
*
|
|
19
|
+
* - {@link AppOwner} coordinates sync and persists for the lifetime of the app
|
|
20
|
+
* identity.
|
|
21
|
+
* - {@link ShardOwner} partitions application data so it can be synced and
|
|
22
|
+
* deleted independently.
|
|
23
|
+
* - {@link SharedOwner} grants collaborative read and write access.
|
|
24
|
+
* - {@link SharedReadonlyOwner} grants read-only access to shared data.
|
|
25
|
+
*
|
|
26
|
+
* An {@link OwnerSecret} deterministically derives three independent values
|
|
27
|
+
* using SLIP-21:
|
|
28
|
+
*
|
|
29
|
+
* - {@link OwnerId}: the public identifier.
|
|
30
|
+
* - {@link OwnerEncryptionKey}: the symmetric key that protects the data.
|
|
31
|
+
* - {@link OwnerWriteKey}: the rotatable token that authorizes writes.
|
|
3
32
|
*
|
|
4
33
|
* @module
|
|
5
34
|
*/
|
|
@@ -10,28 +39,56 @@ import { testCreateRandomLib } from "../Random.js";
|
|
|
10
39
|
import { getOrNull } from "../Result.js";
|
|
11
40
|
import { brand, Id, IdBytes, idBytesToId, idToIdBytes, Mnemonic, NonNegativeInt, } from "../Type.js";
|
|
12
41
|
import { TimestampBytes } from "./Timestamp.js";
|
|
13
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* A branded {@link Id} that uniquely identifies an {@link Owner}.
|
|
44
|
+
*
|
|
45
|
+
* @group Core
|
|
46
|
+
*/
|
|
14
47
|
export const OwnerId = /*#__PURE__*/ brand("OwnerId", Id);
|
|
15
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Binary representation of {@link OwnerId}.
|
|
50
|
+
*
|
|
51
|
+
* @group Core
|
|
52
|
+
*/
|
|
16
53
|
export const OwnerIdBytes = /*#__PURE__*/ brand("OwnerIdBytes", IdBytes);
|
|
17
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Converts {@link OwnerId} to {@link OwnerIdBytes}.
|
|
56
|
+
*
|
|
57
|
+
* @group Core
|
|
58
|
+
*/
|
|
18
59
|
export const ownerIdToOwnerIdBytes = (ownerId) => idToIdBytes(ownerId);
|
|
19
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Converts {@link OwnerIdBytes} to {@link OwnerId}.
|
|
62
|
+
*
|
|
63
|
+
* @group Core
|
|
64
|
+
*/
|
|
20
65
|
export const ownerIdBytesToOwnerId = (ownerIdBytes) => idBytesToId(ownerIdBytes);
|
|
66
|
+
/**
|
|
67
|
+
* Length of an {@link OwnerWriteKey} in bytes.
|
|
68
|
+
*
|
|
69
|
+
* @group Core
|
|
70
|
+
*/
|
|
21
71
|
export const ownerWriteKeyLength = /*#__PURE__*/ NonNegativeInt.orThrow(16);
|
|
22
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Symmetric encryption key for {@link Owner} data protection.
|
|
74
|
+
*
|
|
75
|
+
* @group Core
|
|
76
|
+
*/
|
|
23
77
|
export const OwnerEncryptionKey = /*#__PURE__*/ brand("OwnerEncryptionKey", EncryptionKey);
|
|
24
78
|
/**
|
|
25
|
-
* A
|
|
26
|
-
*
|
|
79
|
+
* A token that authorizes write operations for an {@link Owner}.
|
|
80
|
+
*
|
|
81
|
+
* The initial key is derived from {@link OwnerSecret}. Replace it with a random
|
|
82
|
+
* key from {@link createOwnerWriteKey} to rotate write access without changing
|
|
83
|
+
* the owner identity or encryption key.
|
|
84
|
+
*
|
|
85
|
+
* @group Core
|
|
27
86
|
*/
|
|
28
87
|
export const OwnerWriteKey = /*#__PURE__*/ brand("OwnerWriteKey", Entropy16);
|
|
29
88
|
/**
|
|
30
|
-
* Creates a
|
|
89
|
+
* Creates a random {@link OwnerWriteKey} for rotating write access.
|
|
31
90
|
*
|
|
32
|
-
*
|
|
33
|
-
* {@link OwnerSecret}. Use `createOwnerWriteKey` to rotate (replace) the write
|
|
34
|
-
* key without changing the owner identity.
|
|
91
|
+
* @group Core
|
|
35
92
|
*/
|
|
36
93
|
export const createOwnerWriteKey = (deps) => deps.randomBytes.create(16);
|
|
37
94
|
/**
|
|
@@ -39,19 +96,37 @@ export const createOwnerWriteKey = (deps) => deps.randomBytes.create(16);
|
|
|
39
96
|
*
|
|
40
97
|
* Can be created using {@link createOwnerSecret} or converted from a
|
|
41
98
|
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
99
|
+
*
|
|
100
|
+
* @group Core
|
|
42
101
|
*/
|
|
43
102
|
export const OwnerSecret = /*#__PURE__*/ brand("OwnerSecret", Entropy32);
|
|
44
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Creates a cryptographically random {@link OwnerSecret}.
|
|
105
|
+
*
|
|
106
|
+
* @group Core
|
|
107
|
+
*/
|
|
45
108
|
export const createOwnerSecret = (deps) => deps.randomBytes.create(32);
|
|
46
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Deterministic {@link OwnerSecret} for tests.
|
|
111
|
+
*
|
|
112
|
+
* @group Testing
|
|
113
|
+
*/
|
|
47
114
|
export const testOwnerSecret = /*#__PURE__*/ createOwnerSecret({
|
|
48
115
|
randomBytes: /*#__PURE__*/ testCreateRandomBytes({
|
|
49
116
|
randomLib: /*#__PURE__*/ testCreateRandomLib(),
|
|
50
117
|
}),
|
|
51
118
|
});
|
|
52
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Converts an {@link OwnerSecret} to a {@link Mnemonic}.
|
|
121
|
+
*
|
|
122
|
+
* @group Core
|
|
123
|
+
*/
|
|
53
124
|
export const ownerSecretToMnemonic = (secret) => bip39.entropyToMnemonic(secret, wordlist);
|
|
54
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* Converts a {@link Mnemonic} to an {@link OwnerSecret}.
|
|
127
|
+
*
|
|
128
|
+
* @group Core
|
|
129
|
+
*/
|
|
55
130
|
export const mnemonicToOwnerSecret = (mnemonic) => bip39.mnemonicToEntropy(mnemonic, wordlist);
|
|
56
131
|
/**
|
|
57
132
|
* Creates an {@link Owner} from a {@link OwnerSecret} using SLIP-21 key
|
|
@@ -62,15 +137,27 @@ const createOwner = (secret) => ({
|
|
|
62
137
|
encryptionKey: OwnerEncryptionKey.orThrow(createSlip21(secret, ["Evolu", "OwnerEncryptionKey"])),
|
|
63
138
|
writeKey: OwnerWriteKey.orThrow(createSlip21(secret, ["Evolu", "OwnerWriteKey"]).slice(0, 16)),
|
|
64
139
|
});
|
|
65
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Creates an {@link AppOwner} from an {@link OwnerSecret}.
|
|
142
|
+
*
|
|
143
|
+
* @group Variants
|
|
144
|
+
*/
|
|
66
145
|
export const createAppOwner = (secret) => ({
|
|
67
146
|
...createOwner(secret),
|
|
68
147
|
type: "AppOwner",
|
|
69
148
|
mnemonic: ownerSecretToMnemonic(secret),
|
|
70
149
|
});
|
|
71
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Deterministic {@link AppOwner} for tests.
|
|
152
|
+
*
|
|
153
|
+
* @group Testing
|
|
154
|
+
*/
|
|
72
155
|
export const testAppOwner = /*#__PURE__*/ createAppOwner(testOwnerSecret);
|
|
73
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* Creates a {@link ShardOwner} from an {@link OwnerSecret}.
|
|
158
|
+
*
|
|
159
|
+
* @group Variants
|
|
160
|
+
*/
|
|
74
161
|
export const createShardOwner = (secret) => ({
|
|
75
162
|
...createOwner(secret),
|
|
76
163
|
type: "ShardOwner",
|
|
@@ -92,6 +179,8 @@ export const createShardOwner = (secret) => ({
|
|
|
92
179
|
* - Use paths like `["shard", 1]` for versioned data lifecycle
|
|
93
180
|
* - Use paths like `["project", "MyApp", 1]` for named partitions with versions
|
|
94
181
|
* - Each device can derive the same owners and set up initial structure
|
|
182
|
+
*
|
|
183
|
+
* @group Variants
|
|
95
184
|
*/
|
|
96
185
|
export const deriveShardOwner = (owner, path) => {
|
|
97
186
|
const secret = createSlip21(owner.encryptionKey, path);
|
|
@@ -106,12 +195,18 @@ export const deriveShardOwner = (owner, path) => {
|
|
|
106
195
|
*
|
|
107
196
|
* Use {@link createSharedReadonlyOwner} to create a read-only version for
|
|
108
197
|
* sharing.
|
|
198
|
+
*
|
|
199
|
+
* @group Variants
|
|
109
200
|
*/
|
|
110
201
|
export const createSharedOwner = (secret) => ({
|
|
111
202
|
...createOwner(secret),
|
|
112
203
|
type: "SharedOwner",
|
|
113
204
|
});
|
|
114
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}.
|
|
207
|
+
*
|
|
208
|
+
* @group Variants
|
|
209
|
+
*/
|
|
115
210
|
export const createSharedReadonlyOwner = (sharedOwner) => ({
|
|
116
211
|
type: "SharedReadonlyOwner",
|
|
117
212
|
id: sharedOwner.id,
|
|
@@ -161,6 +256,8 @@ export const createSharedReadonlyOwner = (sharedOwner) => ({
|
|
|
161
256
|
* url: `wss://relay.evolu.dev?ownerId=${appOwner.id}`,
|
|
162
257
|
* });
|
|
163
258
|
* ```
|
|
259
|
+
*
|
|
260
|
+
* @group Transport
|
|
164
261
|
*/
|
|
165
262
|
export const createOwnerWebSocketTransport = (config) => ({
|
|
166
263
|
type: "WebSocket",
|
|
@@ -196,5 +293,7 @@ export const createOwnerWebSocketTransport = (config) => ({
|
|
|
196
293
|
* parseOwnerIdFromOwnerWebSocketTransportUrl("/sync?ownerId=invalid"),
|
|
197
294
|
* ).toBeNull();
|
|
198
295
|
* ```
|
|
296
|
+
*
|
|
297
|
+
* @group Transport
|
|
199
298
|
*/
|
|
200
299
|
export const parseOwnerIdFromOwnerWebSocketTransportUrl = (url) => getOrNull(OwnerId.fromUnknown(url.split("=")[1]));
|
package/package.json
CHANGED
package/src/Function.ts
CHANGED
|
@@ -162,6 +162,8 @@ export function disposable<T extends object>(
|
|
|
162
162
|
value: T extends Disposable ? Omit<T, typeof Symbol.dispose> : T,
|
|
163
163
|
disposer?: DisposableStack,
|
|
164
164
|
): T extends Disposable ? T : T & Disposable;
|
|
165
|
+
|
|
166
|
+
/** Creates an asynchronously disposable object. */
|
|
165
167
|
export function disposable<T extends object>(
|
|
166
168
|
value: T extends AsyncDisposable ? Omit<T, typeof Symbol.asyncDispose> : T,
|
|
167
169
|
disposer: AsyncDisposableStack,
|
package/src/Http.ts
CHANGED
|
@@ -377,24 +377,33 @@ export function fetch(
|
|
|
377
377
|
init?: Omit<RequestInit, "signal">,
|
|
378
378
|
): Task<string, FetchError>;
|
|
379
379
|
|
|
380
|
+
/** Fetches a resource and parses a successful response body as JSON. */
|
|
380
381
|
export function fetch(
|
|
381
382
|
input: RequestInfo | URL,
|
|
382
383
|
mode: "json",
|
|
383
384
|
init?: Omit<RequestInit, "signal">,
|
|
384
385
|
): Task<unknown, FetchError>;
|
|
385
386
|
|
|
387
|
+
/** Fetches a resource and reads a successful response body as bytes. */
|
|
386
388
|
export function fetch(
|
|
387
389
|
input: RequestInfo | URL,
|
|
388
390
|
mode: "bytes",
|
|
389
391
|
init?: Omit<RequestInit, "signal">,
|
|
390
392
|
): Task<Uint8Array<ArrayBuffer>, FetchError>;
|
|
391
393
|
|
|
394
|
+
/**
|
|
395
|
+
* Fetches a resource and returns its body-free response metadata.
|
|
396
|
+
*
|
|
397
|
+
* HTTP status is returned as data rather than interpreted as success or
|
|
398
|
+
* failure.
|
|
399
|
+
*/
|
|
392
400
|
export function fetch(
|
|
393
401
|
input: RequestInfo | URL,
|
|
394
402
|
mode: "headers",
|
|
395
403
|
init?: Omit<RequestInit, "signal">,
|
|
396
404
|
): Task<FetchResponse, FetchTransportError>;
|
|
397
405
|
|
|
406
|
+
/** Fetches a resource and consumes its response with a custom callback. */
|
|
398
407
|
export function fetch<T, E = never>(
|
|
399
408
|
input: RequestInfo | URL,
|
|
400
409
|
consume: FetchConsume<T, E>,
|