@evolu/common 8.9.0 → 8.11.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/Bytes.d.ts +647 -0
- package/dist/src/Bytes.d.ts.map +1 -0
- package/dist/src/{Binary.js → Bytes.js} +266 -16
- package/dist/src/Config.d.ts +142 -0
- package/dist/src/Config.d.ts.map +1 -0
- package/dist/src/Config.js +181 -0
- package/dist/src/Console.d.ts +62 -7
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +20 -4
- package/dist/src/Crypto.d.ts +76 -4
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +55 -4
- package/dist/src/Error.d.ts +45 -0
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +69 -0
- package/dist/src/Fs.d.ts +376 -0
- package/dist/src/Fs.d.ts.map +1 -0
- package/dist/src/Fs.js +113 -0
- package/dist/src/Identicon.d.ts +2 -2
- package/dist/src/Identicon.js +2 -2
- package/dist/src/LeakDetector.d.ts +22 -3
- package/dist/src/LeakDetector.d.ts.map +1 -1
- package/dist/src/LeakDetector.js +12 -2
- package/dist/src/LockManager.d.ts +8 -0
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +6 -0
- package/dist/src/Number.d.ts +50 -7
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +47 -8
- package/dist/src/Object.d.ts +32 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +46 -0
- package/dist/src/Platform.d.ts +47 -7
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +24 -5
- package/dist/src/Random.d.ts +25 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +14 -2
- package/dist/src/Resource.d.ts +156 -1
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +201 -72
- package/dist/src/Schedule.d.ts +11 -10
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +1 -1
- package/dist/src/Sqlite.d.ts +132 -16
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +64 -10
- package/dist/src/Task.d.ts +15 -4
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +41 -15
- package/dist/src/Test.d.ts +9 -0
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +4 -0
- package/dist/src/Time.d.ts +179 -20
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +95 -6
- package/dist/src/Type.d.ts +3056 -1539
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +2548 -584
- package/dist/src/WebSocket.d.ts +164 -13
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +133 -24
- package/dist/src/Worker.d.ts +90 -8
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +28 -2
- package/dist/src/index.d.ts +9 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -4
- package/dist/src/intl/_en.d.ts +24 -1
- package/dist/src/intl/_en.d.ts.map +1 -1
- package/dist/src/intl/_en.js +20 -0
- package/dist/src/intl/ar.d.ts +24 -1
- package/dist/src/intl/ar.d.ts.map +1 -1
- package/dist/src/intl/ar.js +20 -0
- package/dist/src/intl/bn.d.ts +24 -1
- package/dist/src/intl/bn.d.ts.map +1 -1
- package/dist/src/intl/bn.js +20 -0
- package/dist/src/intl/ca.d.ts +24 -1
- package/dist/src/intl/ca.d.ts.map +1 -1
- package/dist/src/intl/ca.js +20 -0
- package/dist/src/intl/cs.d.ts +24 -1
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +20 -0
- package/dist/src/intl/da.d.ts +24 -1
- package/dist/src/intl/da.d.ts.map +1 -1
- package/dist/src/intl/da.js +20 -0
- package/dist/src/intl/de.d.ts +24 -1
- package/dist/src/intl/de.d.ts.map +1 -1
- package/dist/src/intl/de.js +20 -0
- package/dist/src/intl/el.d.ts +24 -1
- package/dist/src/intl/el.d.ts.map +1 -1
- package/dist/src/intl/el.js +20 -0
- package/dist/src/intl/es.d.ts +24 -1
- package/dist/src/intl/es.d.ts.map +1 -1
- package/dist/src/intl/es.js +20 -0
- package/dist/src/intl/fa.d.ts +24 -1
- package/dist/src/intl/fa.d.ts.map +1 -1
- package/dist/src/intl/fa.js +20 -0
- package/dist/src/intl/fi.d.ts +24 -1
- package/dist/src/intl/fi.d.ts.map +1 -1
- package/dist/src/intl/fi.js +20 -0
- package/dist/src/intl/fil.d.ts +24 -1
- package/dist/src/intl/fil.d.ts.map +1 -1
- package/dist/src/intl/fil.js +20 -0
- package/dist/src/intl/fr.d.ts +24 -1
- package/dist/src/intl/fr.d.ts.map +1 -1
- package/dist/src/intl/fr.js +20 -0
- package/dist/src/intl/he.d.ts +24 -1
- package/dist/src/intl/he.d.ts.map +1 -1
- package/dist/src/intl/he.js +20 -0
- package/dist/src/intl/hi.d.ts +24 -1
- package/dist/src/intl/hi.d.ts.map +1 -1
- package/dist/src/intl/hi.js +20 -0
- package/dist/src/intl/hr.d.ts +24 -1
- package/dist/src/intl/hr.d.ts.map +1 -1
- package/dist/src/intl/hr.js +20 -0
- package/dist/src/intl/hu.d.ts +22 -1
- package/dist/src/intl/hu.d.ts.map +1 -1
- package/dist/src/intl/hu.js +18 -0
- package/dist/src/intl/id.d.ts +24 -1
- package/dist/src/intl/id.d.ts.map +1 -1
- package/dist/src/intl/id.js +20 -0
- package/dist/src/intl/it.d.ts +24 -1
- package/dist/src/intl/it.d.ts.map +1 -1
- package/dist/src/intl/it.js +20 -0
- package/dist/src/intl/ja.d.ts +24 -1
- package/dist/src/intl/ja.d.ts.map +1 -1
- package/dist/src/intl/ja.js +20 -0
- package/dist/src/intl/ko.d.ts +24 -1
- package/dist/src/intl/ko.d.ts.map +1 -1
- package/dist/src/intl/ko.js +20 -0
- package/dist/src/intl/ml.d.ts +24 -1
- package/dist/src/intl/ml.d.ts.map +1 -1
- package/dist/src/intl/ml.js +20 -0
- package/dist/src/intl/mr.d.ts +24 -1
- package/dist/src/intl/mr.d.ts.map +1 -1
- package/dist/src/intl/mr.js +20 -0
- package/dist/src/intl/ms.d.ts +24 -1
- package/dist/src/intl/ms.d.ts.map +1 -1
- package/dist/src/intl/ms.js +20 -0
- package/dist/src/intl/nb.d.ts +22 -1
- package/dist/src/intl/nb.d.ts.map +1 -1
- package/dist/src/intl/nb.js +18 -0
- package/dist/src/intl/nl.d.ts +24 -1
- package/dist/src/intl/nl.d.ts.map +1 -1
- package/dist/src/intl/nl.js +20 -0
- package/dist/src/intl/pa.d.ts +24 -1
- package/dist/src/intl/pa.d.ts.map +1 -1
- package/dist/src/intl/pa.js +20 -0
- package/dist/src/intl/pl.d.ts +23 -0
- package/dist/src/intl/pl.d.ts.map +1 -1
- package/dist/src/intl/pl.js +20 -0
- package/dist/src/intl/pt-BR.d.ts +24 -1
- package/dist/src/intl/pt-BR.d.ts.map +1 -1
- package/dist/src/intl/pt-BR.js +20 -0
- package/dist/src/intl/pt.d.ts +24 -1
- package/dist/src/intl/pt.d.ts.map +1 -1
- package/dist/src/intl/pt.js +20 -0
- package/dist/src/intl/ro.d.ts +24 -1
- package/dist/src/intl/ro.d.ts.map +1 -1
- package/dist/src/intl/ro.js +20 -0
- package/dist/src/intl/sk.d.ts +24 -1
- package/dist/src/intl/sk.d.ts.map +1 -1
- package/dist/src/intl/sk.js +20 -0
- package/dist/src/intl/sl.d.ts +24 -1
- package/dist/src/intl/sl.d.ts.map +1 -1
- package/dist/src/intl/sl.js +20 -0
- package/dist/src/intl/sv.d.ts +24 -1
- package/dist/src/intl/sv.d.ts.map +1 -1
- package/dist/src/intl/sv.js +20 -0
- package/dist/src/intl/sw.d.ts +21 -0
- package/dist/src/intl/sw.d.ts.map +1 -1
- package/dist/src/intl/sw.js +18 -0
- package/dist/src/intl/ta.d.ts +24 -1
- package/dist/src/intl/ta.d.ts.map +1 -1
- package/dist/src/intl/ta.js +20 -0
- package/dist/src/intl/te.d.ts +24 -1
- package/dist/src/intl/te.d.ts.map +1 -1
- package/dist/src/intl/te.js +20 -0
- package/dist/src/intl/th.d.ts +24 -1
- package/dist/src/intl/th.d.ts.map +1 -1
- package/dist/src/intl/th.js +20 -0
- package/dist/src/intl/tr.d.ts +24 -1
- package/dist/src/intl/tr.d.ts.map +1 -1
- package/dist/src/intl/tr.js +20 -0
- package/dist/src/intl/uk.d.ts +80 -57
- package/dist/src/intl/uk.d.ts.map +1 -1
- package/dist/src/intl/uk.js +174 -149
- package/dist/src/intl/ur.d.ts +24 -1
- package/dist/src/intl/ur.d.ts.map +1 -1
- package/dist/src/intl/ur.js +20 -0
- package/dist/src/intl/vi.d.ts +24 -1
- package/dist/src/intl/vi.d.ts.map +1 -1
- package/dist/src/intl/vi.js +20 -0
- package/dist/src/intl/zh-CN.d.ts +24 -1
- package/dist/src/intl/zh-CN.d.ts.map +1 -1
- package/dist/src/intl/zh-CN.js +20 -0
- package/dist/src/intl/zh-TW.d.ts +24 -1
- package/dist/src/intl/zh-TW.d.ts.map +1 -1
- package/dist/src/intl/zh-TW.js +20 -0
- package/dist/src/local-first/Db.d.ts +52 -3
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +412 -137
- package/dist/src/local-first/Evolu.d.ts +336 -211
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +102 -15
- package/dist/src/local-first/Owner.d.ts +13 -30
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +13 -30
- package/dist/src/local-first/Protocol.d.ts +95 -17
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +119 -39
- package/dist/src/local-first/Query.d.ts +8 -15
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Schema.d.ts +345 -21
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +214 -17
- package/dist/src/local-first/Shared.d.ts +537 -22
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +1437 -234
- package/dist/src/local-first/Storage.d.ts +192 -14
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +82 -21
- package/dist/src/local-first/Timestamp.d.ts +392 -41
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +404 -82
- package/dist/src/local-first/index.d.ts +0 -1
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +0 -1
- package/package.json +1 -1
- package/src/Assert.test.ts +2 -5
- package/src/{Binary.test.ts → Bytes.test.ts} +286 -1
- package/src/{Binary.ts → Bytes.ts} +652 -21
- package/src/Config.test.ts +668 -0
- package/src/Config.ts +410 -0
- package/src/Console.ts +62 -7
- package/src/Crypto.ts +76 -4
- package/src/Eq.test.ts +2 -3
- package/src/Error.test.ts +76 -3
- package/src/Error.ts +71 -0
- package/src/Fs.test.ts +105 -0
- package/src/Fs.ts +488 -0
- package/src/Identicon.ts +2 -2
- package/src/LeakDetector.ts +22 -3
- package/src/LockManager.ts +8 -0
- package/src/Number.test.ts +82 -18
- package/src/Number.ts +76 -8
- package/src/Object.test.ts +139 -10
- package/src/Object.ts +49 -0
- package/src/Platform.ts +50 -8
- package/src/Random.ts +25 -2
- package/src/Resource.test.ts +837 -0
- package/src/Resource.ts +235 -15
- package/src/Schedule.test.ts +50 -12
- package/src/Schedule.ts +24 -14
- package/src/Sqlite.ts +138 -18
- package/src/Task.test.ts +189 -8
- package/src/Task.ts +56 -17
- package/src/Test.ts +9 -0
- package/src/Time.test.ts +82 -11
- package/src/Time.ts +246 -24
- package/src/Type.test.ts +3994 -1119
- package/src/Type.ts +7258 -3842
- package/src/Types.test.ts +4 -14
- package/src/WebSocket.ts +313 -40
- package/src/Worker.ts +90 -8
- package/src/index.ts +18 -7
- package/src/intl/_en.ts +70 -0
- package/src/intl/ar.ts +71 -0
- package/src/intl/bn.ts +70 -0
- package/src/intl/ca.ts +70 -0
- package/src/intl/cs.ts +70 -0
- package/src/intl/da.ts +70 -0
- package/src/intl/de.ts +70 -0
- package/src/intl/el.ts +70 -0
- package/src/intl/es.ts +70 -0
- package/src/intl/fa.ts +70 -0
- package/src/intl/fi.ts +70 -0
- package/src/intl/fil.ts +70 -0
- package/src/intl/fr.ts +70 -0
- package/src/intl/he.ts +70 -0
- package/src/intl/hi.ts +70 -0
- package/src/intl/hr.ts +70 -0
- package/src/intl/hu.ts +69 -0
- package/src/intl/id.ts +70 -0
- package/src/intl/intl.test.ts +819 -1
- package/src/intl/it.ts +70 -0
- package/src/intl/ja.ts +70 -0
- package/src/intl/ko.ts +68 -0
- package/src/intl/ml.ts +70 -0
- package/src/intl/mr.ts +70 -0
- package/src/intl/ms.ts +71 -0
- package/src/intl/nb.ts +69 -0
- package/src/intl/nl.ts +70 -0
- package/src/intl/pa.ts +70 -0
- package/src/intl/pl.ts +63 -0
- package/src/intl/pt-BR.ts +70 -0
- package/src/intl/pt.ts +71 -0
- package/src/intl/ro.ts +70 -0
- package/src/intl/sk.ts +71 -0
- package/src/intl/sl.ts +70 -0
- package/src/intl/sv.ts +70 -0
- package/src/intl/sw.ts +62 -0
- package/src/intl/ta.ts +70 -0
- package/src/intl/te.ts +70 -0
- package/src/intl/th.ts +68 -0
- package/src/intl/tr.ts +70 -0
- package/src/intl/uk.ts +228 -155
- package/src/intl/ur.ts +70 -0
- package/src/intl/vi.ts +70 -0
- package/src/intl/zh-CN.ts +68 -0
- package/src/intl/zh-TW.ts +68 -0
- package/src/local-first/Db.ts +644 -339
- package/src/local-first/Evolu.test.ts +686 -21
- package/src/local-first/Evolu.ts +450 -228
- package/src/local-first/Owner.ts +13 -30
- package/src/local-first/Protocol.test.ts +618 -11
- package/src/local-first/Protocol.ts +197 -73
- package/src/local-first/Query.ts +8 -15
- package/src/local-first/Schema.test.ts +143 -0
- package/src/local-first/Schema.ts +374 -24
- package/src/local-first/Shared.test.ts +7731 -559
- package/src/local-first/Shared.ts +2036 -267
- package/src/local-first/Storage.ts +219 -33
- package/src/local-first/Timestamp.test.ts +344 -70
- package/src/local-first/Timestamp.ts +435 -119
- package/src/local-first/index.ts +0 -1
- package/dist/src/Binary.d.ts +0 -254
- package/dist/src/Binary.d.ts.map +0 -1
- package/dist/src/local-first/Error.d.ts +0 -12
- package/dist/src/local-first/Error.d.ts.map +0 -1
- package/dist/src/local-first/Error.js +0 -6
- package/dist/src/local-first/LocalAuth.d.ts +0 -150
- package/dist/src/local-first/LocalAuth.d.ts.map +0 -1
- package/dist/src/local-first/LocalAuth.js +0 -179
- package/src/local-first/Error.ts +0 -17
- package/src/local-first/LocalAuth.ts +0 -457
package/dist/src/Binary.d.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Binary data handling and byte array utilities.
|
|
3
|
-
*
|
|
4
|
-
* Buffer-based decoding functions intentionally throw errors instead of
|
|
5
|
-
* returning {@link Result}. This is a deliberate micro-optimization for Evolu
|
|
6
|
-
* Protocol's hot paths: Result is inexpensive, but returning decoded values
|
|
7
|
-
* directly avoids its success-case allocation, and using `Error` objects
|
|
8
|
-
* preserves stack traces. In the future, we will try returning `Error` objects
|
|
9
|
-
* in `Result` values to measure the real-world performance impact.
|
|
10
|
-
*
|
|
11
|
-
* @module
|
|
12
|
-
*/
|
|
13
|
-
import { bytesToUtf8, utf8ToBytes } from "@noble/ciphers/utils.js";
|
|
14
|
-
import type { FiniteNumber, JsonValue, NonNegativeInt, PositiveInt } from "./Type.ts";
|
|
15
|
-
export { bytesToHex, concatBytes, hexToBytes } from "@noble/ciphers/utils.js";
|
|
16
|
-
export { bytesToUtf8, utf8ToBytes };
|
|
17
|
-
/**
|
|
18
|
-
* Custom error for {@link Buffer}-related failures like premature end of data.
|
|
19
|
-
* Provides better stack traces for debugging binary protocol issues.
|
|
20
|
-
*/
|
|
21
|
-
export declare class BufferError extends Error {
|
|
22
|
-
constructor(message: string);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A Buffer is a dynamic, resizable container for binary data, optimized for
|
|
26
|
-
* scenarios where the final size is unknown. It grows exponentially (doubling
|
|
27
|
-
* its capacity) to minimize memory reallocations and uses `subarray` for
|
|
28
|
-
* efficient, copy-free data access in methods like `unwrap` and `shift`.
|
|
29
|
-
*
|
|
30
|
-
* ## Recommended Usage
|
|
31
|
-
*
|
|
32
|
-
* Create as few Buffers as possible—typically one main Buffer for the final
|
|
33
|
-
* output. Temporary Buffers are allowed when necessary (e.g., for
|
|
34
|
-
* variable-length headers), but avoid excessive allocations. Buffers can be
|
|
35
|
-
* reused within functions by leveraging `reset` to clear contents while
|
|
36
|
-
* preserving capacity, or `truncate` to adjust the length to a specific size,
|
|
37
|
-
* reducing the need for new allocations. Pass Buffers to `encode*` functions to
|
|
38
|
-
* append serialized data and use `decode*` functions to extract data.
|
|
39
|
-
*
|
|
40
|
-
* ### Example
|
|
41
|
-
*
|
|
42
|
-
* ```ts
|
|
43
|
-
* import {
|
|
44
|
-
* assertEqual,
|
|
45
|
-
* assertErr,
|
|
46
|
-
* assertInstanceOf,
|
|
47
|
-
* createBuffer,
|
|
48
|
-
* createIdFromString,
|
|
49
|
-
* IdBytes,
|
|
50
|
-
* idBytesToId,
|
|
51
|
-
* idBytesTypeValueLength,
|
|
52
|
-
* idToIdBytes,
|
|
53
|
-
* NonNegativeInt,
|
|
54
|
-
* trySync,
|
|
55
|
-
* decodeNonNegativeInt,
|
|
56
|
-
* encodeNonNegativeInt,
|
|
57
|
-
* } from "@evolu/common";
|
|
58
|
-
*
|
|
59
|
-
* const buffer = createBuffer();
|
|
60
|
-
* const id = createIdFromString("buffer-example");
|
|
61
|
-
* encodeNonNegativeInt(buffer, NonNegativeInt.orThrow(300));
|
|
62
|
-
* buffer.extend(idToIdBytes(id));
|
|
63
|
-
*
|
|
64
|
-
* const decoder = createBuffer(buffer.unwrap());
|
|
65
|
-
* assertEqual(decodeNonNegativeInt(decoder), 300);
|
|
66
|
-
* const decodedId = idBytesToId(
|
|
67
|
-
* IdBytes.orThrow(decoder.shiftN(idBytesTypeValueLength)),
|
|
68
|
-
* );
|
|
69
|
-
* assertEqual(decodedId, id);
|
|
70
|
-
* const result = trySync(() => decodeNonNegativeInt(decoder));
|
|
71
|
-
* assertErr(result);
|
|
72
|
-
* assertInstanceOf(result.error, Error);
|
|
73
|
-
* assertEqual(result.error.message, "Buffer parse ended prematurely");
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* For more on exponential growth, see:
|
|
77
|
-
* https://blog.mozilla.org/nnethercote/2014/11/04/please-grow-your-buffers-exponentially
|
|
78
|
-
*/
|
|
79
|
-
export interface Buffer {
|
|
80
|
-
/** Returns the current capacity of the buffer. */
|
|
81
|
-
getCapacity: () => NonNegativeInt;
|
|
82
|
-
/** Returns the current number of bytes stored in the buffer. */
|
|
83
|
-
getLength: () => NonNegativeInt;
|
|
84
|
-
/**
|
|
85
|
-
* Appends binary data to the buffer, resizing if necessary. Throws if
|
|
86
|
-
* `arg.length` is not a non-negative safe integer.
|
|
87
|
-
*/
|
|
88
|
-
extend: (arg: Uint8Array | ArrayLike<number>) => void;
|
|
89
|
-
/**
|
|
90
|
-
* Removes and returns the first byte. Throws an `Error` with message "Buffer
|
|
91
|
-
* parse ended prematurely" if the buffer is empty.
|
|
92
|
-
*/
|
|
93
|
-
shift: () => NonNegativeInt;
|
|
94
|
-
/**
|
|
95
|
-
* Removes and returns the first `n` bytes. Throws an `Error` with message
|
|
96
|
-
* "Buffer parse ended prematurely" if fewer than `n` bytes remain.
|
|
97
|
-
*/
|
|
98
|
-
shiftN: (n: NonNegativeInt) => Uint8Array;
|
|
99
|
-
/**
|
|
100
|
-
* Truncates the buffer to the specified length, discarding data from the end.
|
|
101
|
-
* Throws if the new length is greater than the current length.
|
|
102
|
-
*/
|
|
103
|
-
truncate: (length: NonNegativeInt) => void;
|
|
104
|
-
/**
|
|
105
|
-
* Resets the buffer to its initial empty state, preserving its capacity.
|
|
106
|
-
*
|
|
107
|
-
* This allows efficient buffer reuse without reallocating memory. Use this
|
|
108
|
-
* when you want to clear the buffer and write new data, avoiding unnecessary
|
|
109
|
-
* allocations.
|
|
110
|
-
*/
|
|
111
|
-
reset: () => void;
|
|
112
|
-
/**
|
|
113
|
-
* Returns a view of the buffer’s current data. Do not modify this array, as
|
|
114
|
-
* it directly alters the buffer’s internal state, potentially breaking
|
|
115
|
-
* subsequent operations.
|
|
116
|
-
*/
|
|
117
|
-
unwrap: () => Uint8Array;
|
|
118
|
-
}
|
|
119
|
-
/** Creates a {@link Buffer} for efficient byte operations. */
|
|
120
|
-
export declare const createBuffer: (arrayLike?: Uint8Array | ArrayLike<number>) => Buffer;
|
|
121
|
-
/**
|
|
122
|
-
* Evolu uses MessagePack to handle finite numbers except for NonNegativeInt.
|
|
123
|
-
* For NonNegativeInt, Evolu provides more efficient encoding.
|
|
124
|
-
*/
|
|
125
|
-
export declare const encodeNumber: (buffer: Buffer, number: FiniteNumber) => void;
|
|
126
|
-
export declare const decodeNumber: (buffer: Buffer) => FiniteNumber;
|
|
127
|
-
/**
|
|
128
|
-
* Encodes an array of boolean flags into a single byte.
|
|
129
|
-
*
|
|
130
|
-
* Each element in the array corresponds to a bit (0-7). Array can have 0-8
|
|
131
|
-
* elements.
|
|
132
|
-
*
|
|
133
|
-
* ### Example
|
|
134
|
-
*
|
|
135
|
-
* ```ts
|
|
136
|
-
* import { assertEqual, createBuffer, encodeFlags } from "@evolu/common";
|
|
137
|
-
*
|
|
138
|
-
* const buffer = createBuffer();
|
|
139
|
-
* encodeFlags(buffer, [true, false, true]);
|
|
140
|
-
*
|
|
141
|
-
* assertEqual(buffer.unwrap(), new Uint8Array([0b101]));
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
export declare const encodeFlags: (buffer: Buffer, flags: ReadonlyArray<boolean>) => void;
|
|
145
|
-
/**
|
|
146
|
-
* Decodes a byte into an array of boolean flags.
|
|
147
|
-
*
|
|
148
|
-
* ### Example
|
|
149
|
-
*
|
|
150
|
-
* ```ts
|
|
151
|
-
* import {
|
|
152
|
-
* assertEqual,
|
|
153
|
-
* createBuffer,
|
|
154
|
-
* decodeFlags,
|
|
155
|
-
* PositiveInt,
|
|
156
|
-
* } from "@evolu/common";
|
|
157
|
-
*
|
|
158
|
-
* const buffer = createBuffer([0b101]);
|
|
159
|
-
* const flags = decodeFlags(buffer, PositiveInt.orThrow(3));
|
|
160
|
-
*
|
|
161
|
-
* assertEqual(flags, [true, false, true]);
|
|
162
|
-
* assertEqual(buffer.getLength(), 0);
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export declare const decodeFlags: (buffer: Buffer, count: PositiveInt) => ReadonlyArray<boolean>;
|
|
166
|
-
/**
|
|
167
|
-
* Encodes a non-negative integer into a variable-length integer format. It's
|
|
168
|
-
* more efficient than encoding via {@link encodeNumber}.
|
|
169
|
-
*
|
|
170
|
-
* https://en.wikipedia.org/wiki/Variable-length_quantity
|
|
171
|
-
*/
|
|
172
|
-
export declare const encodeNonNegativeInt: (buffer: Buffer, value: NonNegativeInt) => void;
|
|
173
|
-
/**
|
|
174
|
-
* Decodes a non-negative integer from a variable-length integer format.
|
|
175
|
-
*
|
|
176
|
-
* https://en.wikipedia.org/wiki/Variable-length_quantity
|
|
177
|
-
*/
|
|
178
|
-
export declare const decodeNonNegativeInt: (buffer: Buffer) => NonNegativeInt;
|
|
179
|
-
/** Encodes the length of an array-like value. */
|
|
180
|
-
export declare const encodeLength: (buffer: Buffer, value: ArrayLike<unknown>) => void;
|
|
181
|
-
/** Decodes an array-like value length. */
|
|
182
|
-
export declare const decodeLength: typeof decodeNonNegativeInt;
|
|
183
|
-
/** Encodes a length-prefixed UTF-8 string. */
|
|
184
|
-
export declare const encodeString: (buffer: Buffer, value: string) => void;
|
|
185
|
-
/** Decodes a length-prefixed UTF-8 string. */
|
|
186
|
-
export declare const decodeString: (buffer: Buffer) => string;
|
|
187
|
-
/** Incrementally encodes consecutive equal values using run-length encoding. */
|
|
188
|
-
export interface RunLengthEncoder<T> {
|
|
189
|
-
readonly add: (value: T) => void;
|
|
190
|
-
readonly getLength: () => NonNegativeInt;
|
|
191
|
-
readonly unwrap: () => Uint8Array;
|
|
192
|
-
}
|
|
193
|
-
/** Creates an incremental run-length encoder. */
|
|
194
|
-
export declare const createRunLengthEncoder: <T>(encodeValue: (buffer: Buffer, value: T) => void) => RunLengthEncoder<T>;
|
|
195
|
-
/** Decodes a run-length encoded sequence. */
|
|
196
|
-
export declare const decodeRle: <T>(buffer: Buffer, length: NonNegativeInt, decodeValue: () => T) => ReadonlyArray<T>;
|
|
197
|
-
/**
|
|
198
|
-
* Encodes a {@link JsonValue} using the MessagePack format.
|
|
199
|
-
*
|
|
200
|
-
* ### Example
|
|
201
|
-
*
|
|
202
|
-
* ```ts
|
|
203
|
-
* import {
|
|
204
|
-
* assertEqual,
|
|
205
|
-
* createBuffer,
|
|
206
|
-
* encodeJsonValue,
|
|
207
|
-
* JsonValue,
|
|
208
|
-
* } from "@evolu/common";
|
|
209
|
-
*
|
|
210
|
-
* const buffer = createBuffer();
|
|
211
|
-
* const value = JsonValue.orThrow({ name: "Ada" });
|
|
212
|
-
*
|
|
213
|
-
* encodeJsonValue(buffer, value);
|
|
214
|
-
*
|
|
215
|
-
* assertEqual(
|
|
216
|
-
* buffer.unwrap(),
|
|
217
|
-
* new Uint8Array([
|
|
218
|
-
* 0x81, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa3, 0x41, 0x64, 0x61,
|
|
219
|
-
* ]),
|
|
220
|
-
* );
|
|
221
|
-
* ```
|
|
222
|
-
*
|
|
223
|
-
* Encoding is artificially limited to 1,000 nested arrays or objects to keep
|
|
224
|
-
* recursive encoding and decoding safe and symmetric. JSON data should not
|
|
225
|
-
* require such depth; flatten or split deeply nested data, or use a
|
|
226
|
-
* purpose-built serialization format.
|
|
227
|
-
*/
|
|
228
|
-
export declare const encodeJsonValue: (buffer: Buffer, value: JsonValue) => void;
|
|
229
|
-
/**
|
|
230
|
-
* Decodes a {@link JsonValue} using the MessagePack format.
|
|
231
|
-
*
|
|
232
|
-
* Throws a {@link BufferError} without modifying the Buffer if the encoded value
|
|
233
|
-
* is malformed, truncated, unsupported, outside the JsonValue domain, or
|
|
234
|
-
* exceeds 1,000 nested arrays or objects.
|
|
235
|
-
*
|
|
236
|
-
* ### Example
|
|
237
|
-
*
|
|
238
|
-
* ```ts
|
|
239
|
-
* import {
|
|
240
|
-
* assertEqual,
|
|
241
|
-
* createBuffer,
|
|
242
|
-
* decodeJsonValue,
|
|
243
|
-
* } from "@evolu/common";
|
|
244
|
-
*
|
|
245
|
-
* const buffer = createBuffer([
|
|
246
|
-
* 0x81, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa3, 0x41, 0x64, 0x61,
|
|
247
|
-
* ]);
|
|
248
|
-
*
|
|
249
|
-
* assertEqual(decodeJsonValue(buffer), { name: "Ada" });
|
|
250
|
-
* assertEqual(buffer.unwrap(), new Uint8Array());
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
export declare const decodeJsonValue: (buffer: Buffer) => JsonValue;
|
|
254
|
-
//# sourceMappingURL=Binary.d.ts.map
|
package/dist/src/Binary.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Binary.d.ts","sourceRoot":"","sources":["../../src/Binary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEnE,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,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@module
|
|
5
|
-
*/
|
|
6
|
-
import type { DecryptWithXChaCha20Poly1305Error } from "../Crypto.ts";
|
|
7
|
-
import type { UnknownError } from "../Error.ts";
|
|
8
|
-
import type { ProtocolError } from "./Protocol.ts";
|
|
9
|
-
import type { TimestampError } from "./Timestamp.ts";
|
|
10
|
-
/** Represents errors that can occur in Evolu. */
|
|
11
|
-
export type EvoluError = DecryptWithXChaCha20Poly1305Error | ProtocolError | TimestampError | UnknownError;
|
|
12
|
-
//# sourceMappingURL=Error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../../src/local-first/Error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,iDAAiD;AACjD,MAAM,MAAM,UAAU,GAClB,iCAAiC,GACjC,aAAa,GACb,cAAc,GACd,YAAY,CAAC"}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local authentication and owner management.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
import type { RandomBytesDep } from "../Crypto.ts";
|
|
7
|
-
import type { Mnemonic } from "../Type.ts";
|
|
8
|
-
import type { AppOwner } from "./Owner.ts";
|
|
9
|
-
import { OwnerId } from "./Owner.ts";
|
|
10
|
-
/**
|
|
11
|
-
* Local authentication and authorization system for Evolu. This is API is
|
|
12
|
-
* subject to change and not recommended for production use.
|
|
13
|
-
*/
|
|
14
|
-
export interface LocalAuth {
|
|
15
|
-
/** Logs in with the given owner ID, or loads the target owner if not provided. */
|
|
16
|
-
login: (ownerId: OwnerId, options?: LocalAuthOptions) => Promise<AuthResult | null>;
|
|
17
|
-
/** Registers a new owner with the given username. */
|
|
18
|
-
register: (username: string, options?: LocalAuthOptions & {
|
|
19
|
-
mnemonic?: Mnemonic | null;
|
|
20
|
-
}) => Promise<AuthResult | null>;
|
|
21
|
-
/** Unregisters an owner with the given owner ID. */
|
|
22
|
-
unregister: (ownerId: OwnerId, options?: LocalAuthOptions) => Promise<void>;
|
|
23
|
-
/** Gets the current owner (last logged in or last registered owner) */
|
|
24
|
-
getOwner: (options?: LocalAuthOptions) => Promise<AuthResult | null>;
|
|
25
|
-
/** Lists all registered owner ids with associated usernames. */
|
|
26
|
-
getProfiles: (options?: LocalAuthOptionsValues) => Promise<Array<AuthList>>;
|
|
27
|
-
/** Clears all owners and metadata from the local auth. */
|
|
28
|
-
clearAll: (options?: LocalAuthOptions) => Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
export interface LocalAuthDep {
|
|
31
|
-
readonly localAuth: LocalAuth;
|
|
32
|
-
}
|
|
33
|
-
/** Secure storage interface that must be implemented by each platform. */
|
|
34
|
-
export interface SecureStorage {
|
|
35
|
-
setItem: (key: string, value: string, options?: LocalAuthOptions) => Promise<MutationResult>;
|
|
36
|
-
getItem: (key: string, options?: LocalAuthOptionsValues) => Promise<SensitiveInfoItem | null>;
|
|
37
|
-
deleteItem: (key: string, options?: LocalAuthOptions) => Promise<boolean>;
|
|
38
|
-
getAllItems: (options?: LocalAuthOptionsValues) => Promise<Array<SensitiveInfoItem>>;
|
|
39
|
-
clearService: (options?: LocalAuthOptions) => Promise<void>;
|
|
40
|
-
}
|
|
41
|
-
export interface SecureStorageDep {
|
|
42
|
-
readonly secureStorage: SecureStorage;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates a local auth using the given secure storage implementation. This
|
|
46
|
-
* factory function allows each platform to provide its own storage layer while
|
|
47
|
-
* sharing the common auth logic.
|
|
48
|
-
*/
|
|
49
|
-
export declare const createLocalAuth: (deps: SecureStorageDep & RandomBytesDep) => LocalAuth;
|
|
50
|
-
export declare const localAuth_Namespace = "evolu";
|
|
51
|
-
export declare const localAuthDefaultOptions: LocalAuthOptions;
|
|
52
|
-
export interface AuthResult {
|
|
53
|
-
/** The app 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 AuthList {
|
|
59
|
-
/** The app owner ID. */
|
|
60
|
-
readonly ownerId: OwnerId;
|
|
61
|
-
/** The name provided by the user during registration. */
|
|
62
|
-
readonly username: string;
|
|
63
|
-
}
|
|
64
|
-
export interface LocalAuthOptions {
|
|
65
|
-
/**
|
|
66
|
-
* Native: Namespaces the stored entry. Defaults to the bundle identifier
|
|
67
|
-
* (when available) or `default`.
|
|
68
|
-
*/
|
|
69
|
-
readonly service?: string;
|
|
70
|
-
/** IOS: Enable keychain item synchronization via iCloud. */
|
|
71
|
-
readonly iosSynchronizable?: boolean;
|
|
72
|
-
/** IOS: Custom keychain access group. */
|
|
73
|
-
readonly keychainGroup?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Native: Desired access-control policy. The native implementation will
|
|
76
|
-
* automatically fall back to the strongest supported policy for the current
|
|
77
|
-
* device (Secure Enclave ➝ Biometry ➝ Device Credential ➝ None).
|
|
78
|
-
*/
|
|
79
|
-
readonly accessControl?: AccessControl;
|
|
80
|
-
/**
|
|
81
|
-
* Android: Fine tune whether the hardware-authenticated key should require
|
|
82
|
-
* biometrics only.
|
|
83
|
-
*/
|
|
84
|
-
readonly androidBiometricsStrongOnly?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Native: Optional prompt configuration that will be shown when protected
|
|
87
|
-
* keys require user presence.
|
|
88
|
-
*/
|
|
89
|
-
readonly authenticationPrompt?: AuthenticationPrompt;
|
|
90
|
-
/** Web: The relying party ID for WebAuthn. Defaults to the current hostname. */
|
|
91
|
-
readonly relyingPartyID?: string;
|
|
92
|
-
/** Web: The relying party name for WebAuthn. Defaults to 'Evolu'. */
|
|
93
|
-
readonly relyingPartyName?: string;
|
|
94
|
-
/** Web: The username for WebAuthn. Defaults to 'Evolu User'. */
|
|
95
|
-
readonly webAuthnUsername?: string;
|
|
96
|
-
/**
|
|
97
|
-
* Web: The user verification requirement for WebAuthn. Defaults to
|
|
98
|
-
* 'required'.
|
|
99
|
-
*/
|
|
100
|
-
readonly webAuthnUserVerification?: UserVerificationRequirement;
|
|
101
|
-
/** Web: The authenticator attachment for WebAuthn. Defaults to 'platform'. */
|
|
102
|
-
readonly webAuthnAuthenticatorAttachment?: AuthenticatorAttachment;
|
|
103
|
-
}
|
|
104
|
-
export interface LocalAuthOptionsValues extends LocalAuthOptions {
|
|
105
|
-
/** When true, the stored value is returned for each item. Defaults to false. */
|
|
106
|
-
readonly includeValues?: boolean;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Configuration for the biometric/device credential prompt shown when a
|
|
110
|
-
* protected item is accessed.
|
|
111
|
-
*/
|
|
112
|
-
export interface AuthenticationPrompt {
|
|
113
|
-
readonly title: string;
|
|
114
|
-
readonly subtitle?: string;
|
|
115
|
-
readonly description?: string;
|
|
116
|
-
readonly cancel?: string;
|
|
117
|
-
}
|
|
118
|
-
export interface SensitiveInfoGetRequest extends LocalAuthOptions {
|
|
119
|
-
readonly key: string;
|
|
120
|
-
/** Include the encrypted value when available. Defaults to true. */
|
|
121
|
-
readonly includeValue?: boolean;
|
|
122
|
-
}
|
|
123
|
-
export interface StorageMetadata {
|
|
124
|
-
readonly securityLevel: SecurityLevel;
|
|
125
|
-
readonly backend: StorageBackend;
|
|
126
|
-
readonly accessControl: AccessControl;
|
|
127
|
-
readonly timestamp: number;
|
|
128
|
-
}
|
|
129
|
-
export interface SensitiveInfoItem {
|
|
130
|
-
readonly key: string;
|
|
131
|
-
readonly service: string;
|
|
132
|
-
readonly value?: string;
|
|
133
|
-
readonly metadata: StorageMetadata;
|
|
134
|
-
}
|
|
135
|
-
export interface MutationResult {
|
|
136
|
-
readonly metadata: StorageMetadata;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Enumerates the highest security tier that was effectively applied while
|
|
140
|
-
* storing a value.
|
|
141
|
-
*/
|
|
142
|
-
export type SecurityLevel = "secureEnclave" | "strongBox" | "biometry" | "deviceCredential" | "software";
|
|
143
|
-
/** Enumerates the native storage backend used to persist sensitive data. */
|
|
144
|
-
export type StorageBackend = "keychain" | "androidKeystore" | "encryptedSharedPreferences";
|
|
145
|
-
/**
|
|
146
|
-
* Enumerates the access-control policy enforced by the underlying secure
|
|
147
|
-
* storage.
|
|
148
|
-
*/
|
|
149
|
-
export type AccessControl = "secureEnclaveBiometry" | "biometryCurrentSet" | "biometryAny" | "devicePasscode" | "none";
|
|
150
|
-
//# sourceMappingURL=LocalAuth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalAuth.d.ts","sourceRoot":"","sources":["../../../src/local-first/LocalAuth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAKL,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB;;;GAGG;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,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E;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,uBAAuB,GACvB,oBAAoB,GACpB,aAAa,GACb,gBAAgB,GAChB,MAAM,CAAC"}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local authentication and owner management.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
import { createAppOwner, createOwnerSecret, mnemonicToOwnerSecret, OwnerEncryptionKey, OwnerId, OwnerWriteKey, } from "./Owner.js";
|
|
7
|
-
/**
|
|
8
|
-
* Creates a local auth using the given secure storage implementation. This
|
|
9
|
-
* factory function allows each platform to provide its own storage layer while
|
|
10
|
-
* sharing the common auth logic.
|
|
11
|
-
*/
|
|
12
|
-
export const createLocalAuth = (deps) => {
|
|
13
|
-
const setLastOwnerId = async (id, options) => {
|
|
14
|
-
await deps.secureStorage.setItem(localAuthMetakeyLastOwner, id, {
|
|
15
|
-
...buildAuthOptions(options),
|
|
16
|
-
accessControl: "none",
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
const getLastOwnerId = async (options) => {
|
|
20
|
-
const item = await deps.secureStorage.getItem(localAuthMetakeyLastOwner, {
|
|
21
|
-
...buildAuthOptions(options),
|
|
22
|
-
accessControl: "none",
|
|
23
|
-
});
|
|
24
|
-
return item?.value;
|
|
25
|
-
};
|
|
26
|
-
const getOwnerNames = async (options) => {
|
|
27
|
-
const item = await deps.secureStorage.getItem(localAuthMetakeyOwnerNames, {
|
|
28
|
-
...buildAuthOptions(options),
|
|
29
|
-
accessControl: "none",
|
|
30
|
-
});
|
|
31
|
-
let names = {};
|
|
32
|
-
if (item?.value) {
|
|
33
|
-
names = JSON.parse(item.value);
|
|
34
|
-
}
|
|
35
|
-
return names;
|
|
36
|
-
};
|
|
37
|
-
const setOwnerName = async (id, username, options) => {
|
|
38
|
-
const names = await getOwnerNames(options);
|
|
39
|
-
names[id] = username;
|
|
40
|
-
await deps.secureStorage.setItem(localAuthMetakeyOwnerNames, JSON.stringify(names), {
|
|
41
|
-
...buildAuthOptions(options),
|
|
42
|
-
accessControl: "none",
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const deleteOwnerName = async (id, options) => {
|
|
46
|
-
const { [id]: _, ...names } = await getOwnerNames(options);
|
|
47
|
-
await deps.secureStorage.setItem(localAuthMetakeyOwnerNames, JSON.stringify(names), {
|
|
48
|
-
...buildAuthOptions(options),
|
|
49
|
-
accessControl: "none",
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const getOwnerIds = async (options) => {
|
|
53
|
-
const items = await deps.secureStorage.getAllItems({
|
|
54
|
-
...buildAuthOptions(options),
|
|
55
|
-
includeValues: false,
|
|
56
|
-
});
|
|
57
|
-
return items
|
|
58
|
-
.filter(Boolean)
|
|
59
|
-
.filter((i) => i.key !== localAuthMetakeyLastOwner &&
|
|
60
|
-
i.key !== localAuthMetakeyOwnerNames)
|
|
61
|
-
.map((i) => i.key);
|
|
62
|
-
};
|
|
63
|
-
const clearAuthStore = (options) => deps.secureStorage.clearService(buildAuthOptions(options));
|
|
64
|
-
const buildAuthOptions = (options, username) => {
|
|
65
|
-
const newOptions = {
|
|
66
|
-
...localAuthDefaultOptions,
|
|
67
|
-
...(username && { webAuthnUsername: username }),
|
|
68
|
-
...options,
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
...newOptions,
|
|
72
|
-
authenticationPrompt: {
|
|
73
|
-
title: replaceMessageTokens(newOptions.authenticationPrompt?.title ?? "", username),
|
|
74
|
-
cancel: replaceMessageTokens(newOptions.authenticationPrompt?.cancel ?? "", username),
|
|
75
|
-
subtitle: replaceMessageTokens(newOptions.authenticationPrompt?.subtitle ?? "", username),
|
|
76
|
-
description: replaceMessageTokens(newOptions.authenticationPrompt?.description ?? "", username),
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
const replaceMessageTokens = (text, username) => {
|
|
81
|
-
if (!username)
|
|
82
|
-
return text;
|
|
83
|
-
return text.replace("|USERNAME|", username);
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
login: async (ownerId, options) => {
|
|
87
|
-
// Lookup the associated username
|
|
88
|
-
const names = await getOwnerNames(options);
|
|
89
|
-
const username = names[ownerId] ?? "";
|
|
90
|
-
// Currently a reload is needed. This avoids authentication
|
|
91
|
-
// it needs to be handled on next page load.
|
|
92
|
-
// We set the last owner so we know what the target is.
|
|
93
|
-
// It is the applications's responsibility to reload and trigger login.
|
|
94
|
-
await setLastOwnerId(ownerId, options);
|
|
95
|
-
return { owner: undefined, username };
|
|
96
|
-
},
|
|
97
|
-
register: async (username, options) => {
|
|
98
|
-
// Create an owner with a new secret or use specified mnemonic
|
|
99
|
-
const owner = createAppOwner(options?.mnemonic
|
|
100
|
-
? mnemonicToOwnerSecret(options.mnemonic)
|
|
101
|
-
: createOwnerSecret(deps));
|
|
102
|
-
// Store owner, associated username, and update last owner
|
|
103
|
-
await Promise.all([
|
|
104
|
-
// setOwnerItem
|
|
105
|
-
deps.secureStorage.setItem(owner.id, JSON.stringify({ owner }), buildAuthOptions(options, username)),
|
|
106
|
-
setOwnerName(owner.id, username, options),
|
|
107
|
-
setLastOwnerId(owner.id, options),
|
|
108
|
-
]);
|
|
109
|
-
// Return the owner and associated username
|
|
110
|
-
return { owner, username };
|
|
111
|
-
},
|
|
112
|
-
unregister: async (ownerId, options) => {
|
|
113
|
-
// Delete the owner and associated username
|
|
114
|
-
await Promise.all([
|
|
115
|
-
// deleteOwnerItem
|
|
116
|
-
deps.secureStorage.deleteItem(ownerId, buildAuthOptions(options)),
|
|
117
|
-
deleteOwnerName(ownerId, options),
|
|
118
|
-
]);
|
|
119
|
-
// If the owner was the last owner then set to
|
|
120
|
-
// the next owner based on metadata timestamp
|
|
121
|
-
const lastOwnerId = await getLastOwnerId(options);
|
|
122
|
-
if (lastOwnerId === ownerId) {
|
|
123
|
-
const ids = await getOwnerIds(options);
|
|
124
|
-
if (ids.length > 0) {
|
|
125
|
-
await setLastOwnerId(ids[0], options);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
getOwner: async (options) => {
|
|
130
|
-
const ownerId = await getLastOwnerId(options);
|
|
131
|
-
if (!ownerId)
|
|
132
|
-
return null;
|
|
133
|
-
const names = await getOwnerNames(options);
|
|
134
|
-
const username = names[ownerId] ?? "";
|
|
135
|
-
// Retrieve and decrypt the owner (this will trigger device authentication)
|
|
136
|
-
const account = await deps.secureStorage.getItem(ownerId, buildAuthOptions(options, username));
|
|
137
|
-
if (!account?.value)
|
|
138
|
-
return null;
|
|
139
|
-
// Unserialize the values (TODO: save these as base64 instead of json serializing)
|
|
140
|
-
const result = JSON.parse(account.value);
|
|
141
|
-
const writeKey = OwnerWriteKey.orThrow(new Uint8Array(Object.values(result.owner.writeKey)));
|
|
142
|
-
const encryptionKey = OwnerEncryptionKey.orThrow(new Uint8Array(Object.values(result.owner.encryptionKey)));
|
|
143
|
-
const owner = { ...result.owner, writeKey, encryptionKey };
|
|
144
|
-
// Update the last owner for future login attempts
|
|
145
|
-
await setLastOwnerId(ownerId, options);
|
|
146
|
-
// Return the owner and associated username
|
|
147
|
-
return { owner, username };
|
|
148
|
-
},
|
|
149
|
-
getProfiles: async (options) => {
|
|
150
|
-
// Get all owner ids and associated usernames
|
|
151
|
-
const [ids, names] = await Promise.all([
|
|
152
|
-
getOwnerIds(options),
|
|
153
|
-
getOwnerNames(options),
|
|
154
|
-
]);
|
|
155
|
-
// Return the list of profiles (usually used for login UX)
|
|
156
|
-
return ids.map((ownerId) => ({
|
|
157
|
-
ownerId,
|
|
158
|
-
username: names[ownerId] ?? "",
|
|
159
|
-
}));
|
|
160
|
-
},
|
|
161
|
-
clearAll: async (options) => {
|
|
162
|
-
// Delete all owners and associated metadata (scoped to the service)
|
|
163
|
-
await clearAuthStore(options);
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
export const localAuth_Namespace = "evolu";
|
|
168
|
-
export const localAuthDefaultOptions = {
|
|
169
|
-
service: localAuth_Namespace,
|
|
170
|
-
keychainGroup: localAuth_Namespace,
|
|
171
|
-
androidBiometricsStrongOnly: true,
|
|
172
|
-
iosSynchronizable: true,
|
|
173
|
-
webAuthnUsername: "Evolu User",
|
|
174
|
-
authenticationPrompt: {
|
|
175
|
-
title: "Authenticate as |USERNAME|",
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
const localAuthMetakeyLastOwner = "_last_owner";
|
|
179
|
-
const localAuthMetakeyOwnerNames = "_owner_names";
|
package/src/local-first/Error.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Evolu error types.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { DecryptWithXChaCha20Poly1305Error } from "../Crypto.ts";
|
|
8
|
-
import type { UnknownError } from "../Error.ts";
|
|
9
|
-
import type { ProtocolError } from "./Protocol.ts";
|
|
10
|
-
import type { TimestampError } from "./Timestamp.ts";
|
|
11
|
-
|
|
12
|
-
/** Represents errors that can occur in Evolu. */
|
|
13
|
-
export type EvoluError =
|
|
14
|
-
| DecryptWithXChaCha20Poly1305Error
|
|
15
|
-
| ProtocolError
|
|
16
|
-
| TimestampError
|
|
17
|
-
| UnknownError;
|