@evolu/common 6.0.1-preview.19 → 6.0.1-preview.20

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 (140) hide show
  1. package/dist/src/Assert.d.ts.map +1 -1
  2. package/dist/src/Assert.js +1 -1
  3. package/dist/src/Buffer.d.ts +1 -1
  4. package/dist/src/Buffer.d.ts.map +1 -1
  5. package/dist/src/Buffer.js +1 -1
  6. package/dist/src/CallbackRegistry.d.ts +53 -0
  7. package/dist/src/CallbackRegistry.d.ts.map +1 -0
  8. package/dist/src/CallbackRegistry.js +25 -0
  9. package/dist/src/Console.d.ts +31 -6
  10. package/dist/src/Console.d.ts.map +1 -1
  11. package/dist/src/Console.js +72 -9
  12. package/dist/src/Crypto.d.ts +48 -37
  13. package/dist/src/Crypto.d.ts.map +1 -1
  14. package/dist/src/Crypto.js +27 -50
  15. package/dist/src/Evolu/Db.d.ts +138 -66
  16. package/dist/src/Evolu/Db.d.ts.map +1 -1
  17. package/dist/src/Evolu/Db.js +248 -645
  18. package/dist/src/Evolu/Diff.d.ts +3 -3
  19. package/dist/src/Evolu/Diff.d.ts.map +1 -1
  20. package/dist/src/Evolu/Diff.js +7 -5
  21. package/dist/src/Evolu/Evolu.d.ts +79 -116
  22. package/dist/src/Evolu/Evolu.d.ts.map +1 -1
  23. package/dist/src/Evolu/Evolu.js +275 -132
  24. package/dist/src/Evolu/Internal.d.ts +0 -2
  25. package/dist/src/Evolu/Internal.d.ts.map +1 -1
  26. package/dist/src/Evolu/Internal.js +0 -2
  27. package/dist/src/Evolu/LocalAuth.d.ts +144 -0
  28. package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
  29. package/dist/src/Evolu/LocalAuth.js +171 -0
  30. package/dist/src/Evolu/Owner.d.ts +129 -83
  31. package/dist/src/Evolu/Owner.d.ts.map +1 -1
  32. package/dist/src/Evolu/Owner.js +80 -89
  33. package/dist/src/Evolu/Platform.d.ts +9 -7
  34. package/dist/src/Evolu/Platform.d.ts.map +1 -1
  35. package/dist/src/Evolu/Protocol.d.ts +114 -191
  36. package/dist/src/Evolu/Protocol.d.ts.map +1 -1
  37. package/dist/src/Evolu/Protocol.js +409 -416
  38. package/dist/src/Evolu/Public.d.ts +6 -8
  39. package/dist/src/Evolu/Public.d.ts.map +1 -1
  40. package/dist/src/Evolu/Public.js +2 -3
  41. package/dist/src/Evolu/PublicKysely.js +3 -3
  42. package/dist/src/Evolu/Relay.d.ts +1 -2
  43. package/dist/src/Evolu/Relay.d.ts.map +1 -1
  44. package/dist/src/Evolu/Relay.js +11 -9
  45. package/dist/src/Evolu/Schema.d.ts +88 -27
  46. package/dist/src/Evolu/Schema.d.ts.map +1 -1
  47. package/dist/src/Evolu/Schema.js +141 -24
  48. package/dist/src/Evolu/Storage.d.ts +158 -14
  49. package/dist/src/Evolu/Storage.d.ts.map +1 -1
  50. package/dist/src/Evolu/Storage.js +32 -32
  51. package/dist/src/Evolu/Sync.d.ts +77 -13
  52. package/dist/src/Evolu/Sync.d.ts.map +1 -1
  53. package/dist/src/Evolu/Sync.js +453 -20
  54. package/dist/src/Evolu/Timestamp.d.ts +29 -27
  55. package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
  56. package/dist/src/Evolu/Timestamp.js +20 -18
  57. package/dist/src/ManyToManyMap.d.ts +74 -10
  58. package/dist/src/ManyToManyMap.d.ts.map +1 -1
  59. package/dist/src/ManyToManyMap.js +41 -6
  60. package/dist/src/Random.d.ts +3 -2
  61. package/dist/src/Random.d.ts.map +1 -1
  62. package/dist/src/RefCountedResourceManager.d.ts +119 -0
  63. package/dist/src/RefCountedResourceManager.d.ts.map +1 -0
  64. package/dist/src/RefCountedResourceManager.js +197 -0
  65. package/dist/src/Result.d.ts +144 -22
  66. package/dist/src/Result.d.ts.map +1 -1
  67. package/dist/src/Result.js +5 -2
  68. package/dist/src/Sqlite.d.ts +20 -4
  69. package/dist/src/Sqlite.d.ts.map +1 -1
  70. package/dist/src/Sqlite.js +50 -8
  71. package/dist/src/Task.d.ts +511 -0
  72. package/dist/src/Task.d.ts.map +1 -0
  73. package/dist/src/Task.js +410 -0
  74. package/dist/src/Time.d.ts +59 -0
  75. package/dist/src/Time.d.ts.map +1 -1
  76. package/dist/src/Time.js +87 -4
  77. package/dist/src/Type.d.ts +431 -341
  78. package/dist/src/Type.d.ts.map +1 -1
  79. package/dist/src/Type.js +458 -466
  80. package/dist/src/WebSocket.d.ts +5 -2
  81. package/dist/src/WebSocket.d.ts.map +1 -1
  82. package/dist/src/WebSocket.js +12 -13
  83. package/dist/src/Worker.d.ts +39 -11
  84. package/dist/src/Worker.d.ts.map +1 -1
  85. package/dist/src/Worker.js +22 -4
  86. package/dist/src/index.d.ts +2 -3
  87. package/dist/src/index.d.ts.map +1 -1
  88. package/dist/src/index.js +2 -3
  89. package/package.json +7 -7
  90. package/src/Assert.ts +2 -4
  91. package/src/Buffer.ts +1 -1
  92. package/src/CallbackRegistry.ts +84 -0
  93. package/src/Console.ts +91 -11
  94. package/src/Crypto.ts +78 -91
  95. package/src/Evolu/Db.ts +455 -947
  96. package/src/Evolu/Diff.ts +7 -5
  97. package/src/Evolu/Evolu.ts +545 -307
  98. package/src/Evolu/Internal.ts +0 -2
  99. package/src/Evolu/LocalAuth.ts +422 -0
  100. package/src/Evolu/Owner.ts +191 -131
  101. package/src/Evolu/Platform.ts +9 -9
  102. package/src/Evolu/Protocol.ts +536 -653
  103. package/src/Evolu/Public.ts +7 -9
  104. package/src/Evolu/PublicKysely.ts +3 -3
  105. package/src/Evolu/Relay.ts +17 -12
  106. package/src/Evolu/Schema.ts +271 -66
  107. package/src/Evolu/Storage.ts +263 -55
  108. package/src/Evolu/Sync.ts +758 -37
  109. package/src/Evolu/Timestamp.ts +30 -35
  110. package/src/ManyToManyMap.ts +127 -24
  111. package/src/Random.ts +3 -2
  112. package/src/RefCountedResourceManager.ts +368 -0
  113. package/src/Result.ts +149 -23
  114. package/src/Sqlite.ts +59 -24
  115. package/src/Task.ts +779 -0
  116. package/src/Time.ts +168 -4
  117. package/src/Type.ts +657 -695
  118. package/src/WebSocket.ts +23 -17
  119. package/src/Worker.ts +72 -23
  120. package/src/index.ts +2 -3
  121. package/dist/src/Callbacks.d.ts +0 -20
  122. package/dist/src/Callbacks.d.ts.map +0 -1
  123. package/dist/src/Callbacks.js +0 -18
  124. package/dist/src/Evolu/Config.d.ts +0 -82
  125. package/dist/src/Evolu/Config.d.ts.map +0 -1
  126. package/dist/src/Evolu/Config.js +0 -9
  127. package/dist/src/Evolu/Kysely.d.ts +0 -6
  128. package/dist/src/Evolu/Kysely.d.ts.map +0 -1
  129. package/dist/src/Evolu/Kysely.js +0 -21
  130. package/dist/src/NanoId.d.ts +0 -27
  131. package/dist/src/NanoId.d.ts.map +0 -1
  132. package/dist/src/NanoId.js +0 -6
  133. package/dist/src/Promise.d.ts +0 -180
  134. package/dist/src/Promise.d.ts.map +0 -1
  135. package/dist/src/Promise.js +0 -176
  136. package/src/Callbacks.ts +0 -43
  137. package/src/Evolu/Config.ts +0 -97
  138. package/src/Evolu/Kysely.ts +0 -38
  139. package/src/NanoId.ts +0 -39
  140. package/src/Promise.ts +0 -295
@@ -0,0 +1,144 @@
1
+ import { RandomBytesDep } from "../Crypto.js";
2
+ import { Mnemonic } from "../Type.js";
3
+ import { AppOwner, OwnerId } from "./Owner.js";
4
+ /** @experimental */
5
+ export interface LocalAuth {
6
+ /** Logs in with the given owner ID, or loads the target owner if not provided. */
7
+ login: (ownerId?: OwnerId, options?: LocalAuthOptions & {
8
+ reloadNeeded?: boolean;
9
+ }) => Promise<AuthResult | null>;
10
+ /** Registers a new owner with the given username. */
11
+ register: (username: string, options?: LocalAuthOptions & {
12
+ mnemonic?: Mnemonic | null;
13
+ }) => Promise<AuthResult | null>;
14
+ /** Unregisters an owner with the given owner ID. */
15
+ unregister: (ownerId: OwnerId, options?: LocalAuthOptions) => Promise<void>;
16
+ /** Lists all registered owner ids with associated usernames. */
17
+ getProfiles: (options?: LocalAuthOptionsValues) => Promise<Array<{
18
+ ownerId: OwnerId;
19
+ username: string;
20
+ }>>;
21
+ /** Clears all owners and metadata from the local auth. */
22
+ clearAll: (options?: LocalAuthOptions) => Promise<void>;
23
+ }
24
+ export interface LocalAuthDep {
25
+ readonly localAuth: LocalAuth;
26
+ }
27
+ /**
28
+ * - **⚠️
29
+ *
30
+ * Secure storage interface that must be implemented by each platform.
31
+ */
32
+ export interface SecureStorage {
33
+ setItem: (key: string, value: string, options?: LocalAuthOptions) => Promise<MutationResult>;
34
+ getItem: (key: string, options?: LocalAuthOptionsValues) => Promise<SensitiveInfoItem | null>;
35
+ deleteItem: (key: string, options?: LocalAuthOptions) => Promise<boolean>;
36
+ getAllItems: (options?: LocalAuthOptionsValues) => Promise<Array<SensitiveInfoItem>>;
37
+ clearService: (options?: LocalAuthOptions) => Promise<void>;
38
+ }
39
+ export interface SecureStorageDep {
40
+ readonly secureStorage: SecureStorage;
41
+ }
42
+ /**
43
+ * Creates a local auth using the given secure storage implementation. This
44
+ * factory function allows each platform to provide its own storage layer while
45
+ * sharing the common auth logic.
46
+ */
47
+ export declare const createLocalAuth: (deps: SecureStorageDep & RandomBytesDep) => LocalAuth;
48
+ export declare const AUTH_NAMESPACE = "evolu";
49
+ export declare const AUTH_METAKEY_LAST_OWNER = "_last_owner";
50
+ export declare const AUTH_METAKEY_OWNER_NAMES = "_owner_names";
51
+ export declare const AUTH_DEFAULT_OPTIONS: LocalAuthOptions;
52
+ export interface AuthResult {
53
+ /** The owner created during registration. */
54
+ readonly owner: AppOwner | undefined;
55
+ /** The name provided by the user during registration. */
56
+ readonly username: string;
57
+ }
58
+ export interface LocalAuthOptions {
59
+ /**
60
+ * Native: Namespaces the stored entry. Defaults to the bundle identifier
61
+ * (when available) or `default`.
62
+ */
63
+ readonly service?: string;
64
+ /** IOS: Enable keychain item synchronization via iCloud. */
65
+ readonly iosSynchronizable?: boolean;
66
+ /** IOS: Custom keychain access group. */
67
+ readonly keychainGroup?: string;
68
+ /**
69
+ * Native: Desired access-control policy. The native implementation will
70
+ * automatically fall back to the strongest supported policy for the current
71
+ * device (Secure Enclave ➝ Biometry ➝ Device Credential ➝ None).
72
+ */
73
+ readonly accessControl?: AccessControl;
74
+ /**
75
+ * Android: Fine tune whether the hardware-authenticated key should require
76
+ * biometrics only.
77
+ */
78
+ readonly androidBiometricsStrongOnly?: boolean;
79
+ /**
80
+ * Native: Optional prompt configuration that will be shown when protected
81
+ * keys require user presence.
82
+ */
83
+ readonly authenticationPrompt?: AuthenticationPrompt;
84
+ /** Web: The relying party ID for WebAuthn. Defaults to the current hostname. */
85
+ readonly relyingPartyID?: string;
86
+ /** Web: The relying party name for WebAuthn. Defaults to 'Evolu'. */
87
+ readonly relyingPartyName?: string;
88
+ /** Web: The username for WebAuthn. Defaults to 'Evolu User'. */
89
+ readonly webAuthnUsername?: string;
90
+ /**
91
+ * Web: The user verification requirement for WebAuthn. Defaults to
92
+ * 'required'.
93
+ */
94
+ readonly webAuthnUserVerification?: UserVerificationRequirement;
95
+ /** Web: The authenticator attachment for WebAuthn. Defaults to 'platform'. */
96
+ readonly webAuthnAuthenticatorAttachment?: AuthenticatorAttachment;
97
+ }
98
+ export interface LocalAuthOptionsValues extends LocalAuthOptions {
99
+ /** When true, the stored value is returned for each item. Defaults to false. */
100
+ readonly includeValues?: boolean;
101
+ }
102
+ /**
103
+ * Configuration for the biometric/device credential prompt shown when a
104
+ * protected item is accessed.
105
+ */
106
+ export interface AuthenticationPrompt {
107
+ readonly title: string;
108
+ readonly subtitle?: string;
109
+ readonly description?: string;
110
+ readonly cancel?: string;
111
+ }
112
+ export interface SensitiveInfoGetRequest extends LocalAuthOptions {
113
+ readonly key: string;
114
+ /** Include the encrypted value when available. Defaults to true. */
115
+ readonly includeValue?: boolean;
116
+ }
117
+ export interface StorageMetadata {
118
+ readonly securityLevel: SecurityLevel;
119
+ readonly backend: StorageBackend;
120
+ readonly accessControl: AccessControl;
121
+ readonly timestamp: number;
122
+ }
123
+ export interface SensitiveInfoItem {
124
+ readonly key: string;
125
+ readonly service: string;
126
+ readonly value?: string;
127
+ readonly metadata: StorageMetadata;
128
+ }
129
+ export interface MutationResult {
130
+ readonly metadata: StorageMetadata;
131
+ }
132
+ /**
133
+ * Enumerates the highest security tier that was effectively applied while
134
+ * storing a value.
135
+ */
136
+ export type SecurityLevel = "secureEnclave" | "strongBox" | "biometry" | "deviceCredential" | "software";
137
+ /** Enumerates the native storage backend used to persist sensitive data. */
138
+ export type StorageBackend = "keychain" | "androidKeystore" | "encryptedSharedPreferences";
139
+ /**
140
+ * Enumerates the access-control policy enforced by the underlying secure
141
+ * storage.
142
+ */
143
+ export type AccessControl = "secureEnclaveBiometry" | "biometryCurrentSet" | "biometryAny" | "devicePasscode" | "none";
144
+ //# sourceMappingURL=LocalAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalAuth.d.ts","sourceRoot":"","sources":["../../../src/Evolu/LocalAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,QAAQ,EAKR,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB,oBAAoB;AACpB,MAAM,WAAW,SAAS;IACxB,kFAAkF;IAClF,KAAK,EAAE,CACL,OAAO,CAAC,EAAE,OAAO,EACjB,OAAO,CAAC,EAAE,gBAAgB,GAAG;QAAE,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,KACpD,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAEhC,qDAAqD;IACrD,QAAQ,EAAE,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,gBAAgB,GAAG;QAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;KAAE,KACxD,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAEhC,oDAAoD;IACpD,UAAU,EAAE,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Key, OwnerWriteKey, } from "./Owner.js";
2
+ /**
3
+ * Creates a local auth using the given secure storage implementation. This
4
+ * factory function allows each platform to provide its own storage layer while
5
+ * sharing the common auth logic.
6
+ */
7
+ export const createLocalAuth = (deps) => {
8
+ const setLastOwnerId = async (id, options) => {
9
+ await deps.secureStorage.setItem(AUTH_METAKEY_LAST_OWNER, id, {
10
+ ...AUTH_DEFAULT_OPTIONS,
11
+ ...options,
12
+ accessControl: "none",
13
+ });
14
+ };
15
+ const getLastOwnerId = async (options) => {
16
+ const item = await deps.secureStorage.getItem(AUTH_METAKEY_LAST_OWNER, {
17
+ ...AUTH_DEFAULT_OPTIONS,
18
+ ...options,
19
+ accessControl: "none",
20
+ });
21
+ return item?.value;
22
+ };
23
+ const getOwnerNames = async (options) => {
24
+ const item = await deps.secureStorage.getItem(AUTH_METAKEY_OWNER_NAMES, {
25
+ ...AUTH_DEFAULT_OPTIONS,
26
+ ...options,
27
+ accessControl: "none",
28
+ });
29
+ let names = {};
30
+ if (item?.value) {
31
+ names = JSON.parse(item.value);
32
+ }
33
+ return names;
34
+ };
35
+ const setOwnerName = async (id, username, options) => {
36
+ const names = await getOwnerNames(options);
37
+ names[id] = username;
38
+ await deps.secureStorage.setItem(AUTH_METAKEY_OWNER_NAMES, JSON.stringify(names), {
39
+ ...AUTH_DEFAULT_OPTIONS,
40
+ ...options,
41
+ accessControl: "none",
42
+ });
43
+ };
44
+ const deleteOwnerName = async (id, options) => {
45
+ const { [id]: _, ...names } = await getOwnerNames(options);
46
+ await deps.secureStorage.setItem(AUTH_METAKEY_OWNER_NAMES, JSON.stringify(names), {
47
+ ...AUTH_DEFAULT_OPTIONS,
48
+ ...options,
49
+ accessControl: "none",
50
+ });
51
+ };
52
+ const getOwnerIds = async (options) => {
53
+ const items = await deps.secureStorage.getAllItems({
54
+ ...AUTH_DEFAULT_OPTIONS,
55
+ ...options,
56
+ includeValues: false,
57
+ });
58
+ return items
59
+ .filter(Boolean)
60
+ .filter((i) => i.key !== AUTH_METAKEY_LAST_OWNER &&
61
+ i.key !== AUTH_METAKEY_OWNER_NAMES)
62
+ .map((i) => i.key);
63
+ };
64
+ const clearAuthStore = (options) => deps.secureStorage.clearService({
65
+ ...AUTH_DEFAULT_OPTIONS,
66
+ ...options,
67
+ });
68
+ return {
69
+ login: async (ownerId, options) => {
70
+ // Use either specified owner or the last owner used during registration/login.
71
+ const targetOwnerId = ownerId ?? (await getLastOwnerId(options));
72
+ if (!targetOwnerId)
73
+ return null;
74
+ // Lookup the associated username
75
+ const names = await getOwnerNames(options);
76
+ const username = names[targetOwnerId] ?? "";
77
+ // If a reload is needed, avoid authentication, it needs to be handled on next page load.
78
+ // We set the last owner so we know what the target is.
79
+ // It is the applications's responsibility to reload and trigger login.
80
+ if (options?.reloadNeeded) {
81
+ await setLastOwnerId(targetOwnerId, options);
82
+ return { owner: undefined, username };
83
+ }
84
+ // Retrieve and decrypt the owner (this will trigger device authentication)
85
+ const account = await deps.secureStorage.getItem(targetOwnerId, {
86
+ ...AUTH_DEFAULT_OPTIONS,
87
+ ...options,
88
+ });
89
+ if (!account?.value)
90
+ return null;
91
+ // Unserialize the values (TODO: save these as base64 instead of json serializing)
92
+ const result = JSON.parse(account.value);
93
+ const writeKey = OwnerWriteKey.orThrow(new Uint8Array(Object.values(result.owner.writeKey)));
94
+ const encryptionKey = OwnerEncryptionKey.orThrow(new Uint8Array(Object.values(result.owner.encryptionKey)));
95
+ const owner = { ...result.owner, writeKey, encryptionKey };
96
+ // Update the last owner for future login attempts
97
+ await setLastOwnerId(targetOwnerId, options);
98
+ // Return the owner and associated username
99
+ return { owner, username };
100
+ },
101
+ register: async (username, options) => {
102
+ // Create an owner with a new secret or use specified mnemonic
103
+ const owner = createAppOwner(options?.mnemonic
104
+ ? mnemonicToOwnerSecret(options.mnemonic)
105
+ : createOwnerSecret(deps));
106
+ // Store owner, associated username, and update last owner
107
+ await Promise.all([
108
+ // setOwnerItem
109
+ deps.secureStorage.setItem(owner.id, JSON.stringify({ owner }), {
110
+ ...AUTH_DEFAULT_OPTIONS,
111
+ webAuthnUsername: username,
112
+ ...options,
113
+ }),
114
+ setOwnerName(owner.id, username, options),
115
+ setLastOwnerId(owner.id, options),
116
+ ]);
117
+ // Return the owner and associated username
118
+ return { owner, username };
119
+ },
120
+ unregister: async (ownerId, options) => {
121
+ // Delete the owner and associated username
122
+ await Promise.all([
123
+ // deleteOwnerItem
124
+ deps.secureStorage.deleteItem(ownerId, {
125
+ ...AUTH_DEFAULT_OPTIONS,
126
+ ...options,
127
+ }),
128
+ deleteOwnerName(ownerId, options),
129
+ ]);
130
+ // If the owner was the last owner then set to
131
+ // the next owner based on metadata timestamp
132
+ const lastOwnerId = await getLastOwnerId(options);
133
+ if (lastOwnerId === ownerId) {
134
+ const ids = await getOwnerIds(options);
135
+ if (ids.length > 0) {
136
+ await setLastOwnerId(ids[0], options);
137
+ }
138
+ }
139
+ },
140
+ getProfiles: async (options) => {
141
+ // Get all owner ids and associated usernames
142
+ const [ids, names] = await Promise.all([
143
+ getOwnerIds(options),
144
+ getOwnerNames(options),
145
+ ]);
146
+ // Return the list of profiles (usually used for login UX)
147
+ return ids.map((ownerId) => ({
148
+ ownerId,
149
+ username: names[ownerId] ?? "",
150
+ }));
151
+ },
152
+ clearAll: async (options) => {
153
+ // Delete all owners and associated metadata (scoped to the service)
154
+ await clearAuthStore(options);
155
+ },
156
+ };
157
+ };
158
+ // TOHO: With `const`, we don't need UPPER_CASE
159
+ export const AUTH_NAMESPACE = "evolu";
160
+ export const AUTH_METAKEY_LAST_OWNER = "_last_owner";
161
+ export const AUTH_METAKEY_OWNER_NAMES = "_owner_names";
162
+ export const AUTH_DEFAULT_OPTIONS = {
163
+ service: AUTH_NAMESPACE,
164
+ keychainGroup: AUTH_NAMESPACE,
165
+ androidBiometricsStrongOnly: true,
166
+ iosSynchronizable: true,
167
+ webAuthnUsername: "Evolu User",
168
+ authenticationPrompt: {
169
+ title: "Authenticate to unlock your session",
170
+ },
171
+ };
@@ -1,79 +1,108 @@
1
+ import { NonEmptyReadonlyArray } from "../Array.js";
2
+ import { EncryptionKey, RandomBytesDep } from "../Crypto.js";
3
+ import { Mnemonic, NonNegativeInt } from "../Type.js";
1
4
  /**
2
- * Evolu Owner - Data Ownership and Collaboration
3
- *
4
- * An {@link Owner} is an entity that represents ownership of data in Evolu. It
5
- * consists of cryptographic keys derived from a {@link Mnemonic} via SLIP-21:
6
- *
7
- * - **{@link OwnerId}**: Globally unique public identifier
8
- * - **{@link EncryptionKey}**: Symmetric encryption key for data protection
9
- * - **{@link WriteKey}**: Authentication token for write operations
5
+ * 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
10
6
  *
11
- * Every Evolu app has at least one owner, the {@link AppOwner}. There are
12
- * several owner variants for different use cases:
7
+ * Can be created using {@link createOwnerSecret} or converted from a
8
+ * {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
9
+ */
10
+ export declare const OwnerSecret: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("../Type.js").LengthError<32>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "OwnerSecret", import("../Type.js").BrandWithoutRefineError<"OwnerSecret", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>, never>;
11
+ export type OwnerSecret = typeof OwnerSecret.Type;
12
+ /** Creates a {@link OwnerSecret}. */
13
+ export declare const createOwnerSecret: (deps: RandomBytesDep) => OwnerSecret;
14
+ /** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
15
+ export declare const ownerSecretToMnemonic: (secret: OwnerSecret) => Mnemonic;
16
+ /** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
17
+ export declare const mnemonicToOwnerSecret: (mnemonic: Mnemonic) => OwnerSecret;
18
+ /**
19
+ * The Owner represents ownership of data in Evolu. Every database change is
20
+ * assigned to an owner, enabling sync functionality and access control.
13
21
  *
14
- * **{@link ShardOwner}**: Derived from {@link AppOwner} for partitioning data and
15
- * selective synchronization using {@link createShardOwner}
22
+ * Owners enable **partial sync** - applications can choose which owners to
23
+ * sync, allowing selective data synchronization based on specific needs.
16
24
  *
17
- * **{@link SharedOwner}**: Created for collaboration with write access, not
18
- * meant to be shared directly
25
+ * Owners also provide **real data deletion** - while individual changes in
26
+ * local-first/distributed systems can only be marked as deleted, entire owners
27
+ * can be completely deleted from both relays and devices (except for
28
+ * {@link AppOwner}, which must be preserved for sync coordination).
19
29
  *
20
- * **{@link SharedReadonlyOwner}**: Read-only version for safe data sharing,
21
- * created from {@link SharedOwner} using {@link createSharedReadonlyOwner}
30
+ * Evolu provides different owner types depending on their use case:
22
31
  *
23
- * Owners are designed for data synchronization and backup. Authentication
24
- * systems built on public/private key cryptography use these primitives. This
25
- * design ensures Evolu Relay knows as little as possible - it only sees
26
- * Timestamp, OwnerId, and EncryptedDbChange.
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
27
38
  *
28
- * @module
29
- */
30
- import { NonEmptyReadonlyArray } from "../Array.js";
31
- import { CreateMnemonicDep, CreateRandomBytesDep, EncryptionKey, MnemonicSeed } from "../Crypto.js";
32
- import { Mnemonic, NonNegativeInt } from "../Type.js";
33
- /**
34
- * Represents ownership of data in Evolu. Created from a {@link Mnemonic} via
35
- * SLIP-21 key derivation using {@link createOwner}, providing cryptographic keys
36
- * for data access and authentication.
39
+ * Owners are cryptographically derived from an {@link OwnerSecret} using
40
+ * SLIP-21, ensuring secure and deterministic key generation:
37
41
  *
38
42
  * - {@link OwnerId}: Globally unique public identifier
39
43
  * - {@link EncryptionKey}: Symmetric encryption key for data protection
40
- * - {@link WriteKey}: Authentication token for write operations (rotatable)
44
+ * - {@link OwnerWriteKey}: Authentication token for write operations (rotatable)
45
+ *
46
+ * @see {@link createOwner}
41
47
  */
42
48
  export interface Owner {
43
49
  readonly id: OwnerId;
44
- readonly encryptionKey: EncryptionKey;
45
- readonly writeKey: WriteKey;
50
+ readonly encryptionKey: OwnerEncryptionKey;
51
+ readonly writeKey: OwnerWriteKey;
46
52
  }
47
53
  /**
48
- * The unique identifier of {@link Owner} derived from the {@link Mnemonic}.
49
- *
50
- * This branded {@link Id} type, generated by {@link createSlip21Id}, is a
51
- * 21-character {@link Base64Url} string (126 bits of entropy), providing a
52
- * compact, shareable, and secure identifier for UI use, tied to the owner's
53
- * mnemonic and derivation path.
54
+ * OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}.
55
+ * Branded from {@link Id} to leverage existing helpers like {@link idToIdBytes}.
54
56
  */
55
- 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").RegexError<"Id">, import("../Type.js").StringError>, "OwnerId", import("../Type.js").BrandWithoutRefineError<"OwnerId", import("../Type.js").StringError | import("../Type.js").RegexError<"Id">>, never>;
57
+ 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>;
56
58
  export type OwnerId = typeof OwnerId.Type;
57
- export declare const writeKeyLength: NonNegativeInt;
59
+ /** Bytes representation of {@link OwnerId}. */
60
+ 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>;
61
+ export type OwnerIdBytes = typeof OwnerIdBytes.Type;
62
+ export declare const ownerIdToOwnerIdBytes: (ownerId: OwnerId) => OwnerIdBytes;
63
+ export declare const ownerIdBytesToOwnerId: (ownerIdBytes: OwnerIdBytes) => OwnerId;
64
+ export declare const ownerWriteKeyLength: NonNegativeInt;
65
+ export declare const OwnerEncryptionKey: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("../Type.js").LengthError<32>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "EncryptionKey", import("../Type.js").BrandWithoutRefineError<"EncryptionKey", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>, never>, "OwnerEncryptionKey", import("../Type.js").BrandWithoutRefineError<"OwnerEncryptionKey", import("../Type.js").BrandWithoutRefineError<"EncryptionKey", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>>, never>;
66
+ export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Type;
58
67
  /**
59
- * A secure token proving that the initiator can write changes. Derived from a
60
- * mnemonic or randomly generated via {@link createWriteKey}. It is rotatable.
68
+ * A secure token for write operations. It's derived from {@link OwnerSecret} by
69
+ * default and can be rotated via {@link createOwnerWriteKey}.
61
70
  */
62
- export declare const WriteKey: 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>, `Length${number & import("../Brand.js").Brand<"Int"> & import("../Brand.js").Brand<"NonNegative">}`, import("../Type.js").LengthError<number & import("../Brand.js").Brand<"Int"> & import("../Brand.js").Brand<"NonNegative">>, import("../Type.js").Uint8ArrayError>, "WriteKey", import("../Type.js").BrandWithoutRefineError<"WriteKey", import("../Type.js").Uint8ArrayError | import("../Type.js").LengthError<number & import("../Brand.js").Brand<"Int"> & import("../Brand.js").Brand<"NonNegative">>>, never>;
63
- export type WriteKey = typeof WriteKey.Type;
64
- /** Creates a randomly generated {@link WriteKey}. */
65
- export declare const createWriteKey: (deps: CreateRandomBytesDep) => WriteKey;
66
- /** Creates an {@link Owner} from a {@link Mnemonic} using SLIP-21 key derivation. */
67
- export declare const createOwner: (mnemonic: Mnemonic) => Owner;
71
+ export declare const OwnerWriteKey: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length16", import("../Type.js").LengthError<16>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "OwnerWriteKey", import("../Type.js").BrandWithoutRefineError<"OwnerWriteKey", import("../Type.js").LengthError<16> | import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, never>;
72
+ export type OwnerWriteKey = typeof OwnerWriteKey.Type;
73
+ /** Creates a randomly generated {@link OwnerWriteKey}. */
74
+ export declare const createOwnerWriteKey: (deps: RandomBytesDep) => OwnerWriteKey;
68
75
  /**
69
- * Creates an {@link Owner} from a {@link MnemonicSeed} using SLIP-21 key
76
+ * Creates an {@link Owner} from a {@link OwnerSecret} using SLIP-21 key
70
77
  * derivation.
78
+ *
79
+ * This is an internal helper function, use:
80
+ *
81
+ * - {@link createAppOwner}
82
+ * - {@link createShardOwner}
83
+ * - {@link createSharedOwner}
84
+ * - {@link createSharedReadonlyOwner}
71
85
  */
72
- export declare const createOwnerFromMnemonicSeed: (seed: MnemonicSeed) => Owner;
86
+ export declare const createOwner: (secret: OwnerSecret) => Owner;
73
87
  /**
74
- * The owner representing app data. Can be created from a {@link Mnemonic} or
75
- * from external keys when the mnemonic should not be shared with the Evolu
76
- * app.
88
+ * The AppOwner represents the application owner. It's created using a
89
+ * cryptographically secure random generator or derived from an external source,
90
+ * e.g., mnemonic stored securely in a hardware device.
91
+ *
92
+ * While it's possible to store all application data in AppOwner, the better
93
+ * approach is to use it only for sync coordination. Storing all app data in
94
+ * AppOwner means that data will be stored/synced forever. And that's a problem
95
+ * if we want to provide real data deletion or in-app data migration without
96
+ * data duplication. In local-first apps/distributed systems, we can't delete
97
+ * individual changes, we only mark them as deleted, otherwise sync could not
98
+ * work.
99
+ *
100
+ * If we really want to delete data or at least avoid syncing it, we must store
101
+ * it using a different owner than AppOwner, e.g. {@link ShardOwner} or
102
+ * {@link SharedOwner}, and delete that owner. The AppOwner itself must be
103
+ * preserved because it coordinates deletion information across devices. Other
104
+ * devices need to sync the information that an owner was deleted so they can
105
+ * delete their local data as well.
77
106
  */
78
107
  export interface AppOwner extends Owner {
79
108
  readonly type: "AppOwner";
@@ -84,41 +113,62 @@ export interface AppOwner extends Owner {
84
113
  */
85
114
  readonly mnemonic?: Mnemonic | null;
86
115
  }
87
- export declare const createAppOwner: (mnemonic: Mnemonic) => AppOwner;
116
+ /** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
117
+ export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
118
+ export type TransportConfig = WebSocketTransportConfig;
119
+ export interface WebSocketTransportConfig {
120
+ readonly type: "WebSocket";
121
+ readonly url: string;
122
+ }
88
123
  /**
89
- * Owner for sharding app data. Allows partitioning of database changes for
90
- * selective synchronization.
124
+ * An {@link Owner} for sharding data.
125
+ *
126
+ * ShardOwners are the recommended storage location for most application data
127
+ * because they can be completely deleted (both on relays and devices) and
128
+ * conditionally synced.
129
+ *
130
+ * Can be created from {@link OwnerSecret} via {@link createShardOwner} or
131
+ * deterministically derived from {@link AppOwner} using
132
+ * {@link deriveShardOwner}.
91
133
  */
92
134
  export interface ShardOwner extends Owner {
93
135
  readonly type: "ShardOwner";
136
+ readonly transports?: ReadonlyArray<TransportConfig>;
94
137
  }
138
+ /** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
139
+ export declare const createShardOwner: (secret: OwnerSecret, transports?: ReadonlyArray<TransportConfig>) => ShardOwner;
95
140
  /**
96
- * Creates a {@link ShardOwner} derived from an {@link AppOwner} using the
97
- * specified path.
98
- *
99
- * ### Example
100
- *
101
- * ```ts
102
- * const contactsShard = createShardOwner(appOwner, ["contacts"]);
103
- * const projectShard = createShardOwner(appOwner, [
104
- * "projects",
105
- * "project-1",
106
- * ]);
107
- * ```
108
- */
109
- export declare const createShardOwner: (appOwner: AppOwner, path: NonEmptyReadonlyArray<string>) => ShardOwner;
110
- /**
111
- * Owner for collaborative data with write access. Created by a user for their
112
- * own use, not meant to be shared directly. To share data, use
113
- * {@link createSharedReadonlyOwner} to create a {@link SharedReadonlyOwner} for
114
- * read-only access.
141
+ * Derives a {@link ShardOwner} from an {@link AppOwner} using the specified path.
142
+ *
143
+ * **Advantages of derived owners:**
144
+ *
145
+ * - **Deterministic**: Same path always produces the same ShardOwner across all
146
+ * devices
147
+ * - **Immediate availability**: Can be hardcoded and used before sync occurs
148
+ * - **Consistent setup**: All devices start with identical data structure
149
+ * - **Lifecycle management**: Can implement epoch patterns for clean data
150
+ * deletion and recreation
151
+ *
152
+ * **Common patterns:**
153
+ *
154
+ * - Use paths like `["shard", 1]` for versioned data lifecycle
155
+ * - Use paths like `["project", "MyApp", 1]` for named partitions with versions
156
+ * - Each device can derive the same owners and set up initial structure
115
157
  */
158
+ export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number>, transports?: ReadonlyArray<TransportConfig>) => ShardOwner;
159
+ /** An {@link Owner} for collaborative data with write access. */
116
160
  export interface SharedOwner extends Owner {
117
161
  readonly type: "SharedOwner";
118
- readonly mnemonic: Mnemonic;
162
+ readonly transports?: ReadonlyArray<TransportConfig>;
119
163
  }
120
- /** Creates a {@link SharedOwner} with a freshly generated {@link Mnemonic}. */
121
- export declare const createSharedOwner: (deps: CreateMnemonicDep) => SharedOwner;
164
+ /**
165
+ * Creates a {@link SharedOwner} from an {@link OwnerSecret} for collaborative
166
+ * write access.
167
+ *
168
+ * Use {@link createSharedReadonlyOwner} to create a read-only version for
169
+ * sharing.
170
+ */
171
+ export declare const createSharedOwner: (secret: OwnerSecret, transports?: ReadonlyArray<TransportConfig>) => SharedOwner;
122
172
  /**
123
173
  * Read-only version of a {@link SharedOwner} for data sharing. Contains only the
124
174
  * {@link OwnerId} and {@link EncryptionKey} needed for others to read the shared
@@ -128,12 +178,8 @@ export interface SharedReadonlyOwner {
128
178
  readonly type: "SharedReadonlyOwner";
129
179
  readonly id: OwnerId;
130
180
  readonly encryptionKey: EncryptionKey;
181
+ readonly transports?: ReadonlyArray<TransportConfig>;
131
182
  }
132
183
  /** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
133
184
  export declare const createSharedReadonlyOwner: (sharedOwner: SharedOwner) => SharedReadonlyOwner;
134
- /**
135
- * Rotates the {@link WriteKey} for an {@link AppOwner}, {@link ShardOwner}, or
136
- * {@link SharedOwner}, returning a new instance with the updated key.
137
- */
138
- export declare const rotateWriteKey: <T extends AppOwner | ShardOwner | SharedOwner>(owner: T, newWriteKey: WriteKey) => T;
139
185
  //# sourceMappingURL=Owner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Owner.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EAGpB,aAAa,EACb,YAAY,EAEb,MAAM,cAAc,CAAC;AACtB,OAAO,EAKL,QAAQ,EACR,cAAc,EAEf,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,qaAAuB,CAAC;AAC5C,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC;AAE1C,eAAO,MAAM,cAAc,EAAS,cAAc,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,QAAQ,mwBAAwD,CAAC;AAC9E,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC;AAE5C,qDAAqD;AACrD,eAAO,MAAM,cAAc,GAAI,MAAM,oBAAoB,KAAG,QACT,CAAC;AAEpD,qFAAqF;AACrF,eAAO,MAAM,WAAW,GAAI,UAAU,QAAQ,KAAG,KAGhD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,YAAY,KAAG,KAS/D,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,QAAS,SAAQ,KA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