@evolu/common 6.0.1-preview.4 → 6.0.1-preview.5

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.
@@ -79,4 +79,15 @@ export declare const padmePaddedLength: (length: NonNegativeInt) => NonNegativeI
79
79
  * {@link padmePaddedLength}.
80
80
  */
81
81
  export declare const padmePaddingLength: (length: NonNegativeInt) => NonNegativeInt;
82
+ /**
83
+ * Performs a timing-safe comparison of two Uint8Arrays. Returns true if they
84
+ * are equal, false otherwise. Takes constant time regardless of where the
85
+ * arrays differ.
86
+ *
87
+ * @see https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
88
+ */
89
+ export type TimingSafeEqual = (a: Uint8Array, b: Uint8Array) => boolean;
90
+ export interface TimingSafeEqualDep {
91
+ readonly timingSafeEqual: TimingSafeEqual;
92
+ }
82
93
  //# sourceMappingURL=Crypto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAc,MAAM,EAAW,MAAM,aAAa,CAAC;AAC1D,OAAO,EAEL,EAAE,EAEF,QAAQ,EACR,cAAc,EAEf,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,yDAAyD;AACzD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,WAAW,CAAC;AAEtE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;CAC/C;AAED,oFAAoF;AACpF,eAAO,MAAM,iBAAiB,EAAE,iBACS,CAAC;AAE1C,MAAM,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC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,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC;AAExE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C"}
@@ -1,4 +1,5 @@
1
1
  import { ConsoleConfig } from "../Console.js";
2
+ import { TimingSafeEqualDep } from "../Crypto.js";
2
3
  import { Result } from "../Result.js";
3
4
  import { SqliteError } from "../Sqlite.js";
4
5
  import { SimpleName } from "../Type.js";
@@ -9,5 +10,6 @@ export interface Relay extends Disposable {
9
10
  export interface RelayConfig extends ConsoleConfig {
10
11
  readonly name?: SimpleName;
11
12
  }
12
- export declare const createRelayStorage: (deps: SqliteStorageDeps) => (options: CreateSqliteStorageBaseOptions) => Result<Storage, SqliteError>;
13
+ export type RelaySqliteStorageDeps = SqliteStorageDeps & TimingSafeEqualDep;
14
+ export declare const createRelayStorage: (deps: RelaySqliteStorageDeps) => (options: CreateSqliteStorageBaseOptions) => Result<Storage, SqliteError>;
13
15
  //# sourceMappingURL=Relay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Relay.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Relay.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAM,MAAM,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAO,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAqB,OAAO,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAEL,8BAA8B,EAC9B,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,KAAM,SAAQ,UAAU;CAAG;AAE5C,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED,eAAO,MAAM,kBAAkB,GAC5B,MAAM,iBAAiB,MACvB,SAAS,8BAA8B,KAAG,MAAM,CAAC,OAAO,EAAE,WAAW,CAsHrE,CAAC"}
1
+ {"version":3,"file":"Relay.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Relay.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAM,MAAM,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAO,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAqB,OAAO,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAEL,8BAA8B,EAC9B,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,KAAM,SAAQ,UAAU;CAAG;AAE5C,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAE5E,eAAO,MAAM,kBAAkB,GAC5B,MAAM,sBAAsB,MAC5B,SAAS,8BAA8B,KAAG,MAAM,CAAC,OAAO,EAAE,WAAW,CAsHrE,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { isNonEmptyReadonlyArray } from "../Array.js";
2
- import { eqArrayNumber } from "../Eq.js";
3
2
  import { ok } from "../Result.js";
4
3
  import { sql } from "../Sqlite.js";
5
4
  import { createSqliteStorageBase, } from "./Storage.js";
@@ -64,7 +63,7 @@ export const createRelayStorage = (deps) => (options) => {
64
63
  }
65
64
  return true;
66
65
  }
67
- return eqArrayNumber(rows[0].writeKey, writeKey);
66
+ return deps.timingSafeEqual(rows[0].writeKey, writeKey);
68
67
  },
69
68
  writeMessages: (ownerId, messages) => {
70
69
  const result = deps.sqlite.transaction(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evolu/common",
3
- "version": "6.0.1-preview.4",
3
+ "version": "6.0.1-preview.5",
4
4
  "description": "TypeScript library and local-first framework",
5
5
  "keywords": [
6
6
  "evolu",
package/src/Crypto.ts CHANGED
@@ -189,3 +189,16 @@ export const padmePaddedLength = (length: NonNegativeInt): NonNegativeInt => {
189
189
  export const padmePaddingLength = (length: NonNegativeInt): NonNegativeInt => {
190
190
  return (padmePaddedLength(length) - length) as NonNegativeInt;
191
191
  };
192
+
193
+ /**
194
+ * Performs a timing-safe comparison of two Uint8Arrays. Returns true if they
195
+ * are equal, false otherwise. Takes constant time regardless of where the
196
+ * arrays differ.
197
+ *
198
+ * @see https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
199
+ */
200
+ export type TimingSafeEqual = (a: Uint8Array, b: Uint8Array) => boolean;
201
+
202
+ export interface TimingSafeEqualDep {
203
+ readonly timingSafeEqual: TimingSafeEqual;
204
+ }
@@ -1,6 +1,6 @@
1
1
  import { isNonEmptyReadonlyArray } from "../Array.js";
2
2
  import { ConsoleConfig } from "../Console.js";
3
- import { eqArrayNumber } from "../Eq.js";
3
+ import { TimingSafeEqualDep } from "../Crypto.js";
4
4
  import { ok, Result } from "../Result.js";
5
5
  import { sql, SqliteError } from "../Sqlite.js";
6
6
  import { SimpleName } from "../Type.js";
@@ -19,8 +19,10 @@ export interface RelayConfig extends ConsoleConfig {
19
19
  readonly name?: SimpleName;
20
20
  }
21
21
 
22
+ export type RelaySqliteStorageDeps = SqliteStorageDeps & TimingSafeEqualDep;
23
+
22
24
  export const createRelayStorage =
23
- (deps: SqliteStorageDeps) =>
25
+ (deps: RelaySqliteStorageDeps) =>
24
26
  (options: CreateSqliteStorageBaseOptions): Result<Storage, SqliteError> => {
25
27
  const sqliteStorageBase = createSqliteStorageBase(deps)(options);
26
28
  if (!sqliteStorageBase.ok) return sqliteStorageBase;
@@ -87,7 +89,7 @@ export const createRelayStorage =
87
89
  return true;
88
90
  }
89
91
 
90
- return eqArrayNumber(rows[0].writeKey, writeKey);
92
+ return deps.timingSafeEqual(rows[0].writeKey, writeKey);
91
93
  },
92
94
 
93
95
  writeMessages: (ownerId, messages) => {