@evolu/common 8.0.0-next.4 → 8.0.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/Array.d.ts +279 -173
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +105 -101
- package/dist/src/Assert.d.ts +44 -44
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +44 -32
- package/dist/src/BigInt.d.ts +6 -3
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -2
- package/dist/src/Brand.d.ts +27 -40
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Buffer.d.ts +27 -11
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Cache.d.ts +9 -4
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +8 -3
- package/dist/src/Callbacks.d.ts +30 -19
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Console.d.ts +145 -66
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +91 -43
- package/dist/src/Crypto.d.ts +85 -42
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +44 -20
- package/dist/src/Eq.d.ts +87 -21
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +67 -19
- package/dist/src/Error.d.ts +5 -3
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +16 -0
- package/dist/src/Function.d.ts +119 -58
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +86 -43
- package/dist/src/Http.d.ts +394 -0
- package/dist/src/Http.d.ts.map +1 -0
- package/dist/src/Http.js +102 -0
- package/dist/src/Identicon.d.ts +16 -7
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +14 -5
- package/dist/src/LeakDetector.d.ts +88 -0
- package/dist/src/LeakDetector.d.ts.map +1 -0
- package/dist/src/LeakDetector.js +86 -0
- package/dist/src/LockManager.d.ts +18 -9
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +7 -8
- package/dist/src/Lookup.d.ts +43 -13
- package/dist/src/Lookup.d.ts.map +1 -1
- package/dist/src/Lookup.js +28 -8
- package/dist/src/Microtask.d.ts +1 -1
- package/dist/src/Microtask.d.ts.map +1 -1
- package/dist/src/Microtask.js +3 -7
- package/dist/src/Number.d.ts +49 -13
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +34 -5
- package/dist/src/Object.d.ts +160 -40
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +92 -46
- package/dist/src/Option.d.ts +10 -7
- package/dist/src/Option.d.ts.map +1 -1
- package/dist/src/Option.js +9 -6
- package/dist/src/Order.d.ts +21 -21
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +18 -21
- package/dist/src/Platform.d.ts +31 -0
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +98 -0
- package/dist/src/Random.d.ts +32 -17
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +12 -8
- package/dist/src/Redacted.d.ts +43 -29
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +14 -3
- package/dist/src/Ref.d.ts +11 -3
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +2 -2
- package/dist/src/RefCount.d.ts +2 -6
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/RefCount.js +33 -90
- package/dist/src/Relation.d.ts +70 -5
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +77 -2
- package/dist/src/Resource.d.ts +590 -155
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +592 -343
- package/dist/src/Result.d.ts +838 -191
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +163 -102
- package/dist/src/Schedule.d.ts +684 -231
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +766 -295
- package/dist/src/Set.d.ts +89 -40
- package/dist/src/Set.d.ts.map +1 -1
- package/dist/src/Set.js +50 -29
- package/dist/src/Sqlite.d.ts +29 -72
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +41 -46
- package/dist/src/StackTrace.d.ts +40 -0
- package/dist/src/StackTrace.d.ts.map +1 -0
- package/dist/src/StackTrace.js +140 -0
- package/dist/src/Store.d.ts +5 -4
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +5 -4
- package/dist/src/String.d.ts +7 -1
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +20 -7
- package/dist/src/Task.d.ts +3572 -1770
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1879 -1274
- package/dist/src/Test.d.ts +17 -125
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +17 -68
- package/dist/src/Time.d.ts +108 -49
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +172 -73
- package/dist/src/Type.d.ts +3542 -1926
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +3070 -1784
- package/dist/src/Types.d.ts +200 -108
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +39 -8
- package/dist/src/WebSocket.d.ts +48 -23
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +15 -6
- package/dist/src/Worker.d.ts +94 -36
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +58 -24
- package/dist/src/index.d.ts +55 -52
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/intl/cs.d.ts +94 -0
- package/dist/src/intl/cs.d.ts.map +1 -0
- package/dist/src/intl/cs.js +220 -0
- package/dist/src/intl/index.d.ts +7 -0
- package/dist/src/intl/index.d.ts.map +1 -0
- package/dist/src/intl/index.js +6 -0
- package/dist/src/local-first/Db.d.ts +12 -8
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +109 -132
- package/dist/src/local-first/Error.d.ts +4 -4
- package/dist/src/local-first/Evolu.d.ts +338 -92
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +47 -55
- package/dist/src/local-first/LocalAuth.d.ts +4 -4
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/Owner.d.ts +61 -24
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +45 -8
- package/dist/src/local-first/Protocol.d.ts +44 -31
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +36 -13
- package/dist/src/local-first/Query.d.ts +147 -62
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +112 -58
- package/dist/src/local-first/Relay.d.ts +44 -14
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Schema.d.ts +92 -41
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +25 -8
- package/dist/src/local-first/Shared.d.ts +23 -21
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +100 -57
- package/dist/src/local-first/Storage.d.ts +53 -32
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +194 -234
- package/dist/src/local-first/Timestamp.d.ts +21 -21
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +2 -2
- package/dist/src/local-first/index.d.ts +11 -11
- package/package.json +14 -13
- package/src/Array.ts +306 -205
- package/src/Assert.ts +54 -69
- package/src/BigInt.ts +6 -3
- package/src/Brand.ts +27 -40
- package/src/Buffer.ts +28 -12
- package/src/Cache.ts +9 -4
- package/src/Callbacks.ts +30 -19
- package/src/Console.ts +156 -84
- package/src/Crypto.ts +83 -41
- package/src/Eq.ts +95 -22
- package/src/Error.ts +8 -4
- package/src/Function.ts +167 -59
- package/src/Http.ts +549 -0
- package/src/Identicon.ts +16 -7
- package/src/LeakDetector.ts +182 -0
- package/src/LockManager.ts +43 -39
- package/src/Lookup.ts +62 -28
- package/src/Microtask.ts +19 -23
- package/src/Number.ts +64 -12
- package/src/Object.ts +173 -49
- package/src/Option.ts +10 -7
- package/src/Order.ts +23 -21
- package/src/Platform.ts +136 -0
- package/src/Polyfills.ts +6 -12
- package/src/Random.ts +32 -19
- package/src/Redacted.ts +44 -30
- package/src/Ref.ts +14 -6
- package/src/RefCount.ts +38 -80
- package/src/Relation.ts +202 -10
- package/src/Resource.ts +1199 -591
- package/src/Result.ts +930 -271
- package/src/Schedule.ts +859 -343
- package/src/Set.ts +89 -40
- package/src/Sqlite.ts +144 -138
- package/src/StackTrace.ts +230 -0
- package/src/Store.ts +8 -7
- package/src/String.ts +22 -5
- package/src/Task.ts +5101 -2832
- package/src/Test.ts +20 -168
- package/src/Time.ts +293 -90
- package/src/Type.ts +10034 -4117
- package/src/Types.ts +227 -110
- package/src/WebSocket.ts +64 -36
- package/src/Worker.ts +180 -72
- package/src/index.ts +55 -52
- package/src/intl/cs.ts +388 -0
- package/src/intl/index.ts +7 -0
- package/src/local-first/Db.ts +152 -179
- package/src/local-first/Error.ts +4 -4
- package/src/local-first/Evolu.ts +495 -250
- package/src/local-first/LocalAuth.ts +6 -12
- package/src/local-first/Owner.ts +58 -21
- package/src/local-first/Protocol.ts +49 -31
- package/src/local-first/Query.ts +146 -61
- package/src/local-first/Relay.ts +51 -21
- package/src/local-first/Schema.ts +109 -51
- package/src/local-first/Shared.ts +266 -226
- package/src/local-first/Storage.ts +266 -264
- package/src/local-first/Timestamp.ts +25 -18
- package/src/local-first/index.ts +11 -11
- package/dist/src/Skiplist.d.ts +0 -28
- package/dist/src/Skiplist.d.ts.map +0 -1
- package/dist/src/Skiplist.js +0 -64
- package/dist/src/Tracer.d.ts +0 -48
- package/dist/src/Tracer.d.ts.map +0 -1
- package/dist/src/Tracer.js +0 -6
- package/src/Skiplist.ts +0 -108
- package/src/Tracer.ts +0 -54
package/dist/src/Console.js
CHANGED
|
@@ -62,14 +62,21 @@ export const createConsole = ({ name = "", level = "log", output = createNativeC
|
|
|
62
62
|
* ### Example
|
|
63
63
|
*
|
|
64
64
|
* ```ts
|
|
65
|
+
* import {
|
|
66
|
+
* createNativeConsoleOutput,
|
|
67
|
+
* type ConsoleOutput,
|
|
68
|
+
* } from "@evolu/common";
|
|
69
|
+
*
|
|
65
70
|
* const output = createNativeConsoleOutput();
|
|
71
|
+
*
|
|
72
|
+
* expectTypeOf(output).toEqualTypeOf<ConsoleOutput>();
|
|
73
|
+
* expect(output.write).toBeTypeOf("function");
|
|
66
74
|
* ```
|
|
67
75
|
*/
|
|
68
76
|
export const createNativeConsoleOutput = () => ({
|
|
69
77
|
write: (entry, formatter) => {
|
|
70
78
|
const args = formatter ? formatter(entry) : entry.args;
|
|
71
|
-
|
|
72
|
-
fn(...args);
|
|
79
|
+
globalThis.console[entry.method](...args);
|
|
73
80
|
},
|
|
74
81
|
});
|
|
75
82
|
/**
|
|
@@ -80,23 +87,52 @@ export const createNativeConsoleOutput = () => ({
|
|
|
80
87
|
* ### Example
|
|
81
88
|
*
|
|
82
89
|
* ```ts
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
90
|
+
* import {
|
|
91
|
+
* createConsoleFormatter,
|
|
92
|
+
* Millis,
|
|
93
|
+
* testCreateTime,
|
|
94
|
+
* type ConsoleEntry,
|
|
95
|
+
* } from "@evolu/common";
|
|
88
96
|
*
|
|
89
|
-
*
|
|
90
|
-
* const
|
|
91
|
-
*
|
|
92
|
-
*
|
|
97
|
+
* const time = testCreateTime({ startAt: Millis.orThrow(0) });
|
|
98
|
+
* const formatRelative = createConsoleFormatter({ time })({
|
|
99
|
+
* timestampFormat: "relative",
|
|
100
|
+
* });
|
|
101
|
+
* const connected: ConsoleEntry = {
|
|
102
|
+
* method: "log",
|
|
103
|
+
* path: ["relay"],
|
|
104
|
+
* args: ["connected"],
|
|
105
|
+
* };
|
|
93
106
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
107
|
+
* expect(formatRelative(connected)).toEqual([
|
|
108
|
+
* "+0.000s [relay]",
|
|
109
|
+
* "connected",
|
|
110
|
+
* ]);
|
|
111
|
+
* time.advance("1.5s");
|
|
112
|
+
* expect(
|
|
113
|
+
* formatRelative({
|
|
114
|
+
* ...connected,
|
|
115
|
+
* path: ["relay", "db"],
|
|
116
|
+
* args: ["opened"],
|
|
117
|
+
* }),
|
|
118
|
+
* ).toEqual(["+1.500s [relay] [db]", "opened"]);
|
|
97
119
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
120
|
+
* const localTimestamp = new globalThis.Date(
|
|
121
|
+
* 2026,
|
|
122
|
+
* 0,
|
|
123
|
+
* 28,
|
|
124
|
+
* 14,
|
|
125
|
+
* 30,
|
|
126
|
+
* 15,
|
|
127
|
+
* 123,
|
|
128
|
+
* ).getTime();
|
|
129
|
+
* const formatAbsolute = createConsoleFormatter({
|
|
130
|
+
* time: testCreateTime({ startAt: Millis.orThrow(localTimestamp) }),
|
|
131
|
+
* })({ timestampFormat: "absolute" });
|
|
132
|
+
* expect(formatAbsolute(connected)).toEqual([
|
|
133
|
+
* "14:30:15.123 [relay]",
|
|
134
|
+
* "connected",
|
|
135
|
+
* ]);
|
|
100
136
|
* ```
|
|
101
137
|
*/
|
|
102
138
|
export const createConsoleFormatter = ({ time = createTime() } = {}) => (config = {}) => {
|
|
@@ -141,11 +177,20 @@ export const createConsoleStoreOutput = () => {
|
|
|
141
177
|
* ### Example
|
|
142
178
|
*
|
|
143
179
|
* ```ts
|
|
144
|
-
*
|
|
145
|
-
*
|
|
180
|
+
* import {
|
|
181
|
+
* createConsole,
|
|
182
|
+
* createConsoleArrayOutput,
|
|
183
|
+
* type ConsoleEntry,
|
|
184
|
+
* } from "@evolu/common";
|
|
146
185
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
186
|
+
* const entries: Array<ConsoleEntry> = [];
|
|
187
|
+
* const console = createConsole({
|
|
188
|
+
* output: createConsoleArrayOutput(entries),
|
|
189
|
+
* });
|
|
190
|
+
* console.info("connected");
|
|
191
|
+
* expect(entries).toEqual([
|
|
192
|
+
* { method: "info", path: [], args: ["connected"] },
|
|
193
|
+
* ]);
|
|
149
194
|
* ```
|
|
150
195
|
*/
|
|
151
196
|
export const createConsoleArrayOutput = (entries) => ({
|
|
@@ -162,10 +207,25 @@ export const createConsoleArrayOutput = (entries) => ({
|
|
|
162
207
|
* ### Example
|
|
163
208
|
*
|
|
164
209
|
* ```ts
|
|
210
|
+
* import {
|
|
211
|
+
* createConsole,
|
|
212
|
+
* createConsoleArrayOutput,
|
|
213
|
+
* createConsoleStoreOutput,
|
|
214
|
+
* createMultiOutput,
|
|
215
|
+
* type ConsoleEntry,
|
|
216
|
+
* } from "@evolu/common";
|
|
217
|
+
*
|
|
218
|
+
* const entries: Array<ConsoleEntry> = [];
|
|
165
219
|
* const storeOutput = createConsoleStoreOutput();
|
|
166
220
|
* const console = createConsole({
|
|
167
|
-
* output: createMultiOutput([
|
|
221
|
+
* output: createMultiOutput([
|
|
222
|
+
* createConsoleArrayOutput(entries),
|
|
223
|
+
* storeOutput,
|
|
224
|
+
* ]),
|
|
168
225
|
* });
|
|
226
|
+
* console.error("disconnected");
|
|
227
|
+
*
|
|
228
|
+
* expect(storeOutput.entry.get()).toEqual(entries[0]);
|
|
169
229
|
* ```
|
|
170
230
|
*/
|
|
171
231
|
export const createMultiOutput = (outputs) => ({
|
|
@@ -177,33 +237,21 @@ export const createMultiOutput = (outputs) => ({
|
|
|
177
237
|
/**
|
|
178
238
|
* Creates a {@link TestConsole} that captures all output for testing.
|
|
179
239
|
*
|
|
180
|
-
* Unlike {@link createConsole}, this doesn't require dependencies and
|
|
181
|
-
*
|
|
240
|
+
* Unlike {@link createConsole}, this doesn't require dependencies and captures
|
|
241
|
+
* entries in memory.
|
|
182
242
|
*
|
|
183
243
|
* ### Example
|
|
184
244
|
*
|
|
185
245
|
* ```ts
|
|
186
|
-
*
|
|
187
|
-
* const console = testCreateConsole();
|
|
188
|
-
* console.info("Hello");
|
|
189
|
-
*
|
|
190
|
-
* expect(console.getEntriesSnapshot()).toMatchInlineSnapshot(`
|
|
191
|
-
* [
|
|
192
|
-
* {
|
|
193
|
-
* "method": "info",
|
|
194
|
-
* "path": [],
|
|
195
|
-
* "args": ["Hello"]
|
|
196
|
-
* }
|
|
197
|
-
* ]
|
|
198
|
-
* `);
|
|
199
|
-
* });
|
|
246
|
+
* import { testCreateConsole } from "@evolu/common";
|
|
200
247
|
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* }
|
|
248
|
+
* const console = testCreateConsole({ level: "info" });
|
|
249
|
+
* console.debug("ignored");
|
|
250
|
+
* console.child("relay").info("connected");
|
|
251
|
+
*
|
|
252
|
+
* expect(console.getEntriesSnapshot()).toEqual([
|
|
253
|
+
* { method: "info", path: ["relay"], args: ["connected"] },
|
|
254
|
+
* ]);
|
|
207
255
|
* ```
|
|
208
256
|
*/
|
|
209
257
|
export const testCreateConsole = ({ level = "trace", } = {}) => {
|
package/dist/src/Crypto.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
-
import type { RandomLibDep } from "./Random.
|
|
11
|
-
import type { Result } from "./Result.
|
|
12
|
-
import { NonNegativeInt, type Typed } from "./Type.
|
|
10
|
+
import type { RandomLibDep } from "./Random.ts";
|
|
11
|
+
import type { Result } from "./Result.ts";
|
|
12
|
+
import { NonNegativeInt, type Typed } from "./Type.ts";
|
|
13
13
|
export interface RandomBytes {
|
|
14
14
|
/**
|
|
15
15
|
* Creates cryptographically secure random bytes with type-safe length
|
|
@@ -23,20 +23,35 @@ export interface RandomBytes {
|
|
|
23
23
|
*
|
|
24
24
|
* Returns specific branded types for common sizes:
|
|
25
25
|
*
|
|
26
|
-
* - `
|
|
27
|
-
* - `
|
|
28
|
-
* - `
|
|
29
|
-
* - `
|
|
30
|
-
* - `
|
|
26
|
+
* - `Entropy16` for 16-byte values (128 bits)
|
|
27
|
+
* - `Entropy24` for 24-byte values (192 bits)
|
|
28
|
+
* - `Entropy32` for 32-byte values (256 bits)
|
|
29
|
+
* - `Entropy64` for 64-byte values (512 bits)
|
|
30
|
+
* - `Entropy` for any other size
|
|
31
31
|
*
|
|
32
32
|
* ### Example
|
|
33
33
|
*
|
|
34
34
|
* ```ts
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
35
|
+
* import {
|
|
36
|
+
* createRandomBytes,
|
|
37
|
+
* type Entropy16,
|
|
38
|
+
* type Entropy24,
|
|
39
|
+
* type Entropy32,
|
|
40
|
+
* type Entropy64,
|
|
41
|
+
* } from "@evolu/common";
|
|
42
|
+
*
|
|
43
|
+
* const randomBytes = createRandomBytes();
|
|
44
|
+
* const nonce16 = randomBytes.create(16);
|
|
45
|
+
* const nonce24 = randomBytes.create(24);
|
|
46
|
+
* const key = randomBytes.create(32);
|
|
47
|
+
* const seed = randomBytes.create(64);
|
|
48
|
+
* const custom = randomBytes.create(48);
|
|
49
|
+
*
|
|
50
|
+
* expectTypeOf(nonce16).toEqualTypeOf<Entropy16>();
|
|
51
|
+
* expectTypeOf(nonce24).toEqualTypeOf<Entropy24>();
|
|
52
|
+
* expectTypeOf(key).toEqualTypeOf<Entropy32>();
|
|
53
|
+
* expectTypeOf(seed).toEqualTypeOf<Entropy64>();
|
|
54
|
+
* expect(custom).toHaveLength(48);
|
|
40
55
|
* ```
|
|
41
56
|
*/
|
|
42
57
|
create(bytesLength: 16): Entropy16;
|
|
@@ -48,16 +63,16 @@ export interface RandomBytes {
|
|
|
48
63
|
export interface RandomBytesDep {
|
|
49
64
|
readonly randomBytes: RandomBytes;
|
|
50
65
|
}
|
|
51
|
-
declare const Entropy: import("./Type.
|
|
52
|
-
type Entropy = typeof Entropy.
|
|
53
|
-
export declare const Entropy16: import("./Type.
|
|
54
|
-
export type Entropy16 = typeof Entropy16.
|
|
55
|
-
export declare const Entropy24: import("./Type.
|
|
56
|
-
export type Entropy24 = typeof Entropy24.
|
|
57
|
-
export declare const Entropy32: import("./Type.
|
|
58
|
-
export type Entropy32 = typeof Entropy32.
|
|
59
|
-
export declare const Entropy64: import("./Type.
|
|
60
|
-
export type Entropy64 = typeof Entropy64.
|
|
66
|
+
declare const Entropy: import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>;
|
|
67
|
+
type Entropy = typeof Entropy.Output;
|
|
68
|
+
export declare const Entropy16: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length16", import("./Type.ts").LengthError<16>>;
|
|
69
|
+
export type Entropy16 = typeof Entropy16.Output;
|
|
70
|
+
export declare const Entropy24: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length24", import("./Type.ts").LengthError<24>>;
|
|
71
|
+
export type Entropy24 = typeof Entropy24.Output;
|
|
72
|
+
export declare const Entropy32: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length32", import("./Type.ts").LengthError<32>>;
|
|
73
|
+
export type Entropy32 = typeof Entropy32.Output;
|
|
74
|
+
export declare const Entropy64: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length64", import("./Type.ts").LengthError<64>>;
|
|
75
|
+
export type Entropy64 = typeof Entropy64.Output;
|
|
61
76
|
export declare const createRandomBytes: () => RandomBytes;
|
|
62
77
|
/** Creates seeded random bytes for deterministic tests. */
|
|
63
78
|
export declare const testCreateRandomBytes: (deps: RandomLibDep) => RandomBytes;
|
|
@@ -74,8 +89,8 @@ export declare const createSlip21: (seed: Entropy16 | Entropy32 | Entropy64, pat
|
|
|
74
89
|
*/
|
|
75
90
|
export declare const deriveSlip21Node: (label: string, parentNode: Entropy64) => Entropy64;
|
|
76
91
|
/** The encryption key for symmetric encryption. */
|
|
77
|
-
export declare const EncryptionKey: import("./Type.
|
|
78
|
-
export type EncryptionKey = typeof EncryptionKey.
|
|
92
|
+
export declare const EncryptionKey: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length32", import("./Type.ts").LengthError<32>>, "EncryptionKey", never>;
|
|
93
|
+
export type EncryptionKey = typeof EncryptionKey.Output;
|
|
79
94
|
/** The nonce length for XChaCha20-Poly1305 encryption. */
|
|
80
95
|
export declare const xChaCha20Poly1305NonceLength = 24;
|
|
81
96
|
/**
|
|
@@ -83,8 +98,8 @@ export declare const xChaCha20Poly1305NonceLength = 24;
|
|
|
83
98
|
*
|
|
84
99
|
* @see {@link encryptWithXChaCha20Poly1305}
|
|
85
100
|
*/
|
|
86
|
-
export declare const XChaCha20Poly1305Ciphertext: import("./Type.
|
|
87
|
-
export type XChaCha20Poly1305Ciphertext = typeof XChaCha20Poly1305Ciphertext.
|
|
101
|
+
export declare const XChaCha20Poly1305Ciphertext: import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "XChaCha20Poly1305Ciphertext", never>;
|
|
102
|
+
export type XChaCha20Poly1305Ciphertext = typeof XChaCha20Poly1305Ciphertext.Output;
|
|
88
103
|
/**
|
|
89
104
|
* Encrypts plaintext with XChaCha20-Poly1305.
|
|
90
105
|
*
|
|
@@ -94,11 +109,22 @@ export type XChaCha20Poly1305Ciphertext = typeof XChaCha20Poly1305Ciphertext.Typ
|
|
|
94
109
|
* ### Example
|
|
95
110
|
*
|
|
96
111
|
* ```ts
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
112
|
+
* import {
|
|
113
|
+
* createRandomBytes,
|
|
114
|
+
* EncryptionKey,
|
|
115
|
+
* encryptWithXChaCha20Poly1305,
|
|
116
|
+
* type XChaCha20Poly1305Ciphertext,
|
|
117
|
+
* utf8ToBytes,
|
|
118
|
+
* } from "@evolu/common";
|
|
119
|
+
*
|
|
120
|
+
* const plaintext = utf8ToBytes("secret message");
|
|
121
|
+
* const encryptionKey = EncryptionKey.orThrow(new Uint8Array(32).fill(7));
|
|
122
|
+
* const [ciphertext, nonce] = encryptWithXChaCha20Poly1305({
|
|
123
|
+
* randomBytes: createRandomBytes(),
|
|
124
|
+
* })(plaintext, encryptionKey);
|
|
125
|
+
*
|
|
126
|
+
* expectTypeOf(ciphertext).toEqualTypeOf<XChaCha20Poly1305Ciphertext>();
|
|
127
|
+
* expect(nonce).toHaveLength(24);
|
|
102
128
|
* ```
|
|
103
129
|
*
|
|
104
130
|
* @see https://github.com/paulmillr/noble-ciphers
|
|
@@ -117,16 +143,33 @@ export interface DecryptWithXChaCha20Poly1305Error extends Typed<"DecryptWithXCh
|
|
|
117
143
|
* ### Example
|
|
118
144
|
*
|
|
119
145
|
* ```ts
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* }
|
|
129
|
-
*
|
|
146
|
+
* import {
|
|
147
|
+
* bytesToUtf8,
|
|
148
|
+
* createRandomBytes,
|
|
149
|
+
* decryptWithXChaCha20Poly1305,
|
|
150
|
+
* EncryptionKey,
|
|
151
|
+
* encryptWithXChaCha20Poly1305,
|
|
152
|
+
* ok,
|
|
153
|
+
* utf8ToBytes,
|
|
154
|
+
* } from "@evolu/common";
|
|
155
|
+
*
|
|
156
|
+
* const plaintext = utf8ToBytes("secret message");
|
|
157
|
+
* const encryptionKey = EncryptionKey.orThrow(new Uint8Array(32).fill(7));
|
|
158
|
+
* const [ciphertext, nonce] = encryptWithXChaCha20Poly1305({
|
|
159
|
+
* randomBytes: createRandomBytes(),
|
|
160
|
+
* })(plaintext, encryptionKey);
|
|
161
|
+
*
|
|
162
|
+
* const decryptMessage = () => {
|
|
163
|
+
* const result = decryptWithXChaCha20Poly1305(
|
|
164
|
+
* ciphertext,
|
|
165
|
+
* nonce,
|
|
166
|
+
* encryptionKey,
|
|
167
|
+
* );
|
|
168
|
+
* if (!result.ok) return result;
|
|
169
|
+
* return ok(bytesToUtf8(result.value));
|
|
170
|
+
* };
|
|
171
|
+
*
|
|
172
|
+
* expectOk(decryptMessage(), "secret message");
|
|
130
173
|
* ```
|
|
131
174
|
*/
|
|
132
175
|
export declare const decryptWithXChaCha20Poly1305: (ciphertext: XChaCha20Poly1305Ciphertext, nonce: Entropy24, encryptionKey: EncryptionKey) => Result<Uint8Array, DecryptWithXChaCha20Poly1305Error>;
|
package/dist/src/Crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"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"}
|
package/dist/src/Crypto.js
CHANGED
|
@@ -11,7 +11,6 @@ import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
|
11
11
|
import { hmac } from "@noble/hashes/hmac.js";
|
|
12
12
|
import { sha512 } from "@noble/hashes/sha2.js";
|
|
13
13
|
import { randomBytes, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
14
|
-
import { arrayFrom } from "./Array.js";
|
|
15
14
|
import { trySync } from "./Result.js";
|
|
16
15
|
import { brand, length, NonNegativeInt, Uint8Array, zeroNonNegativeInt, } from "./Type.js";
|
|
17
16
|
const Entropy = /*#__PURE__*/ brand("Entropy", Uint8Array);
|
|
@@ -24,10 +23,7 @@ export const createRandomBytes = () => ({
|
|
|
24
23
|
});
|
|
25
24
|
/** Creates seeded random bytes for deterministic tests. */
|
|
26
25
|
export const testCreateRandomBytes = (deps) => ({
|
|
27
|
-
create: (bytesLength) => {
|
|
28
|
-
const array = arrayFrom(bytesLength, () => deps.randomLib.int(0, 255));
|
|
29
|
-
return new globalThis.Uint8Array(array);
|
|
30
|
-
},
|
|
26
|
+
create: (bytesLength) => globalThis.Uint8Array.from({ length: bytesLength }, () => deps.randomLib.int(0, 255)),
|
|
31
27
|
});
|
|
32
28
|
/**
|
|
33
29
|
* SLIP21.
|
|
@@ -73,11 +69,22 @@ export const XChaCha20Poly1305Ciphertext = /*#__PURE__*/ brand("XChaCha20Poly130
|
|
|
73
69
|
* ### Example
|
|
74
70
|
*
|
|
75
71
|
* ```ts
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
72
|
+
* import {
|
|
73
|
+
* createRandomBytes,
|
|
74
|
+
* EncryptionKey,
|
|
75
|
+
* encryptWithXChaCha20Poly1305,
|
|
76
|
+
* type XChaCha20Poly1305Ciphertext,
|
|
77
|
+
* utf8ToBytes,
|
|
78
|
+
* } from "@evolu/common";
|
|
79
|
+
*
|
|
80
|
+
* const plaintext = utf8ToBytes("secret message");
|
|
81
|
+
* const encryptionKey = EncryptionKey.orThrow(new Uint8Array(32).fill(7));
|
|
82
|
+
* const [ciphertext, nonce] = encryptWithXChaCha20Poly1305({
|
|
83
|
+
* randomBytes: createRandomBytes(),
|
|
84
|
+
* })(plaintext, encryptionKey);
|
|
85
|
+
*
|
|
86
|
+
* expectTypeOf(ciphertext).toEqualTypeOf<XChaCha20Poly1305Ciphertext>();
|
|
87
|
+
* expect(nonce).toHaveLength(24);
|
|
81
88
|
* ```
|
|
82
89
|
*
|
|
83
90
|
* @see https://github.com/paulmillr/noble-ciphers
|
|
@@ -97,16 +104,33 @@ export const encryptWithXChaCha20Poly1305 = (deps) => (plaintext, encryptionKey)
|
|
|
97
104
|
* ### Example
|
|
98
105
|
*
|
|
99
106
|
* ```ts
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* }
|
|
109
|
-
*
|
|
107
|
+
* import {
|
|
108
|
+
* bytesToUtf8,
|
|
109
|
+
* createRandomBytes,
|
|
110
|
+
* decryptWithXChaCha20Poly1305,
|
|
111
|
+
* EncryptionKey,
|
|
112
|
+
* encryptWithXChaCha20Poly1305,
|
|
113
|
+
* ok,
|
|
114
|
+
* utf8ToBytes,
|
|
115
|
+
* } from "@evolu/common";
|
|
116
|
+
*
|
|
117
|
+
* const plaintext = utf8ToBytes("secret message");
|
|
118
|
+
* const encryptionKey = EncryptionKey.orThrow(new Uint8Array(32).fill(7));
|
|
119
|
+
* const [ciphertext, nonce] = encryptWithXChaCha20Poly1305({
|
|
120
|
+
* randomBytes: createRandomBytes(),
|
|
121
|
+
* })(plaintext, encryptionKey);
|
|
122
|
+
*
|
|
123
|
+
* const decryptMessage = () => {
|
|
124
|
+
* const result = decryptWithXChaCha20Poly1305(
|
|
125
|
+
* ciphertext,
|
|
126
|
+
* nonce,
|
|
127
|
+
* encryptionKey,
|
|
128
|
+
* );
|
|
129
|
+
* if (!result.ok) return result;
|
|
130
|
+
* return ok(bytesToUtf8(result.value));
|
|
131
|
+
* };
|
|
132
|
+
*
|
|
133
|
+
* expectOk(decryptMessage(), "secret message");
|
|
110
134
|
* ```
|
|
111
135
|
*/
|
|
112
136
|
export const decryptWithXChaCha20Poly1305 = (ciphertext, nonce, encryptionKey) => trySync(() => xchacha20poly1305(encryptionKey, nonce).decrypt(ciphertext), (error) => ({
|