@evolu/common 7.4.0 → 8.0.0-next.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.
Files changed (251) hide show
  1. package/README.md +4 -61
  2. package/dist/src/Array.d.ts +343 -102
  3. package/dist/src/Array.d.ts.map +1 -1
  4. package/dist/src/Array.js +181 -85
  5. package/dist/src/Assert.d.ts +57 -11
  6. package/dist/src/Assert.d.ts.map +1 -1
  7. package/dist/src/Assert.js +47 -11
  8. package/dist/src/BigInt.d.ts +6 -1
  9. package/dist/src/BigInt.d.ts.map +1 -1
  10. package/dist/src/BigInt.js +5 -0
  11. package/dist/src/Brand.d.ts +40 -12
  12. package/dist/src/Brand.d.ts.map +1 -1
  13. package/dist/src/Brand.js +5 -0
  14. package/dist/src/Buffer.d.ts +6 -1
  15. package/dist/src/Buffer.d.ts.map +1 -1
  16. package/dist/src/Buffer.js +7 -2
  17. package/dist/src/Cache.d.ts +10 -2
  18. package/dist/src/Cache.d.ts.map +1 -1
  19. package/dist/src/Cache.js +6 -0
  20. package/dist/src/Callbacks.d.ts +10 -7
  21. package/dist/src/Callbacks.d.ts.map +1 -1
  22. package/dist/src/Callbacks.js +23 -13
  23. package/dist/src/Console.d.ts +361 -69
  24. package/dist/src/Console.d.ts.map +1 -1
  25. package/dist/src/Console.js +217 -117
  26. package/dist/src/Crypto.d.ts +70 -21
  27. package/dist/src/Crypto.d.ts.map +1 -1
  28. package/dist/src/Crypto.js +72 -27
  29. package/dist/src/Eq.d.ts +22 -2
  30. package/dist/src/Eq.d.ts.map +1 -1
  31. package/dist/src/Eq.js +21 -1
  32. package/dist/src/Error.d.ts +23 -12
  33. package/dist/src/Error.d.ts.map +1 -1
  34. package/dist/src/Error.js +27 -11
  35. package/dist/src/Function.d.ts +128 -56
  36. package/dist/src/Function.d.ts.map +1 -1
  37. package/dist/src/Function.js +118 -14
  38. package/dist/src/Identicon.d.ts +5 -0
  39. package/dist/src/Identicon.d.ts.map +1 -1
  40. package/dist/src/Identicon.js +6 -1
  41. package/dist/src/Lookup.d.ts +160 -0
  42. package/dist/src/Lookup.d.ts.map +1 -0
  43. package/dist/src/Lookup.js +192 -0
  44. package/dist/src/Microtask.d.ts +21 -0
  45. package/dist/src/Microtask.d.ts.map +1 -0
  46. package/dist/src/Microtask.js +37 -0
  47. package/dist/src/Number.d.ts +18 -4
  48. package/dist/src/Number.d.ts.map +1 -1
  49. package/dist/src/Number.js +23 -1
  50. package/dist/src/Object.d.ts +110 -5
  51. package/dist/src/Object.d.ts.map +1 -1
  52. package/dist/src/Object.js +108 -5
  53. package/dist/src/Option.d.ts +58 -0
  54. package/dist/src/Option.d.ts.map +1 -0
  55. package/dist/src/Option.js +43 -0
  56. package/dist/src/Order.d.ts +5 -0
  57. package/dist/src/Order.d.ts.map +1 -1
  58. package/dist/src/Order.js +8 -3
  59. package/dist/src/Platform.d.ts +36 -2
  60. package/dist/src/Platform.d.ts.map +1 -1
  61. package/dist/src/Platform.js +10 -6
  62. package/dist/src/Polyfills.d.ts +27 -0
  63. package/dist/src/Polyfills.d.ts.map +1 -0
  64. package/dist/src/Polyfills.js +299 -0
  65. package/dist/src/Random.d.ts +18 -7
  66. package/dist/src/Random.d.ts.map +1 -1
  67. package/dist/src/Random.js +9 -7
  68. package/dist/src/Redacted.d.ts +7 -4
  69. package/dist/src/Redacted.d.ts.map +1 -1
  70. package/dist/src/Redacted.js +5 -0
  71. package/dist/src/Ref.d.ts +31 -16
  72. package/dist/src/Ref.d.ts.map +1 -1
  73. package/dist/src/Ref.js +35 -7
  74. package/dist/src/RefCount.d.ts +62 -0
  75. package/dist/src/RefCount.d.ts.map +1 -0
  76. package/dist/src/RefCount.js +83 -0
  77. package/dist/src/Relation.d.ts +84 -29
  78. package/dist/src/Relation.d.ts.map +1 -1
  79. package/dist/src/Relation.js +83 -105
  80. package/dist/src/Resource.d.ts +263 -0
  81. package/dist/src/Resource.d.ts.map +1 -0
  82. package/dist/src/Resource.js +389 -0
  83. package/dist/src/Result.d.ts +390 -374
  84. package/dist/src/Result.d.ts.map +1 -1
  85. package/dist/src/Result.js +142 -70
  86. package/dist/src/Schedule.d.ts +953 -0
  87. package/dist/src/Schedule.d.ts.map +1 -0
  88. package/dist/src/Schedule.js +1199 -0
  89. package/dist/src/Set.d.ts +181 -0
  90. package/dist/src/Set.d.ts.map +1 -0
  91. package/dist/src/Set.js +137 -0
  92. package/dist/src/Skiplist.d.ts +6 -1
  93. package/dist/src/Skiplist.d.ts.map +1 -1
  94. package/dist/src/Skiplist.js +5 -0
  95. package/dist/src/Sqlite.d.ts +160 -60
  96. package/dist/src/Sqlite.d.ts.map +1 -1
  97. package/dist/src/Sqlite.js +290 -190
  98. package/dist/src/Store.d.ts +36 -28
  99. package/dist/src/Store.d.ts.map +1 -1
  100. package/dist/src/Store.js +55 -15
  101. package/dist/src/String.d.ts +5 -0
  102. package/dist/src/String.d.ts.map +1 -1
  103. package/dist/src/String.js +5 -0
  104. package/dist/src/Task.d.ts +2263 -423
  105. package/dist/src/Task.d.ts.map +1 -1
  106. package/dist/src/Task.js +1488 -348
  107. package/dist/src/Test.d.ts +122 -0
  108. package/dist/src/Test.d.ts.map +1 -0
  109. package/dist/src/Test.js +66 -0
  110. package/dist/src/Time.d.ts +201 -48
  111. package/dist/src/Time.d.ts.map +1 -1
  112. package/dist/src/Time.js +190 -86
  113. package/dist/src/Tracer.d.ts +48 -0
  114. package/dist/src/Tracer.d.ts.map +1 -0
  115. package/dist/src/Tracer.js +6 -0
  116. package/dist/src/Type.d.ts +582 -209
  117. package/dist/src/Type.d.ts.map +1 -1
  118. package/dist/src/Type.js +362 -240
  119. package/dist/src/Types.d.ts +160 -6
  120. package/dist/src/Types.d.ts.map +1 -1
  121. package/dist/src/Types.js +22 -2
  122. package/dist/src/WebSocket.d.ts +113 -58
  123. package/dist/src/WebSocket.d.ts.map +1 -1
  124. package/dist/src/WebSocket.js +210 -118
  125. package/dist/src/Worker.d.ts +245 -60
  126. package/dist/src/Worker.d.ts.map +1 -1
  127. package/dist/src/Worker.js +220 -64
  128. package/dist/src/index.d.ts +25 -3
  129. package/dist/src/index.d.ts.map +1 -1
  130. package/dist/src/index.js +19 -3
  131. package/dist/src/local-first/Db.d.ts +24 -213
  132. package/dist/src/local-first/Db.d.ts.map +1 -1
  133. package/dist/src/local-first/Db.js +622 -293
  134. package/dist/src/local-first/Error.d.ts +12 -0
  135. package/dist/src/local-first/Error.d.ts.map +1 -0
  136. package/dist/src/local-first/Error.js +6 -0
  137. package/dist/src/local-first/Evolu.d.ts +330 -285
  138. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  139. package/dist/src/local-first/Evolu.js +472 -402
  140. package/dist/src/local-first/LocalAuth.d.ts +10 -10
  141. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  142. package/dist/src/local-first/LocalAuth.js +6 -1
  143. package/dist/src/local-first/Owner.d.ts +70 -27
  144. package/dist/src/local-first/Owner.d.ts.map +1 -1
  145. package/dist/src/local-first/Owner.js +27 -14
  146. package/dist/src/local-first/Protocol.d.ts +58 -50
  147. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  148. package/dist/src/local-first/Protocol.js +253 -155
  149. package/dist/src/local-first/Query.d.ts +133 -43
  150. package/dist/src/local-first/Query.d.ts.map +1 -1
  151. package/dist/src/local-first/Query.js +139 -90
  152. package/dist/src/local-first/Relay.d.ts +18 -38
  153. package/dist/src/local-first/Relay.d.ts.map +1 -1
  154. package/dist/src/local-first/Relay.js +59 -171
  155. package/dist/src/local-first/Schema.d.ts +139 -144
  156. package/dist/src/local-first/Schema.d.ts.map +1 -1
  157. package/dist/src/local-first/Schema.js +78 -163
  158. package/dist/src/local-first/Shared.d.ts +125 -0
  159. package/dist/src/local-first/Shared.d.ts.map +1 -0
  160. package/dist/src/local-first/Shared.js +569 -0
  161. package/dist/src/local-first/Storage.d.ts +50 -53
  162. package/dist/src/local-first/Storage.d.ts.map +1 -1
  163. package/dist/src/local-first/Storage.js +121 -173
  164. package/dist/src/local-first/Timestamp.d.ts +28 -35
  165. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  166. package/dist/src/local-first/Timestamp.js +24 -25
  167. package/dist/src/local-first/index.d.ts +2 -15
  168. package/dist/src/local-first/index.d.ts.map +1 -1
  169. package/dist/src/local-first/index.js +2 -15
  170. package/package.json +36 -26
  171. package/src/Array.ts +467 -106
  172. package/src/Assert.ts +87 -12
  173. package/src/BigInt.ts +7 -1
  174. package/src/Brand.ts +41 -12
  175. package/src/Buffer.ts +10 -4
  176. package/src/Cache.ts +11 -2
  177. package/src/Callbacks.ts +33 -23
  178. package/src/Console.ts +567 -178
  179. package/src/Crypto.ts +111 -62
  180. package/src/Eq.ts +30 -3
  181. package/src/Error.ts +50 -34
  182. package/src/Function.ts +140 -68
  183. package/src/Identicon.ts +7 -1
  184. package/src/Lookup.ts +415 -0
  185. package/src/Microtask.ts +58 -0
  186. package/src/Number.ts +40 -7
  187. package/src/Object.ts +155 -16
  188. package/src/Option.ts +74 -0
  189. package/src/Order.ts +11 -3
  190. package/src/Platform.ts +43 -7
  191. package/src/Polyfills.ts +465 -0
  192. package/src/Random.ts +25 -11
  193. package/src/Redacted.ts +8 -4
  194. package/src/Ref.ts +72 -21
  195. package/src/RefCount.ts +170 -0
  196. package/src/Relation.ts +188 -136
  197. package/src/Resource.ts +864 -0
  198. package/src/Result.ts +548 -381
  199. package/src/Schedule.ts +1471 -0
  200. package/src/Set.ts +247 -0
  201. package/src/Skiplist.ts +7 -1
  202. package/src/Sqlite.ts +409 -304
  203. package/src/Store.ts +94 -48
  204. package/src/String.ts +6 -0
  205. package/src/Task.ts +3685 -740
  206. package/src/Test.ts +162 -0
  207. package/src/Time.ts +348 -145
  208. package/src/Tracer.ts +54 -0
  209. package/src/Type.ts +1064 -630
  210. package/src/Types.ts +202 -7
  211. package/src/WebSocket.ts +311 -178
  212. package/src/Worker.ts +527 -147
  213. package/src/index.ts +74 -3
  214. package/src/local-first/Db.ts +871 -597
  215. package/src/local-first/Error.ts +17 -0
  216. package/src/local-first/Evolu.ts +884 -823
  217. package/src/local-first/LocalAuth.ts +10 -10
  218. package/src/local-first/Owner.ts +94 -42
  219. package/src/local-first/Protocol.ts +440 -303
  220. package/src/local-first/Query.ts +243 -194
  221. package/src/local-first/Relay.ts +91 -252
  222. package/src/local-first/Schema.ts +284 -394
  223. package/src/local-first/Shared.ts +932 -0
  224. package/src/local-first/Storage.ts +209 -282
  225. package/src/local-first/Timestamp.ts +38 -45
  226. package/src/local-first/index.ts +2 -16
  227. package/LICENSE +0 -21
  228. package/dist/src/Instances.d.ts +0 -34
  229. package/dist/src/Instances.d.ts.map +0 -1
  230. package/dist/src/Instances.js +0 -44
  231. package/dist/src/Resources.d.ts +0 -118
  232. package/dist/src/Resources.d.ts.map +0 -1
  233. package/dist/src/Resources.js +0 -197
  234. package/dist/src/local-first/Platform.d.ts +0 -25
  235. package/dist/src/local-first/Platform.d.ts.map +0 -1
  236. package/dist/src/local-first/Platform.js +0 -1
  237. package/dist/src/local-first/Public.d.ts +0 -22
  238. package/dist/src/local-first/Public.d.ts.map +0 -1
  239. package/dist/src/local-first/Public.js +0 -15
  240. package/dist/src/local-first/PublicKysely.d.ts +0 -148
  241. package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
  242. package/dist/src/local-first/PublicKysely.js +0 -184
  243. package/dist/src/local-first/Sync.d.ts +0 -112
  244. package/dist/src/local-first/Sync.d.ts.map +0 -1
  245. package/dist/src/local-first/Sync.js +0 -529
  246. package/src/Instances.ts +0 -90
  247. package/src/Resources.ts +0 -367
  248. package/src/local-first/Platform.ts +0 -27
  249. package/src/local-first/Public.ts +0 -42
  250. package/src/local-first/PublicKysely.ts +0 -239
  251. package/src/local-first/Sync.ts +0 -960
@@ -1,11 +1,15 @@
1
- import { RandomBytesDep } from "../Crypto.js";
2
- import { Mnemonic } from "../Type.js";
3
- import { AppOwner, OwnerId } from "./Owner.js";
1
+ /**
2
+ * Local authentication and owner management.
3
+ *
4
+ * @module
5
+ */
6
+ import type { RandomBytesDep } from "../Crypto.js";
7
+ import type { Mnemonic } from "../Type.js";
8
+ import type { AppOwner } from "./Owner.js";
9
+ import { OwnerId } from "./Owner.js";
4
10
  /**
5
11
  * Local authentication and authorization system for Evolu. This is API is
6
12
  * subject to change and not recommended for production use.
7
- *
8
- * @experimental
9
13
  */
10
14
  export interface LocalAuth {
11
15
  /** Logs in with the given owner ID, or loads the target owner if not provided. */
@@ -26,11 +30,7 @@ export interface LocalAuth {
26
30
  export interface LocalAuthDep {
27
31
  readonly localAuth: LocalAuth;
28
32
  }
29
- /**
30
- * Secure storage interface that must be implemented by each platform.
31
- *
32
- * @experimental
33
- */
33
+ /** Secure storage interface that must be implemented by each platform. */
34
34
  export interface SecureStorage {
35
35
  setItem: (key: string, value: string, options?: LocalAuthOptions) => Promise<MutationResult>;
36
36
  getItem: (key: string, options?: LocalAuthOptionsValues) => Promise<SensitiveInfoItem | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"LocalAuth.d.ts","sourceRoot":"","sources":["../../../src/local-first/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;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ACpE,QAAQ,CAAC,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,4 +1,9 @@
1
- import { createAppOwner, createOwnerSecret, mnemonicToOwnerSecret, OwnerEncryptionKey, OwnerWriteKey, } from "./Owner.js";
1
+ /**
2
+ * Local authentication and owner management.
3
+ *
4
+ * @module
5
+ */
6
+ import { createAppOwner, createOwnerSecret, mnemonicToOwnerSecret, OwnerEncryptionKey, OwnerId, OwnerWriteKey, } from "./Owner.js";
2
7
  /**
3
8
  * Creates a local auth using the given secure storage implementation. This
4
9
  * factory function allows each platform to provide its own storage layer while
@@ -1,6 +1,11 @@
1
- import { NonEmptyReadonlyArray } from "../Array.js";
2
- import { RandomBytesDep } from "../Crypto.js";
3
- import { Mnemonic, NonNegativeInt } from "../Type.js";
1
+ /**
2
+ * Owner identity and cryptographic key derivation.
3
+ *
4
+ * @module
5
+ */
6
+ import type { NonEmptyReadonlyArray } from "../Array.js";
7
+ import type { RandomBytesDep } from "../Crypto.js";
8
+ import { Mnemonic, NonNegativeInt, type Typed } from "../Type.js";
4
9
  import { TimestampBytes } from "./Timestamp.js";
5
10
  /**
6
11
  * {@link Owner} without a {@link OwnerWriteKey}.
@@ -47,11 +52,19 @@ export interface Owner extends ReadonlyOwner {
47
52
  /** TODO: Wrap with `Redacted` in the next major version. */
48
53
  readonly writeKey: OwnerWriteKey;
49
54
  }
55
+ /**
56
+ * An {@link ReadonlyOwner} or {@link Owner} with non-empty {@link OwnerTransport}s
57
+ * so it can be synced.
58
+ */
59
+ export interface SyncOwner {
60
+ readonly owner: ReadonlyOwner | Owner;
61
+ readonly transports: NonEmptyReadonlyArray<OwnerTransport>;
62
+ }
50
63
  /** OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}. */
51
64
  export declare const OwnerId: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "Id", import("../Type.js").IdError, import("../Type.js").StringError>, "OwnerId", import("../Type.js").BrandWithoutRefineError<"OwnerId", import("../Type.js").StringError | import("../Type.js").IdError>, never>;
52
65
  export type OwnerId = typeof OwnerId.Type;
53
66
  /** Bytes representation of {@link OwnerId}. */
54
- export declare const OwnerIdBytes: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError>, "Length16", import("../Type.js").LengthError<16>, import("../Type.js").Uint8ArrayError>, "IdBytes", import("../Type.js").BrandWithoutRefineError<"IdBytes", import("../Type.js").LengthError<16> | import("../Type.js").Uint8ArrayError>, never>, "OwnerIdBytes", import("../Type.js").BrandWithoutRefineError<"OwnerIdBytes", import("../Type.js").BrandWithoutRefineError<"IdBytes", import("../Type.js").LengthError<16> | import("../Type.js").Uint8ArrayError>>, never>;
67
+ export declare const OwnerIdBytes: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError>, "Length16", import("../Type.js").LengthError<16>, import("../Type.js").Uint8ArrayError>, "IdBytes", import("../Type.js").BrandWithoutRefineError<"IdBytes", import("../Type.js").Uint8ArrayError | import("../Type.js").LengthError<16>>, never>, "OwnerIdBytes", import("../Type.js").BrandWithoutRefineError<"OwnerIdBytes", import("../Type.js").BrandWithoutRefineError<"IdBytes", import("../Type.js").Uint8ArrayError | import("../Type.js").LengthError<16>>>, never>;
55
68
  export type OwnerIdBytes = typeof OwnerIdBytes.Type;
56
69
  /** Converts {@link OwnerId} to {@link OwnerIdBytes}. */
57
70
  export declare const ownerIdToOwnerIdBytes: (ownerId: OwnerId) => OwnerIdBytes;
@@ -85,6 +98,8 @@ export declare const OwnerSecret: import("../Type.js").BrandType<import("../Type
85
98
  export type OwnerSecret = typeof OwnerSecret.Type;
86
99
  /** Creates a {@link OwnerSecret}. */
87
100
  export declare const createOwnerSecret: (deps: RandomBytesDep) => OwnerSecret;
101
+ /** Deterministic {@link OwnerSecret} for tests. */
102
+ export declare const testOwnerSecret: Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy"> & import("../Brand.js").Brand<"Length32"> & import("../Brand.js").Brand<"OwnerSecret">;
88
103
  /** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
89
104
  export declare const ownerSecretToMnemonic: (secret: OwnerSecret) => Mnemonic;
90
105
  /** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
@@ -109,19 +124,19 @@ export declare const mnemonicToOwnerSecret: (mnemonic: Mnemonic) => OwnerSecret;
109
124
  * devices need to sync the information that an owner was deleted so they can
110
125
  * delete their local data as well.
111
126
  *
112
- * ### Privacy Considerations
127
+ * ## Privacy Considerations
128
+ *
129
+ * AppOwner must never be shared with anyone.
113
130
  *
114
- * AppOwner must never be shared with anyone, except for its {@link OwnerId},
115
- * which can be used for authorization with
116
- * {@link createOwnerWebSocketTransport}. It's safe because OwnerId is
117
- * pseudonymous (it can't be assigned to a specific person).
131
+ * AppOwner's {@link OwnerId} is used for authorization with
132
+ * {@link createOwnerWebSocketTransport}. Share it only with trusted relay
133
+ * parties that must verify access, and do not share it with anyone else.
118
134
  *
119
135
  * For data sharing scenarios, use {@link SharedOwner} and
120
- * {@link SharedReadonlyOwner} instead, which are designed specifically for
121
- * collaborative access.
136
+ * {@link SharedReadonlyOwner} to make intent explicit and distinguish
137
+ * collaborative usage from {@link AppOwner} coordination.
122
138
  */
123
- export interface AppOwner extends Owner {
124
- readonly type: "AppOwner";
139
+ export interface AppOwner extends Owner, Typed<"AppOwner"> {
125
140
  /**
126
141
  * The mnemonic that was used to derive the AppOwner keys. Optional when the
127
142
  * AppOwner is created from external keys to avoid sharing the mnemonic with
@@ -129,13 +144,12 @@ export interface AppOwner extends Owner {
129
144
  *
130
145
  * TODO: Wrap with `Redacted` in the next major version.
131
146
  */
132
- readonly mnemonic?: Mnemonic | null;
133
- }
134
- export interface AppOwnerDep {
135
- readonly appOwner: AppOwner;
147
+ readonly mnemonic: Mnemonic;
136
148
  }
137
149
  /** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
138
150
  export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
151
+ /** Deterministic {@link AppOwner} for tests. */
152
+ export declare const testAppOwner: AppOwner;
139
153
  /**
140
154
  * An {@link Owner} for sharding data.
141
155
  *
@@ -147,8 +161,7 @@ export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
147
161
  * deterministically derived from {@link AppOwner} using
148
162
  * {@link deriveShardOwner}.
149
163
  */
150
- export interface ShardOwner extends Owner {
151
- readonly type: "ShardOwner";
164
+ export interface ShardOwner extends Owner, Typed<"ShardOwner"> {
152
165
  }
153
166
  /** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
154
167
  export declare const createShardOwner: (secret: OwnerSecret) => ShardOwner;
@@ -172,8 +185,7 @@ export declare const createShardOwner: (secret: OwnerSecret) => ShardOwner;
172
185
  */
173
186
  export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number>) => ShardOwner;
174
187
  /** An {@link Owner} for collaborative data with write access. */
175
- export interface SharedOwner extends Owner {
176
- readonly type: "SharedOwner";
188
+ export interface SharedOwner extends Owner, Typed<"SharedOwner"> {
177
189
  }
178
190
  /**
179
191
  * Creates a {@link SharedOwner} from an {@link OwnerSecret} for collaborative
@@ -188,8 +200,7 @@ export declare const createSharedOwner: (secret: OwnerSecret) => SharedOwner;
188
200
  * {@link OwnerId} and {@link EncryptionKey} needed for others to read the shared
189
201
  * data without write access.
190
202
  */
191
- export interface SharedReadonlyOwner extends ReadonlyOwner {
192
- readonly type: "SharedReadonlyOwner";
203
+ export interface SharedReadonlyOwner extends ReadonlyOwner, Typed<"SharedReadonlyOwner"> {
193
204
  }
194
205
  /** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
195
206
  export declare const createSharedReadonlyOwner: (sharedOwner: SharedOwner) => SharedReadonlyOwner;
@@ -202,7 +213,7 @@ export type OwnerTransport = OwnerWebSocketTransport;
202
213
  /**
203
214
  * WebSocket transport configuration.
204
215
  *
205
- * ### Authentication via URL
216
+ * ## Authentication via URL
206
217
  *
207
218
  * The {@link OwnerId} is passed as a URL query parameter. While this approach is
208
219
  * generally discouraged for authentication tokens (they get logged), it's safe
@@ -212,7 +223,7 @@ export type OwnerTransport = OwnerWebSocketTransport;
212
223
  * See: [HTTP headers in Websockets client
213
224
  * API](https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api/74564827#74564827)
214
225
  *
215
- * ### Error Handling
226
+ * ## Error Handling
216
227
  *
217
228
  * When a relay rejects a connection (invalid OwnerId, unauthorized owner, or
218
229
  * server error), the browser WebSocket API does not expose the specific HTTP
@@ -226,8 +237,7 @@ export type OwnerTransport = OwnerWebSocketTransport;
226
237
  * @see {@link createOwnerWebSocketTransport}
227
238
  * @see {@link parseOwnerIdFromOwnerWebSocketTransportUrl}
228
239
  */
229
- export interface OwnerWebSocketTransport {
230
- readonly type: "WebSocket";
240
+ export interface OwnerWebSocketTransport extends Typed<"WebSocket"> {
231
241
  readonly url: string;
232
242
  }
233
243
  /**
@@ -314,4 +324,37 @@ export interface OwnerUsage {
314
324
  */
315
325
  readonly lastTimestamp: TimestampBytes | null;
316
326
  }
327
+ /**
328
+ * An {@link AppOwner} for encrypting device-only data.
329
+ *
330
+ * Device-only data belongs to the current device rather than to the synced app
331
+ * identity. A common example is the last used {@link AppOwner}, which can be
332
+ * stored so users do not need to enter the mnemonic every time they reopen the
333
+ * app.
334
+ *
335
+ * This data must be encrypted because other OS processes may be able to read
336
+ * unencrypted app-controlled storage such as `localStorage`, `IndexedDB`, or
337
+ * similar stores.
338
+ *
339
+ * DeviceAppOwner is backed by a platform-specific secure primitive such as Expo
340
+ * SecureStore, Electron safeStorage, or WebAuthn PRF.
341
+ *
342
+ * Use DeviceAppOwner with a local-only Evolu instance. Local-only means an
343
+ * Evolu instance with empty transports (`transports: []`) so it does not sync
344
+ * its AppOwner, and local-only (prefixed with "_") tables.
345
+ *
346
+ * A local-only Evolu instance is better than plain platform storage because
347
+ * device-only data gets schema, reactivity, and the same cross-platform
348
+ * behavior as the rest of Evolu.
349
+ *
350
+ * The local-only Evolu instance can still use other owners for sync via
351
+ * `useOwner`. Use it for data that belongs to the current device rather than
352
+ * the user app Evolu instance (news delivery etc.).
353
+ *
354
+ * DeviceAppOwner Evolu instance is secure only when its data stays on the
355
+ * device.
356
+ */
357
+ export interface DeviceAppOwner extends AppOwner {
358
+ readonly source: "ExpoSecureStore" | "WebAuthnPrf" | "ElectronSafeStorage";
359
+ }
317
360
  //# sourceMappingURL=Owner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/local-first/Owner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAKL,cAAc,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAML,QAAQ,EACR,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,aAAa,EAAE,kBAAkB,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,WAAW,KAAM,SAAQ,aAAa;IAC1C,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;CAClC;AAED,iFAAiF;AACjF,eAAO,MAAM,OAAO,mZAAuB,CAAC;AAC5C,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC;AAE1C,+CAA+C;AAC/C,eAAO,MAAM,YAAY,uvBAAiC,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;AAEpD,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,KAAG,YACnB,CAAC;AAEvC,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,GAAI,cAAc,YAAY,KAAG,OAClB,CAAC;AAElD,eAAO,MAAM,mBAAmB,0FAA6B,CAAC;AAE9D,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,8/BAA6C,CAAC;AAC7E,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAk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Y,CAAC;IAE/B;;;;;;;;;;;;;OAaG;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,aAAa,GAAG,qBAAqB,CAAC;CAC5E"}
@@ -1,24 +1,31 @@
1
+ /**
2
+ * Owner identity and cryptographic key derivation.
3
+ *
4
+ * @module
5
+ */
1
6
  import * as bip39 from "@scure/bip39";
2
7
  import { wordlist } from "@scure/bip39/wordlists/english.js";
3
- import { createSlip21, EncryptionKey, Entropy16, Entropy32, } from "../Crypto.js";
8
+ import { createSlip21, EncryptionKey, Entropy16, Entropy32, testCreateRandomBytes, } from "../Crypto.js";
9
+ import { testCreateRandomLib } from "../Random.js";
4
10
  import { getOrNull } from "../Result.js";
5
- import { brand, Id, IdBytes, idBytesToId, idToIdBytes, NonNegativeInt, } from "../Type.js";
11
+ import { brand, Id, IdBytes, idBytesToId, idToIdBytes, Mnemonic, NonNegativeInt, } from "../Type.js";
12
+ import { TimestampBytes } from "./Timestamp.js";
6
13
  /** OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}. */
7
- export const OwnerId = brand("OwnerId", Id);
14
+ export const OwnerId = /*#__PURE__*/ brand("OwnerId", Id);
8
15
  /** Bytes representation of {@link OwnerId}. */
9
- export const OwnerIdBytes = brand("OwnerIdBytes", IdBytes);
16
+ export const OwnerIdBytes = /*#__PURE__*/ brand("OwnerIdBytes", IdBytes);
10
17
  /** Converts {@link OwnerId} to {@link OwnerIdBytes}. */
11
18
  export const ownerIdToOwnerIdBytes = (ownerId) => idToIdBytes(ownerId);
12
19
  /** Converts {@link OwnerIdBytes} to {@link OwnerId}. */
13
20
  export const ownerIdBytesToOwnerId = (ownerIdBytes) => idBytesToId(ownerIdBytes);
14
- export const ownerWriteKeyLength = NonNegativeInt.orThrow(16);
21
+ export const ownerWriteKeyLength = /*#__PURE__*/ NonNegativeInt.orThrow(16);
15
22
  /** Symmetric encryption key for {@link Owner} data protection. */
16
- export const OwnerEncryptionKey = brand("OwnerEncryptionKey", EncryptionKey);
23
+ export const OwnerEncryptionKey = /*#__PURE__*/ brand("OwnerEncryptionKey", EncryptionKey);
17
24
  /**
18
25
  * A secure token for write operations. It's derived from {@link OwnerSecret} by
19
26
  * default and can be rotated via {@link createOwnerWriteKey}.
20
27
  */
21
- export const OwnerWriteKey = brand("OwnerWriteKey", Entropy16);
28
+ export const OwnerWriteKey = /*#__PURE__*/ brand("OwnerWriteKey", Entropy16);
22
29
  /**
23
30
  * Creates a new random {@link OwnerWriteKey} for rotation.
24
31
  *
@@ -33,9 +40,15 @@ export const createOwnerWriteKey = (deps) => deps.randomBytes.create(16);
33
40
  * Can be created using {@link createOwnerSecret} or converted from a
34
41
  * {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
35
42
  */
36
- export const OwnerSecret = brand("OwnerSecret", Entropy32);
43
+ export const OwnerSecret = /*#__PURE__*/ brand("OwnerSecret", Entropy32);
37
44
  /** Creates a {@link OwnerSecret}. */
38
45
  export const createOwnerSecret = (deps) => deps.randomBytes.create(32);
46
+ /** Deterministic {@link OwnerSecret} for tests. */
47
+ export const testOwnerSecret = /*#__PURE__*/ createOwnerSecret({
48
+ randomBytes: /*#__PURE__*/ testCreateRandomBytes({
49
+ randomLib: /*#__PURE__*/ testCreateRandomLib(),
50
+ }),
51
+ });
39
52
  /** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
40
53
  export const ownerSecretToMnemonic = (secret) => bip39.entropyToMnemonic(secret, wordlist);
41
54
  /** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
@@ -55,13 +68,13 @@ export const createAppOwner = (secret) => ({
55
68
  type: "AppOwner",
56
69
  mnemonic: ownerSecretToMnemonic(secret),
57
70
  });
71
+ /** Deterministic {@link AppOwner} for tests. */
72
+ export const testAppOwner = /*#__PURE__*/ createAppOwner(testOwnerSecret);
58
73
  /** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
59
- export const createShardOwner = (secret) => {
60
- return {
61
- ...createOwner(secret),
62
- type: "ShardOwner",
63
- };
64
- };
74
+ export const createShardOwner = (secret) => ({
75
+ ...createOwner(secret),
76
+ type: "ShardOwner",
77
+ });
65
78
  /**
66
79
  * Derives a {@link ShardOwner} from an {@link AppOwner} using the specified path.
67
80
  *
@@ -20,7 +20,7 @@
20
20
  * transfer, ownership, real-time broadcasting, request-response semantics, and
21
21
  * error handling.
22
22
  *
23
- * ### Message structure
23
+ * ## Message structure
24
24
  *
25
25
  * | Field | Notes |
26
26
  * | :----------------------------- | :------------------------ |
@@ -43,7 +43,7 @@
43
43
  * | - {@link NonNegativeInt} | Number of ranges. |
44
44
  * | - {@link Range} | |
45
45
  *
46
- * ### WriteKey validation
46
+ * ## WriteKey validation
47
47
  *
48
48
  * The initiator sends a hasWriteKey flag and optionally a WriteKey. The
49
49
  * WriteKey is required when sending messages as a secure token proving the
@@ -52,7 +52,7 @@
52
52
  * validates the WriteKey immediately after parsing the initiator header, before
53
53
  * processing any messages or ranges.
54
54
  *
55
- * ### Synchronization
55
+ * ## Synchronization
56
56
  *
57
57
  * - **Messages**: Sends {@link EncryptedCrdtMessage}s in either direction.
58
58
  * - **Ranges**: Determines messages to sync. Usage varies by transport—e.g., sent
@@ -79,7 +79,7 @@
79
79
  * initiator. In relay-to-relay or P2P sync, both sides may require the
80
80
  * {@link OwnerWriteKey} depending on who is the initiator.
81
81
  *
82
- * ### Protocol errors
82
+ * ## Protocol errors
83
83
  *
84
84
  * The protocol uses error codes in the header to signal issues:
85
85
  *
@@ -94,7 +94,7 @@
94
94
  * All protocol errors except `ProtocolInvalidDataError` include the `OwnerId`
95
95
  * to allow clients to associate errors with the correct owner.
96
96
  *
97
- * ### Message size limit
97
+ * ## Message size limit
98
98
  *
99
99
  * The protocol enforces a strict maximum size for all messages, defined by
100
100
  * {@link ProtocolMessageMaxSize}. This ensures every {@link ProtocolMessage} is
@@ -107,7 +107,7 @@
107
107
  * message limit to ensure efficient sync with
108
108
  * {@link defaultProtocolMessageRangesMaxSize}.
109
109
  *
110
- * ### Why Binary?
110
+ * ## Why Binary?
111
111
  *
112
112
  * The protocol avoids JSON because:
113
113
  *
@@ -127,7 +127,7 @@
127
127
  * To avoid reinventing serialization where it’s unnecessary—like for JSON and
128
128
  * certain numbers—the Evolu Protocol relies on MessagePack.
129
129
  *
130
- * ### Versioning
130
+ * ## Versioning
131
131
  *
132
132
  * Evolu Protocol uses explicit versioning to ensure compatibility between
133
133
  * clients and relays (or peers). Each protocol message begins with a version
@@ -148,7 +148,7 @@
148
148
  * Version negotiation is per-owner, allowing Evolu Protocol to evolve safely
149
149
  * over time and provide clear feedback about version mismatches.
150
150
  *
151
- * ### Credible exit
151
+ * ## Credible exit
152
152
  *
153
153
  * The protocol specification is intentionally non-configurable to ensure
154
154
  * universal compatibility. This design allows applications (users) to switch
@@ -159,15 +159,17 @@
159
159
  *
160
160
  * @module
161
161
  */
162
- import { NonEmptyReadonlyArray } from "../Array.js";
163
- import { Brand } from "../Brand.js";
164
- import { Buffer } from "../Buffer.js";
165
- import { EncryptionKey, RandomBytesDep, SymmetricCryptoDecryptError, SymmetricCryptoDep } from "../Crypto.js";
166
- import { Result } from "../Result.js";
162
+ import { type NonEmptyReadonlyArray } from "../Array.js";
163
+ import type { Brand } from "../Brand.js";
164
+ import type { ConsoleDep } from "../Console.js";
165
+ import { type Buffer } from "../Buffer.js";
166
+ import { type DecryptWithXChaCha20Poly1305Error, EncryptionKey, type RandomBytesDep } from "../Crypto.js";
167
+ import { type Result } from "../Result.js";
167
168
  import { SqliteValue } from "../Sqlite.js";
168
- import { NonNegativeInt, PositiveInt } from "../Type.js";
169
- import { Owner, OwnerError, OwnerId, OwnerWriteKey } from "./Owner.js";
170
- import { BaseRange, CrdtMessage, DbChange, EncryptedCrdtMessage, EncryptedDbChange, FingerprintRange, RangeType, SkipRange, StorageDep } from "./Storage.js";
169
+ import type { Task } from "../Task.js";
170
+ import { NonNegativeInt, PositiveInt, type Typed } from "../Type.js";
171
+ import { type Owner, type OwnerError, OwnerId, OwnerWriteKey } from "./Owner.js";
172
+ import { type BaseRange, type CrdtMessage, DbChange, type EncryptedCrdtMessage, type EncryptedDbChange, type FingerprintRange, RangeType, type SkipRange, type StorageDep } from "./Storage.js";
171
173
  import { NodeId, Timestamp } from "./Timestamp.js";
172
174
  /**
173
175
  * Protocol message maximum size.
@@ -185,7 +187,7 @@ import { NodeId, Timestamp } from "./Timestamp.js";
185
187
  * Increasing this value on the client side would break compatibility with
186
188
  * relays that enforce smaller limits.
187
189
  */
188
- export declare const ProtocolMessageMaxSize: import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int">, number, import("../Type.js").IntError, number, import("../Type.js").NumberError>, "Between1000000-100000000", import("../Type.js").BetweenError<1000000, 100000000>, import("../Type.js").IntError | import("../Type.js").NumberError>;
190
+ export declare const ProtocolMessageMaxSize: import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int">, number, import("../Type.js").IntError, number, import("../Type.js").NumberError>, "Between1000000-100000000", import("../Type.js").BetweenError<1000000, 100000000>, import("../Type.js").NumberError | import("../Type.js").IntError>;
189
191
  export type ProtocolMessageMaxSize = typeof ProtocolMessageMaxSize.Type;
190
192
  /**
191
193
  * Default {@link ProtocolMessageMaxSize} (1MB).
@@ -205,7 +207,7 @@ export declare const defaultProtocolMessageMaxSize: ProtocolMessageMaxSize;
205
207
  * {@link defaultProtocolMessageMaxSize}, maintaining compatibility between all
206
208
  * clients and relays.
207
209
  */
208
- export declare const ProtocolMessageRangesMaxSize: import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int">, number, import("../Type.js").IntError, number, import("../Type.js").NumberError>, "Between3000-100000", import("../Type.js").BetweenError<3000, 100000>, import("../Type.js").IntError | import("../Type.js").NumberError>;
210
+ export declare const ProtocolMessageRangesMaxSize: import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int">, number, import("../Type.js").IntError, number, import("../Type.js").NumberError>, "Between3000-100000", import("../Type.js").BetweenError<3000, 100000>, import("../Type.js").NumberError | import("../Type.js").IntError>;
209
211
  export type ProtocolMessageRangesMaxSize = typeof ProtocolMessageRangesMaxSize.Type;
210
212
  /**
211
213
  * Default {@link ProtocolMessageRangesMaxSize} (30KB).
@@ -217,7 +219,7 @@ export declare const defaultProtocolMessageRangesMaxSize: ProtocolMessageRangesM
217
219
  /** Evolu Protocol Message. */
218
220
  export type ProtocolMessage = Uint8Array & Brand<"ProtocolMessage">;
219
221
  /** Evolu Protocol version. */
220
- export declare const protocolVersion: number & Brand<"Int"> & Brand<"NonNegative">;
222
+ export declare const protocolVersion: number & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">;
221
223
  export declare const MessageType: {
222
224
  /** Request message from initiator (client) to non-initiator (relay). */
223
225
  readonly Request: 0;
@@ -227,6 +229,19 @@ export declare const MessageType: {
227
229
  readonly Broadcast: 2;
228
230
  };
229
231
  export type MessageType = (typeof MessageType)[keyof typeof MessageType];
232
+ /** Parsed protocol header for supported protocol messages. */
233
+ export interface ProtocolHeader extends Typed<"ProtocolHeader"> {
234
+ readonly version: 1;
235
+ readonly ownerId: OwnerId;
236
+ readonly messageType: MessageType;
237
+ }
238
+ /**
239
+ * Parses the protocol header needed for routing.
240
+ *
241
+ * Every protocol message begins with `protocolVersion`, `ownerId`, and
242
+ * `messageType`.
243
+ */
244
+ export declare const parseProtocolHeader: (inputMessage: Uint8Array) => Result<ProtocolHeader, ProtocolInvalidDataError>;
230
245
  export declare const SubscriptionFlags: {
231
246
  /** No subscription changes for this owner. */
232
247
  readonly None: 0;
@@ -253,28 +268,24 @@ export type ProtocolError = ProtocolVersionError | ProtocolInvalidDataError | Pr
253
268
  * Represents a version mismatch in the Evolu Protocol. Occurs when the
254
269
  * initiator and non-initiator are using incompatible protocol versions.
255
270
  */
256
- export interface ProtocolVersionError extends OwnerError {
257
- readonly type: "ProtocolVersionError";
271
+ export interface ProtocolVersionError extends OwnerError, Typed<"ProtocolVersionError"> {
258
272
  readonly version: NonNegativeInt;
259
273
  /** Indicates which side is obsolete and should update. */
260
274
  readonly isInitiator: boolean;
261
275
  }
262
276
  /** Error for invalid or corrupted protocol message data. */
263
- export interface ProtocolInvalidDataError {
264
- readonly type: "ProtocolInvalidDataError";
277
+ export interface ProtocolInvalidDataError extends Typed<"ProtocolInvalidDataError"> {
265
278
  readonly data: globalThis.Uint8Array;
266
279
  readonly error: unknown;
267
280
  }
268
281
  /** Error when a {@link OwnerWriteKey} is invalid, missing, or fails validation. */
269
- export interface ProtocolWriteKeyError extends OwnerError {
270
- readonly type: "ProtocolWriteKeyError";
282
+ export interface ProtocolWriteKeyError extends OwnerError, Typed<"ProtocolWriteKeyError"> {
271
283
  }
272
284
  /**
273
285
  * Error indicating a serious relay-side write failure. Clients should log this
274
286
  * error and show a generic sync error to the user.
275
287
  */
276
- export interface ProtocolWriteError extends OwnerError {
277
- readonly type: "ProtocolWriteError";
288
+ export interface ProtocolWriteError extends OwnerError, Typed<"ProtocolWriteError"> {
278
289
  }
279
290
  /**
280
291
  * Error when storage or billing quota is exceeded.
@@ -289,23 +300,20 @@ export interface ProtocolWriteError extends OwnerError {
289
300
  * plan. Quota monitoring and management is the relay provider's
290
301
  * responsibility.
291
302
  */
292
- export interface ProtocolQuotaError extends OwnerError {
293
- readonly type: "ProtocolQuotaError";
303
+ export interface ProtocolQuotaError extends OwnerError, Typed<"ProtocolQuotaError"> {
294
304
  }
295
305
  /**
296
306
  * Error indicating a serious relay-side synchronization failure. Clients should
297
307
  * log this error and show a generic sync error to the user.
298
308
  */
299
- export interface ProtocolSyncError extends OwnerError {
300
- readonly type: "ProtocolSyncError";
309
+ export interface ProtocolSyncError extends OwnerError, Typed<"ProtocolSyncError"> {
301
310
  }
302
311
  /**
303
312
  * Error when embedded timestamp doesn't match expected timestamp in
304
313
  * EncryptedDbChange. Indicates potential tampering or corruption of CRDT
305
314
  * messages.
306
315
  */
307
- export interface ProtocolTimestampMismatchError {
308
- readonly type: "ProtocolTimestampMismatchError";
316
+ export interface ProtocolTimestampMismatchError extends Typed<"ProtocolTimestampMismatchError"> {
309
317
  readonly expected: Timestamp;
310
318
  readonly timestamp: Timestamp;
311
319
  }
@@ -316,9 +324,9 @@ export interface ProtocolTimestampMismatchError {
316
324
  * protocol ensures all messages will be sent in the next round(s) even over
317
325
  * unidirectional and stateless transports.
318
326
  */
319
- export declare const createProtocolMessageFromCrdtMessages: (deps: RandomBytesDep & SymmetricCryptoDep) => (owner: Owner, messages: NonEmptyReadonlyArray<CrdtMessage>, maxSize?: ProtocolMessageMaxSize) => ProtocolMessage;
327
+ export declare const createProtocolMessageFromCrdtMessages: (deps: RandomBytesDep) => (owner: Owner, messages: NonEmptyReadonlyArray<CrdtMessage>, maxSize?: ProtocolMessageMaxSize) => ProtocolMessage;
320
328
  /** Creates a {@link ProtocolMessage} for sync. */
321
- export declare const createProtocolMessageForSync: (deps: StorageDep) => (ownerId: OwnerId, subscriptionFlag?: SubscriptionFlag) => ProtocolMessage | null;
329
+ export declare const createProtocolMessageForSync: (deps: StorageDep & ConsoleDep) => (ownerId: OwnerId, subscriptionFlag?: SubscriptionFlag) => ProtocolMessage | null;
322
330
  export declare const createProtocolMessageForUnsubscribe: (ownerId: OwnerId) => ProtocolMessage;
323
331
  /**
324
332
  * Mutable builder for constructing {@link ProtocolMessage} respecting size
@@ -360,7 +368,7 @@ export interface TimestampsBuffer {
360
368
  }
361
369
  export declare const createTimestampsBuffer: () => TimestampsBuffer;
362
370
  export interface ApplyProtocolMessageAsClientOptions {
363
- getWriteKey?: (ownerId: OwnerId) => OwnerWriteKey | null;
371
+ writeKey?: OwnerWriteKey;
364
372
  rangesMaxSize?: ProtocolMessageRangesMaxSize;
365
373
  /** For tests only. */
366
374
  version?: NonNegativeInt;
@@ -369,15 +377,15 @@ export interface ApplyProtocolMessageAsClientOptions {
369
377
  * Result type for {@link applyProtocolMessageAsClient} that distinguishes
370
378
  * between responses to client requests and broadcast messages.
371
379
  */
372
- export type ApplyProtocolMessageAsClientResult = {
373
- readonly type: "response";
380
+ export interface ApplyProtocolMessageAsClientResponse extends Typed<"Response"> {
374
381
  readonly message: ProtocolMessage;
375
- } | {
376
- readonly type: "no-response";
377
- } | {
378
- readonly type: "broadcast";
379
- };
380
- export declare const applyProtocolMessageAsClient: (deps: StorageDep) => (inputMessage: Uint8Array, options?: ApplyProtocolMessageAsClientOptions) => Promise<Result<ApplyProtocolMessageAsClientResult, ProtocolInvalidDataError | ProtocolSyncError | ProtocolVersionError | ProtocolWriteError | ProtocolWriteKeyError | ProtocolQuotaError>>;
382
+ }
383
+ export interface ApplyProtocolMessageAsClientNoResponse extends Typed<"NoResponse"> {
384
+ }
385
+ export interface ApplyProtocolMessageAsClientBroadcast extends Typed<"Broadcast"> {
386
+ }
387
+ export type ApplyProtocolMessageAsClientResult = ApplyProtocolMessageAsClientResponse | ApplyProtocolMessageAsClientNoResponse | ApplyProtocolMessageAsClientBroadcast;
388
+ export declare const applyProtocolMessageAsClient: (inputMessage: Uint8Array, options?: ApplyProtocolMessageAsClientOptions) => Task<ApplyProtocolMessageAsClientResult, ProtocolInvalidDataError | ProtocolSyncError | ProtocolVersionError | ProtocolWriteError | ProtocolWriteKeyError | ProtocolQuotaError, StorageDep>;
381
389
  export interface ApplyProtocolMessageAsRelayOptions {
382
390
  /** To subscribe an owner for broadcasting. */
383
391
  subscribe?: (ownerId: OwnerId) => void;
@@ -397,13 +405,13 @@ export interface ApplyProtocolMessageAsRelayOptions {
397
405
  * to sync. Clients may choose not to respond in certain cases (like when they
398
406
  * receive broadcast messages or when they lack a write key for syncing).
399
407
  */
400
- export interface ApplyProtocolMessageAsRelayResult {
401
- readonly type: "response";
408
+ export interface ApplyProtocolMessageAsRelayResult extends Typed<"Response"> {
402
409
  readonly message: ProtocolMessage;
403
410
  }
404
- export declare const applyProtocolMessageAsRelay: (deps: StorageDep) => (inputMessage: Uint8Array, options?: ApplyProtocolMessageAsRelayOptions,
411
+ export declare const applyProtocolMessageAsRelay: (inputMessage: Uint8Array, options?: ApplyProtocolMessageAsRelayOptions,
405
412
  /** For tests only. */
406
- version?: number & Brand<"Int"> & Brand<"NonNegative">) => Promise<Result<ApplyProtocolMessageAsRelayResult, ProtocolInvalidDataError>>;
413
+ version?: NonNegativeInt) => Task<ApplyProtocolMessageAsRelayResult, ProtocolInvalidDataError, StorageDep>;
414
+ export declare const decodeRle: <T>(buffer: Buffer, length: NonNegativeInt, decodeValue: () => T) => ReadonlyArray<T>;
407
415
  /**
408
416
  * Evolu uses MessagePack to handle all number variants except for
409
417
  * NonNegativeInt. For NonNegativeInt, Evolu provides more efficient encoding.
@@ -441,13 +449,13 @@ export declare const decodeFlags: (buffer: Buffer, count: PositiveInt) => Readon
441
449
  * timestamp for tamper-proof verification that the timestamp matches the change
442
450
  * data.
443
451
  */
444
- export declare const encodeAndEncryptDbChange: (deps: SymmetricCryptoDep) => (message: CrdtMessage, key: EncryptionKey) => EncryptedDbChange;
452
+ export declare const encodeAndEncryptDbChange: (deps: RandomBytesDep) => (message: CrdtMessage, key: EncryptionKey) => EncryptedDbChange;
445
453
  /**
446
454
  * Decrypts and decodes an {@link EncryptedCrdtMessage} using the provided
447
455
  * owner's encryption key. Verifies that the embedded timestamp matches the
448
456
  * expected timestamp to ensure message integrity.
449
457
  */
450
- export declare const decryptAndDecodeDbChange: (deps: SymmetricCryptoDep) => (message: EncryptedCrdtMessage, key: EncryptionKey) => Result<DbChange, SymmetricCryptoDecryptError | ProtocolInvalidDataError | ProtocolTimestampMismatchError>;
458
+ export declare const decryptAndDecodeDbChange: (message: EncryptedCrdtMessage, key: EncryptionKey) => Result<DbChange, DecryptWithXChaCha20Poly1305Error | ProtocolInvalidDataError | ProtocolTimestampMismatchError>;
451
459
  /**
452
460
  * Encodes a non-negative integer into a variable-length integer format. It's
453
461
  * more efficient than encoding via {@link encodeNumber}.