@evolu/common 6.0.1-preview.8 → 7.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/README.md +2 -2
- package/dist/src/Array.d.ts +256 -12
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +215 -9
- package/dist/src/Assert.d.ts +0 -13
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +0 -15
- package/dist/src/Brand.d.ts +75 -0
- package/dist/src/Brand.d.ts.map +1 -0
- package/dist/src/Brand.js +1 -0
- package/dist/src/Buffer.d.ts +1 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +8 -7
- package/dist/src/Cache.d.ts +44 -0
- package/dist/src/Cache.d.ts.map +1 -0
- package/dist/src/Cache.js +52 -0
- package/dist/src/Callbacks.d.ts +45 -12
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +14 -7
- package/dist/src/Console.d.ts +31 -6
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +72 -9
- package/dist/src/Crypto.d.ts +56 -42
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +40 -53
- package/dist/src/Evolu/Db.d.ts +162 -74
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +284 -702
- package/dist/src/Evolu/Diff.d.ts +3 -3
- package/dist/src/Evolu/Diff.d.ts.map +1 -1
- package/dist/src/Evolu/Diff.js +7 -5
- package/dist/src/Evolu/Evolu.d.ts +214 -134
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +189 -180
- package/dist/src/Evolu/Internal.d.ts +0 -2
- package/dist/src/Evolu/Internal.d.ts.map +1 -1
- package/dist/src/Evolu/Internal.js +0 -2
- package/dist/src/Evolu/LocalAuth.d.ts +150 -0
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
- package/dist/src/Evolu/LocalAuth.js +174 -0
- package/dist/src/Evolu/Owner.d.ts +273 -120
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +130 -104
- package/dist/src/Evolu/Platform.d.ts +9 -7
- package/dist/src/Evolu/Platform.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.d.ts +268 -240
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +600 -454
- package/dist/src/Evolu/Public.d.ts +6 -8
- package/dist/src/Evolu/Public.d.ts.map +1 -1
- package/dist/src/Evolu/Public.js +2 -3
- package/dist/src/Evolu/PublicKysely.d.ts.map +1 -1
- package/dist/src/Evolu/PublicKysely.js +3 -4
- package/dist/src/Evolu/Query.d.ts +2 -1
- package/dist/src/Evolu/Query.d.ts.map +1 -1
- package/dist/src/Evolu/Query.js +1 -1
- package/dist/src/Evolu/Relay.d.ts +91 -8
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +214 -88
- package/dist/src/Evolu/Schema.d.ts +125 -47
- package/dist/src/Evolu/Schema.d.ts.map +1 -1
- package/dist/src/Evolu/Schema.js +175 -31
- package/dist/src/Evolu/Storage.d.ts +249 -27
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +198 -92
- package/dist/src/Evolu/Sync.d.ts +68 -13
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +469 -20
- package/dist/src/Evolu/Timestamp.d.ts +83 -30
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +79 -34
- package/dist/src/Identicon.d.ts +35 -0
- package/dist/src/Identicon.d.ts.map +1 -0
- package/dist/src/Identicon.js +143 -0
- package/dist/src/Instances.d.ts +34 -0
- package/dist/src/Instances.d.ts.map +1 -0
- package/dist/src/Instances.js +44 -0
- package/dist/src/Number.d.ts +4 -3
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +5 -4
- package/dist/src/Object.d.ts +10 -4
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +9 -3
- package/dist/src/Platform.d.ts +20 -0
- package/dist/src/Platform.d.ts.map +1 -0
- package/dist/src/Platform.js +22 -0
- package/dist/src/Random.d.ts +3 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Relation.d.ts +79 -0
- package/dist/src/Relation.d.ts.map +1 -0
- package/dist/src/Relation.js +127 -0
- package/dist/src/Resources.d.ts +118 -0
- package/dist/src/Resources.d.ts.map +1 -0
- package/dist/src/Resources.js +197 -0
- package/dist/src/Result.d.ts +184 -52
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +30 -241
- package/dist/src/Skiplist.js +2 -1
- package/dist/src/Sqlite.d.ts +89 -5
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +136 -9
- package/dist/src/Task.d.ts +586 -0
- package/dist/src/Task.d.ts.map +1 -0
- package/dist/src/Task.js +469 -0
- package/dist/src/Time.d.ts +66 -1
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +99 -5
- package/dist/src/Type.d.ts +676 -343
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +718 -467
- package/dist/src/Types.d.ts +1 -75
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/WebSocket.d.ts +5 -2
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +12 -18
- package/dist/src/Worker.d.ts +39 -11
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +22 -4
- package/dist/src/index.d.ts +8 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -3
- package/package.json +15 -14
- package/src/Array.ts +301 -19
- package/src/Assert.ts +0 -21
- package/src/Brand.ts +75 -0
- package/src/Buffer.ts +7 -7
- package/src/Cache.ts +85 -0
- package/src/Callbacks.ts +62 -22
- package/src/Console.ts +91 -11
- package/src/Crypto.ts +94 -90
- package/src/Evolu/Db.ts +519 -1026
- package/src/Evolu/Diff.ts +7 -5
- package/src/Evolu/Evolu.ts +477 -361
- package/src/Evolu/Internal.ts +0 -2
- package/src/Evolu/LocalAuth.ts +463 -0
- package/src/Evolu/Owner.ts +355 -228
- package/src/Evolu/Platform.ts +9 -9
- package/src/Evolu/Protocol.ts +842 -742
- package/src/Evolu/Public.ts +7 -14
- package/src/Evolu/PublicKysely.ts +4 -5
- package/src/Evolu/Query.ts +3 -2
- package/src/Evolu/Relay.ts +406 -103
- package/src/Evolu/Schema.ts +323 -91
- package/src/Evolu/Storage.ts +559 -137
- package/src/Evolu/Sync.ts +819 -36
- package/src/Evolu/Timestamp.ts +90 -58
- package/src/Identicon.ts +197 -0
- package/src/Instances.ts +90 -0
- package/src/Number.ts +6 -10
- package/src/Object.ts +13 -5
- package/src/Platform.ts +26 -0
- package/src/Random.ts +3 -2
- package/src/Relation.ts +234 -0
- package/src/Resources.ts +367 -0
- package/src/Result.ts +191 -54
- package/src/Skiplist.ts +1 -1
- package/src/Sqlite.ts +152 -17
- package/src/Task.ts +901 -0
- package/src/Time.ts +180 -5
- package/src/Type.ts +1135 -730
- package/src/Types.ts +1 -77
- package/src/WebSocket.ts +27 -25
- package/src/Worker.ts +72 -23
- package/src/index.ts +8 -3
- package/dist/src/Evolu/Config.d.ts +0 -69
- package/dist/src/Evolu/Config.d.ts.map +0 -1
- package/dist/src/Evolu/Config.js +0 -9
- package/dist/src/Evolu/Kysely.d.ts +0 -6
- package/dist/src/Evolu/Kysely.d.ts.map +0 -1
- package/dist/src/Evolu/Kysely.js +0 -21
- package/dist/src/ManyToManyMap.d.ts +0 -26
- package/dist/src/ManyToManyMap.d.ts.map +0 -1
- package/dist/src/ManyToManyMap.js +0 -92
- package/dist/src/NanoId.d.ts +0 -27
- package/dist/src/NanoId.d.ts.map +0 -1
- package/dist/src/NanoId.js +0 -6
- package/dist/src/Promise.d.ts +0 -180
- package/dist/src/Promise.d.ts.map +0 -1
- package/dist/src/Promise.js +0 -176
- package/src/Evolu/Config.ts +0 -83
- package/src/Evolu/Kysely.ts +0 -38
- package/src/ManyToManyMap.ts +0 -140
- package/src/NanoId.ts +0 -39
- package/src/Promise.ts +0 -295
package/dist/src/Buffer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { NonNegativeInt } from "./Type.js";
|
|
2
|
+
export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils.js";
|
|
2
3
|
/**
|
|
3
4
|
* Custom error for {@link Buffer}-related failures like premature end of data.
|
|
4
5
|
* Provides better stack traces for debugging binary protocol issues.
|
|
@@ -14,9 +15,9 @@ export const createBuffer = (arrayLike) => {
|
|
|
14
15
|
let value = arrayLike
|
|
15
16
|
? new globalThis.Uint8Array(arrayLike)
|
|
16
17
|
: new globalThis.Uint8Array(512);
|
|
17
|
-
let length = (arrayLike ? arrayLike.length : 0);
|
|
18
|
+
let length = NonNegativeInt.orThrow(arrayLike ? arrayLike.length : 0);
|
|
18
19
|
const buffer = {
|
|
19
|
-
getCapacity: () => value.length,
|
|
20
|
+
getCapacity: () => NonNegativeInt.orThrow(value.length),
|
|
20
21
|
getLength: () => length,
|
|
21
22
|
extend: (arg) => {
|
|
22
23
|
const targetSize = length + arg.length;
|
|
@@ -27,7 +28,7 @@ export const createBuffer = (arrayLike) => {
|
|
|
27
28
|
value.set(oldValue);
|
|
28
29
|
}
|
|
29
30
|
value.set(arg, length);
|
|
30
|
-
length = (length + arg.length);
|
|
31
|
+
length = NonNegativeInt.orThrow(length + arg.length);
|
|
31
32
|
},
|
|
32
33
|
shift: () => {
|
|
33
34
|
if (length === 0) {
|
|
@@ -36,7 +37,7 @@ export const createBuffer = (arrayLike) => {
|
|
|
36
37
|
const first = value[0];
|
|
37
38
|
value = value.subarray(1);
|
|
38
39
|
length--;
|
|
39
|
-
return first;
|
|
40
|
+
return NonNegativeInt.orThrow(first);
|
|
40
41
|
},
|
|
41
42
|
shiftN: (n) => {
|
|
42
43
|
if (length < n) {
|
|
@@ -44,7 +45,7 @@ export const createBuffer = (arrayLike) => {
|
|
|
44
45
|
}
|
|
45
46
|
const subarray = value.subarray(0, n);
|
|
46
47
|
value = value.subarray(n);
|
|
47
|
-
length = (length - n);
|
|
48
|
+
length = NonNegativeInt.orThrow(length - n);
|
|
48
49
|
return subarray;
|
|
49
50
|
},
|
|
50
51
|
truncate: (newLength) => {
|
|
@@ -54,7 +55,7 @@ export const createBuffer = (arrayLike) => {
|
|
|
54
55
|
length = newLength;
|
|
55
56
|
},
|
|
56
57
|
reset: () => {
|
|
57
|
-
length = 0;
|
|
58
|
+
length = NonNegativeInt.orThrow(0);
|
|
58
59
|
},
|
|
59
60
|
unwrap: () => value.subarray(0, length),
|
|
60
61
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🗄️ Generic cache interface and LRU cache implementation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { PositiveInt } from "./Type.js";
|
|
7
|
+
/**
|
|
8
|
+
* Generic cache interface providing basic key-value storage operations.
|
|
9
|
+
*
|
|
10
|
+
* Keys are compared by reference (standard Map semantics).
|
|
11
|
+
*
|
|
12
|
+
* Note: Cache does not extend Map because eviction policies (like in LRU)
|
|
13
|
+
* violate the Liskov Substitution Principle.
|
|
14
|
+
*/
|
|
15
|
+
export interface Cache<K, V> {
|
|
16
|
+
/** Checks if a key exists in the cache. */
|
|
17
|
+
has: (key: K) => boolean;
|
|
18
|
+
/** Retrieves the value for a key, or undefined if not present. */
|
|
19
|
+
get: (key: K) => V | undefined;
|
|
20
|
+
/** Stores a key-value pair in the cache. */
|
|
21
|
+
set: (key: K, val: V) => void;
|
|
22
|
+
/** Removes a key from the cache. */
|
|
23
|
+
delete: (key: K) => void;
|
|
24
|
+
/** Returns a readonly view of the internal Map. */
|
|
25
|
+
readonly map: ReadonlyMap<K, V>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a Least Recently Used (LRU) cache with a maximum capacity.
|
|
29
|
+
*
|
|
30
|
+
* When the cache reaches capacity, the least recently used entry is evicted.
|
|
31
|
+
* Both `get` and `set` operations update the access order.
|
|
32
|
+
*
|
|
33
|
+
* ### Example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const cache = createLruCache<string, number>(2);
|
|
37
|
+
* cache.set("a", 1);
|
|
38
|
+
* cache.set("b", 2);
|
|
39
|
+
* cache.set("c", 3); // Evicts "a"
|
|
40
|
+
* cache.has("a"); // false
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const createLruCache: <K, V>(capacity: PositiveInt) => Cache<K, V>;
|
|
44
|
+
//# sourceMappingURL=Cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../src/Cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;IACzB,2CAA2C;IAC3C,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;IAEzB,kEAAkE;IAClE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAE/B,4CAA4C;IAC5C,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC;IAE9B,oCAAoC;IACpC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC;IAEzB,mDAAmD;IACnD,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,EAAE,UAAU,WAAW,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAmCtE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🗄️ Generic cache interface and LRU cache implementation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Least Recently Used (LRU) cache with a maximum capacity.
|
|
8
|
+
*
|
|
9
|
+
* When the cache reaches capacity, the least recently used entry is evicted.
|
|
10
|
+
* Both `get` and `set` operations update the access order.
|
|
11
|
+
*
|
|
12
|
+
* ### Example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const cache = createLruCache<string, number>(2);
|
|
16
|
+
* cache.set("a", 1);
|
|
17
|
+
* cache.set("b", 2);
|
|
18
|
+
* cache.set("c", 3); // Evicts "a"
|
|
19
|
+
* cache.has("a"); // false
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const createLruCache = (capacity) => {
|
|
23
|
+
const internalMap = new Map();
|
|
24
|
+
return {
|
|
25
|
+
has: (key) => internalMap.has(key),
|
|
26
|
+
get: (key) => {
|
|
27
|
+
const value = internalMap.get(key);
|
|
28
|
+
if (value === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
// Move to end (most recently used)
|
|
31
|
+
internalMap.delete(key);
|
|
32
|
+
internalMap.set(key, value);
|
|
33
|
+
return value;
|
|
34
|
+
},
|
|
35
|
+
set: (key, val) => {
|
|
36
|
+
// If key exists, delete it first to update order
|
|
37
|
+
if (internalMap.has(key)) {
|
|
38
|
+
internalMap.delete(key);
|
|
39
|
+
}
|
|
40
|
+
else if (internalMap.size === capacity) {
|
|
41
|
+
// Evict least recently used (first entry)
|
|
42
|
+
const firstKey = internalMap.keys().next().value;
|
|
43
|
+
internalMap.delete(firstKey);
|
|
44
|
+
}
|
|
45
|
+
internalMap.set(key, val);
|
|
46
|
+
},
|
|
47
|
+
delete: (key) => {
|
|
48
|
+
internalMap.delete(key);
|
|
49
|
+
},
|
|
50
|
+
map: internalMap,
|
|
51
|
+
};
|
|
52
|
+
};
|
package/dist/src/Callbacks.d.ts
CHANGED
|
@@ -1,20 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Brand } from "./Brand.js";
|
|
2
|
+
import { RandomBytesDep } from "./Crypto.js";
|
|
3
|
+
import { Id } from "./Type.js";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Request-response correlation for callbacks across boundaries.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* Stores callbacks with unique IDs and executes them once with an optional
|
|
8
|
+
* argument. Executed callbacks are automatically removed.
|
|
8
9
|
*
|
|
9
|
-
* This is useful for
|
|
10
|
-
*
|
|
10
|
+
* This is useful for correlating asynchronous request-response operations
|
|
11
|
+
* across boundaries where callback functions cannot be passed directly (e.g.,
|
|
12
|
+
* web workers, message queues).
|
|
13
|
+
*
|
|
14
|
+
* The `execute` method intentionally does not use try-catch or {@link Result}
|
|
15
|
+
* because it's the callback's responsibility to handle its own errors.
|
|
16
|
+
*
|
|
17
|
+
* ### Example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* // No-argument callbacks
|
|
21
|
+
* const callbacks = createCallbacks(deps);
|
|
22
|
+
* const id = callbacks.register(() => console.log("called"));
|
|
23
|
+
* callbacks.execute(id);
|
|
24
|
+
*
|
|
25
|
+
* // With argument callbacks
|
|
26
|
+
* const stringCallbacks = createCallbacks<string>(deps);
|
|
27
|
+
* const id = stringCallbacks.register((value) => {
|
|
28
|
+
* console.log(value);
|
|
29
|
+
* });
|
|
30
|
+
* stringCallbacks.execute(id, "hello");
|
|
31
|
+
*
|
|
32
|
+
* // Promise.withResolvers pattern
|
|
33
|
+
* const promiseCallbacks = createCallbacks<string>(deps);
|
|
34
|
+
* const { promise, resolve } = Promise.withResolvers<string>();
|
|
35
|
+
* const id = promiseCallbacks.register(resolve);
|
|
36
|
+
* promiseCallbacks.execute(id, "resolved value");
|
|
37
|
+
* await promise; // "resolved value"
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @template T - The type of argument passed to callbacks (defaults to undefined
|
|
41
|
+
* for no-argument callbacks)
|
|
11
42
|
*/
|
|
12
|
-
export interface Callbacks {
|
|
43
|
+
export interface Callbacks<T = undefined> {
|
|
13
44
|
/** Registers a callback function and returns a unique ID. */
|
|
14
|
-
readonly register: (callback: (arg
|
|
45
|
+
readonly register: (callback: (arg: T) => void) => CallbackId;
|
|
15
46
|
/** Executes and removes a callback associated with the given ID. */
|
|
16
|
-
readonly execute: (id: CallbackId, arg
|
|
47
|
+
readonly execute: T extends undefined ? (id: CallbackId) => undefined : (id: CallbackId, arg: T) => undefined;
|
|
17
48
|
}
|
|
18
|
-
|
|
19
|
-
export
|
|
49
|
+
/** Unique identifier for a callback in {@link Callbacks}. */
|
|
50
|
+
export type CallbackId = Id & Brand<"Callback">;
|
|
51
|
+
/** Creates a new {@link Callbacks}. */
|
|
52
|
+
export declare const createCallbacks: <T = undefined>(deps: RandomBytesDep) => Callbacks<T>;
|
|
20
53
|
//# sourceMappingURL=Callbacks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Callbacks.d.ts","sourceRoot":"","sources":["../../src/Callbacks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Callbacks.d.ts","sourceRoot":"","sources":["../../src/Callbacks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAY,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,SAAS;IACtC,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,KAAK,UAAU,CAAC;IAE9D,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,CAAC,SAAS,SAAS,GACjC,CAAC,EAAE,EAAE,UAAU,KAAK,SAAS,GAC7B,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC;CAC3C;AAED,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAEhD,uCAAuC;AACvC,eAAO,MAAM,eAAe,GAAI,CAAC,GAAG,SAAS,EAC3C,MAAM,cAAc,KACnB,SAAS,CAAC,CAAC,CAsBb,CAAC"}
|
package/dist/src/Callbacks.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
import { createId } from "./Type.js";
|
|
2
|
+
/** Creates a new {@link Callbacks}. */
|
|
1
3
|
export const createCallbacks = (deps) => {
|
|
2
4
|
const callbackMap = new Map();
|
|
3
|
-
|
|
5
|
+
return {
|
|
4
6
|
register: (callback) => {
|
|
5
|
-
const id = deps
|
|
7
|
+
const id = createId(deps);
|
|
6
8
|
callbackMap.set(id, callback);
|
|
7
9
|
return id;
|
|
8
10
|
},
|
|
9
|
-
execute: (id,
|
|
11
|
+
execute: (id, ...args) => {
|
|
10
12
|
const callback = callbackMap.get(id);
|
|
11
|
-
if (callback)
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
if (!callback)
|
|
14
|
+
return;
|
|
15
|
+
callbackMap.delete(id);
|
|
16
|
+
if (args.length === 0) {
|
|
17
|
+
// Called without argument (undefined case)
|
|
18
|
+
callback();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
callback(args[0]);
|
|
14
22
|
}
|
|
15
23
|
},
|
|
16
24
|
};
|
|
17
|
-
return callbacks;
|
|
18
25
|
};
|
package/dist/src/Console.d.ts
CHANGED
|
@@ -13,14 +13,28 @@
|
|
|
13
13
|
* ### Example
|
|
14
14
|
*
|
|
15
15
|
* ```ts
|
|
16
|
-
* deps.console.log("[
|
|
16
|
+
* deps.console.log("[evolu]", "createEvoluInstance", { name });
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
19
|
* **Tip**: In browser dev tools, you can filter logs by tag (e.g., `[db]`) to
|
|
20
|
-
* quickly find relevant messages.
|
|
20
|
+
* quickly find relevant messages. In Node.js, use `grep` to filter output:
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* ```bash
|
|
23
|
+
* node app.js | grep "\[relay\]" # Show only relay logs
|
|
24
|
+
* node app.js | grep -E "\[db\]|\[sql\]" # Show db and sql logs
|
|
25
|
+
* node app.js | grep -v "\[debug\]" # Hide debug logs
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Or add to package.json scripts:
|
|
29
|
+
*
|
|
30
|
+
* ```json
|
|
31
|
+
* {
|
|
32
|
+
* "scripts": {
|
|
33
|
+
* "dev:relay": "node app.js | grep \"\\[relay\\]\"",
|
|
34
|
+
* "dev:db": "node app.js | grep -E \"\\[db\\]|\\[sql\\]\""
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
24
38
|
*
|
|
25
39
|
* @module
|
|
26
40
|
*/
|
|
@@ -43,6 +57,8 @@ export interface Console {
|
|
|
43
57
|
debug: (...args: Array<any>) => void;
|
|
44
58
|
/** Starts a timer with an optional label */
|
|
45
59
|
time: (label?: string) => void;
|
|
60
|
+
/** Logs the elapsed time for a timer without ending it */
|
|
61
|
+
timeLog: (label?: string, ...data: Array<any>) => void;
|
|
46
62
|
/** Ends a timer and logs the elapsed time */
|
|
47
63
|
timeEnd: (label?: string) => void;
|
|
48
64
|
/** Displays an object's properties in a detailed format */
|
|
@@ -55,8 +71,6 @@ export interface Console {
|
|
|
55
71
|
countReset: (label?: string) => void;
|
|
56
72
|
/** Writes a message if the value is falsy, otherwise does nothing */
|
|
57
73
|
assert: (value: any, message?: string, ...optionalParams: Array<any>) => void;
|
|
58
|
-
/** Logs the elapsed time for a timer without ending it */
|
|
59
|
-
timeLog: (label?: string, ...data: Array<any>) => void;
|
|
60
74
|
/** Prints a stack trace with an optional message */
|
|
61
75
|
trace: (message?: any, ...optionalParams: Array<any>) => void;
|
|
62
76
|
}
|
|
@@ -75,4 +89,15 @@ export interface ConsoleConfig {
|
|
|
75
89
|
}
|
|
76
90
|
/** Creates a console instance using the global console. */
|
|
77
91
|
export declare const createConsole: (config?: ConsoleConfig) => Console;
|
|
92
|
+
export interface ConsoleWithTimeConfig extends ConsoleConfig {
|
|
93
|
+
/**
|
|
94
|
+
* Type of timestamp to prepend to log messages.
|
|
95
|
+
*
|
|
96
|
+
* - 'absolute': Shows actual time (e.g., "14:32:15.234")
|
|
97
|
+
* - 'relative': Shows time since console creation (e.g., "+1.234s")
|
|
98
|
+
*/
|
|
99
|
+
readonly timestampType: "absolute" | "relative";
|
|
100
|
+
}
|
|
101
|
+
/** Creates a console instance with timestamp prefixes. */
|
|
102
|
+
export declare const createConsoleWithTime: (config?: ConsoleWithTimeConfig) => Console;
|
|
78
103
|
//# sourceMappingURL=Console.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Console.d.ts","sourceRoot":"","sources":["../../src/Console.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Console.d.ts","sourceRoot":"","sources":["../../src/Console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,sEAAsE;IACtE,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,uCAAuC;IACvC,GAAG,EAAE,C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EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAE9E,oDAAoD;IACpD,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CAC/D;AAED,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,2DAA2D;AAC3D,eAAO,MAAM,aAAa,GAAI,SAAQ,aAAkB,KAAG,OAgE1D,CAAC;AAEF,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC1D;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAAC;CACjD;AAED,0DAA0D;AAC1D,eAAO,MAAM,qBAAqB,GAChC,SAAQ,qBAAqD,KAC5D,OAmDF,CAAC"}
|
package/dist/src/Console.js
CHANGED
|
@@ -13,14 +13,28 @@
|
|
|
13
13
|
* ### Example
|
|
14
14
|
*
|
|
15
15
|
* ```ts
|
|
16
|
-
* deps.console.log("[
|
|
16
|
+
* deps.console.log("[evolu]", "createEvoluInstance", { name });
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
19
|
* **Tip**: In browser dev tools, you can filter logs by tag (e.g., `[db]`) to
|
|
20
|
-
* quickly find relevant messages.
|
|
20
|
+
* quickly find relevant messages. In Node.js, use `grep` to filter output:
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* ```bash
|
|
23
|
+
* node app.js | grep "\[relay\]" # Show only relay logs
|
|
24
|
+
* node app.js | grep -E "\[db\]|\[sql\]" # Show db and sql logs
|
|
25
|
+
* node app.js | grep -v "\[debug\]" # Hide debug logs
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Or add to package.json scripts:
|
|
29
|
+
*
|
|
30
|
+
* ```json
|
|
31
|
+
* {
|
|
32
|
+
* "scripts": {
|
|
33
|
+
* "dev:relay": "node app.js | grep \"\\[relay\\]\"",
|
|
34
|
+
* "dev:db": "node app.js | grep -E \"\\[db\\]|\\[sql\\]\""
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
24
38
|
*
|
|
25
39
|
* @module
|
|
26
40
|
*/
|
|
@@ -58,6 +72,11 @@ export const createConsole = (config = {}) => {
|
|
|
58
72
|
if (instance.enabled)
|
|
59
73
|
console.time(label);
|
|
60
74
|
},
|
|
75
|
+
timeLog: (label, ...data) => {
|
|
76
|
+
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
|
|
77
|
+
if (instance.enabled)
|
|
78
|
+
console.timeLog(label, ...data);
|
|
79
|
+
},
|
|
61
80
|
timeEnd: (label) => {
|
|
62
81
|
// eslint-disable-next-line no-console
|
|
63
82
|
if (instance.enabled)
|
|
@@ -88,11 +107,6 @@ export const createConsole = (config = {}) => {
|
|
|
88
107
|
if (instance.enabled)
|
|
89
108
|
console.assert(value, message, ...optionalParams);
|
|
90
109
|
},
|
|
91
|
-
timeLog: (label, ...data) => {
|
|
92
|
-
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
|
|
93
|
-
if (instance.enabled)
|
|
94
|
-
console.timeLog(label, ...data);
|
|
95
|
-
},
|
|
96
110
|
trace: (message, ...optionalParams) => {
|
|
97
111
|
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
|
|
98
112
|
if (instance.enabled)
|
|
@@ -101,3 +115,52 @@ export const createConsole = (config = {}) => {
|
|
|
101
115
|
};
|
|
102
116
|
return instance;
|
|
103
117
|
};
|
|
118
|
+
/** Creates a console instance with timestamp prefixes. */
|
|
119
|
+
export const createConsoleWithTime = (config = { timestampType: "relative" }) => {
|
|
120
|
+
const console = createConsole(config);
|
|
121
|
+
const startTime = performance.now();
|
|
122
|
+
const getTimestamp = () => {
|
|
123
|
+
if (config.timestampType === "relative") {
|
|
124
|
+
const elapsed = (performance.now() - startTime) / 1000;
|
|
125
|
+
// Format for better readability at different time scales
|
|
126
|
+
if (elapsed < 60) {
|
|
127
|
+
// Under 1 minute: show seconds with millisecond precision
|
|
128
|
+
return `+${elapsed.toFixed(3)}s`;
|
|
129
|
+
}
|
|
130
|
+
else if (elapsed < 3600) {
|
|
131
|
+
// 1 minute to 1 hour: show minutes and seconds with millisecond precision
|
|
132
|
+
const minutes = Math.floor(elapsed / 60);
|
|
133
|
+
const seconds = (elapsed % 60).toFixed(3);
|
|
134
|
+
return `+${minutes}m${seconds}s`;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// Over 1 hour: show hours, minutes, and seconds with millisecond precision
|
|
138
|
+
const hours = Math.floor(elapsed / 3600);
|
|
139
|
+
const minutes = Math.floor((elapsed % 3600) / 60);
|
|
140
|
+
const seconds = ((elapsed % 3600) % 60).toFixed(3);
|
|
141
|
+
return `+${hours}h${minutes}m${seconds}s`;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// Absolute time - format as HH:MM:SS.mmm
|
|
146
|
+
const now = new Date();
|
|
147
|
+
const hours = now.getHours().toString().padStart(2, "0");
|
|
148
|
+
const minutes = now.getMinutes().toString().padStart(2, "0");
|
|
149
|
+
const seconds = now.getSeconds().toString().padStart(2, "0");
|
|
150
|
+
const milliseconds = now.getMilliseconds().toString().padStart(3, "0");
|
|
151
|
+
return `${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const withTimestamp = (fn) => (...args) => {
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
156
|
+
fn(`[${getTimestamp()}]`, ...args);
|
|
157
|
+
};
|
|
158
|
+
// Override methods that should have timestamps
|
|
159
|
+
console.log = withTimestamp(console.log);
|
|
160
|
+
console.info = withTimestamp(console.info);
|
|
161
|
+
console.warn = withTimestamp(console.warn);
|
|
162
|
+
console.error = withTimestamp(console.error);
|
|
163
|
+
console.debug = withTimestamp(console.debug);
|
|
164
|
+
console.trace = withTimestamp(console.trace);
|
|
165
|
+
return console;
|
|
166
|
+
};
|
package/dist/src/Crypto.d.ts
CHANGED
|
@@ -1,49 +1,64 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 🔒
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
1
|
import { Result } from "./Result.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { NonNegativeInt } from "./Type.js";
|
|
3
|
+
export interface RandomBytes {
|
|
4
|
+
/**
|
|
5
|
+
* Creates cryptographically secure random bytes with type-safe length
|
|
6
|
+
* branding.
|
|
7
|
+
*
|
|
8
|
+
* Uses the operating system's cryptographically secure random number
|
|
9
|
+
* generator (crypto.getRandomValues) to generate high-quality entropy
|
|
10
|
+
* suitable for cryptographic operations.
|
|
11
|
+
*
|
|
12
|
+
* ### Type Safety
|
|
13
|
+
*
|
|
14
|
+
* Returns specific branded types for common sizes:
|
|
15
|
+
*
|
|
16
|
+
* - `Random16` for 16-byte values (128 bits)
|
|
17
|
+
* - `Random32` for 32-byte values (256 bits)
|
|
18
|
+
* - `Random64` for 64-byte values (512 bits)
|
|
19
|
+
* - `Random` for any other size
|
|
20
|
+
*
|
|
21
|
+
* ### Example
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const nonce = randomBytes.create(16); // Type: Random16
|
|
25
|
+
* const key = randomBytes.create(32); // Type: Random32
|
|
26
|
+
* const seed = randomBytes.create(64); // Type: Random64
|
|
27
|
+
* const custom = randomBytes.create(48); // Type: Random
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
create(bytesLength: 16): Entropy16;
|
|
31
|
+
create(bytesLength: 32): Entropy32;
|
|
32
|
+
create(bytesLength: 64): Entropy64;
|
|
33
|
+
create(bytesLength: number): Entropy;
|
|
14
34
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export type CreateMnemonic = () => Mnemonic;
|
|
18
|
-
export interface CreateMnemonicDep {
|
|
19
|
-
readonly createMnemonic: CreateMnemonic;
|
|
35
|
+
export interface RandomBytesDep {
|
|
36
|
+
readonly randomBytes: RandomBytes;
|
|
20
37
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export declare const
|
|
38
|
+
declare const Entropy: import("./Type.js").BrandType<import("./Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError>, "Entropy", import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, never>;
|
|
39
|
+
type Entropy = typeof Entropy.Type;
|
|
40
|
+
export declare const Entropy16: 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>>;
|
|
41
|
+
export type Entropy16 = typeof Entropy16.Type;
|
|
42
|
+
export declare const Entropy32: 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>>;
|
|
43
|
+
export type Entropy32 = typeof Entropy32.Type;
|
|
44
|
+
export declare const Entropy64: 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>, "Length64", import("./Type.js").LengthError<64>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
|
|
45
|
+
export type Entropy64 = typeof Entropy64.Type;
|
|
46
|
+
export declare const createRandomBytes: () => RandomBytes;
|
|
24
47
|
/**
|
|
25
48
|
* SLIP21.
|
|
26
49
|
*
|
|
27
50
|
* https://github.com/satoshilabs/slips/blob/master/slip-0021.md
|
|
28
51
|
*/
|
|
29
|
-
export declare const createSlip21: (seed:
|
|
52
|
+
export declare const createSlip21: (seed: Entropy16 | Entropy32 | Entropy64, path: ReadonlyArray<string | number>) => Entropy32;
|
|
30
53
|
/**
|
|
31
|
-
*
|
|
32
|
-
* derived key.
|
|
33
|
-
*
|
|
34
|
-
* Reduces the 256-bit SLIP-21 output to 126 bits (21 chars × 6 bits) for a
|
|
35
|
-
* compact, human-readable, and shareable identifier suitable for UI display or
|
|
36
|
-
* URL use. While this lowers entropy, 126 bits remains cryptographically secure
|
|
37
|
-
* for uniqueness and unpredictability in most applications (comparable to
|
|
38
|
-
* UUIDv4's 122 bits).
|
|
54
|
+
* Derives a single node in the SLIP-21 hierarchical key derivation.
|
|
39
55
|
*
|
|
40
|
-
*
|
|
56
|
+
* @see {@link createSlip21}
|
|
41
57
|
*/
|
|
42
|
-
export declare const
|
|
58
|
+
export declare const deriveSlip21Node: (label: string, parentNode: Entropy64) => Entropy64;
|
|
43
59
|
/** The encryption key for {@link SymmetricCrypto}. */
|
|
44
|
-
export declare const EncryptionKey: import("./Type.js").BrandType<import("./Type.js").BrandType<import("./Type.js").Type<"
|
|
60
|
+
export declare const EncryptionKey: 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>;
|
|
45
61
|
export type EncryptionKey = typeof EncryptionKey.Type;
|
|
46
|
-
export declare const createEncryptionKey: (seed: MnemonicSeed) => EncryptionKey;
|
|
47
62
|
/** Symmetric cryptography. */
|
|
48
63
|
export interface SymmetricCrypto {
|
|
49
64
|
readonly nonceLength: NonNegativeInt;
|
|
@@ -65,20 +80,18 @@ export interface SymmetricCryptoDecryptError {
|
|
|
65
80
|
*
|
|
66
81
|
* https://github.com/paulmillr/noble-ciphers?tab=readme-ov-file#which-cipher-should-i-pick
|
|
67
82
|
*/
|
|
68
|
-
export declare const createSymmetricCrypto: (deps:
|
|
83
|
+
export declare const createSymmetricCrypto: (deps: RandomBytesDep) => SymmetricCrypto;
|
|
69
84
|
/**
|
|
70
85
|
* Returns the PADMÉ padded length for a given input length.
|
|
71
86
|
*
|
|
72
87
|
* PADMÉ limits information leakage about the length of the plain-text for a
|
|
73
|
-
* wide range of encrypted data sizes.
|
|
74
|
-
*
|
|
75
|
-
|
|
76
|
-
export declare const padmePaddedLength: (length: NonNegativeInt) => NonNegativeInt;
|
|
77
|
-
/**
|
|
78
|
-
* Returns the PADMÉ padding length for a given input length. Uses
|
|
79
|
-
* {@link padmePaddedLength}.
|
|
88
|
+
* wide range of encrypted data sizes.
|
|
89
|
+
*
|
|
90
|
+
* See the PURBs paper for details: https://bford.info/pub/sec/purb.pdf
|
|
80
91
|
*/
|
|
81
|
-
export declare const
|
|
92
|
+
export declare const createPadmePaddedLength: (length: NonNegativeInt) => NonNegativeInt;
|
|
93
|
+
/** Creates a PADMÉ padding array of zeros for the given input length. */
|
|
94
|
+
export declare const createPadmePadding: (length: NonNegativeInt) => Uint8Array;
|
|
82
95
|
/**
|
|
83
96
|
* Performs a timing-safe comparison of two Uint8Arrays. Returns true if they
|
|
84
97
|
* are equal, false otherwise. Takes constant time regardless of where the
|
|
@@ -90,4 +103,5 @@ export type TimingSafeEqual = (a: Uint8Array, b: Uint8Array) => boolean;
|
|
|
90
103
|
export interface TimingSafeEqualDep {
|
|
91
104
|
readonly timingSafeEqual: TimingSafeEqual;
|
|
92
105
|
}
|
|
106
|
+
export {};
|
|
93
107
|
//# sourceMappingURL=Crypto.d.ts.map
|
package/dist/src/Crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAW,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAiB,cAAc,EAAc,MAAM,WAAW,CAAC;AAEtE,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED,QAAA,MAAM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