@cero-base/core 1.17.0 → 1.18.1
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/package.json +10 -9
- package/src/blobs/codec.js +2 -1
- package/src/database/dispatch.js +41 -1
- package/src/database/encryption.js +5 -3
- package/src/database/hooks.js +112 -0
- package/src/database/index.js +71 -467
- package/src/database/membership.js +67 -0
- package/src/database/rotation.js +228 -0
- package/src/lib/utils.js +19 -6
- package/src/network/index.js +68 -2
- package/src/pairing/index.js +3 -3
- package/src/pairing/invite.js +4 -2
- package/src/storage/index.js +12 -6
- package/types/database/encryption.d.ts +1 -1
- package/types/database/hooks.d.ts +8 -0
- package/types/database/index.d.ts +8 -56
- package/types/database/membership.d.ts +7 -0
- package/types/database/rotation.d.ts +32 -0
- package/types/lib/utils.d.ts +6 -7
- package/types/network/index.d.ts +19 -0
- package/types/pairing/index.d.ts +1 -1
|
@@ -30,7 +30,7 @@ export class Database extends ReadyResource {
|
|
|
30
30
|
/** @param {Partial<DatabaseOpts>} [opts] */
|
|
31
31
|
constructor(opts?: Partial<DatabaseOpts>);
|
|
32
32
|
store: any;
|
|
33
|
-
identity: Identity;
|
|
33
|
+
identity: import("../index.js").Identity;
|
|
34
34
|
network: import("../index.js").Network;
|
|
35
35
|
spec: {
|
|
36
36
|
database: any;
|
|
@@ -61,11 +61,7 @@ export class Database extends ReadyResource {
|
|
|
61
61
|
namespace: string;
|
|
62
62
|
encryptionKey: Uint8Array<ArrayBufferLike>;
|
|
63
63
|
keyring: Keyring;
|
|
64
|
-
_rotation:
|
|
65
|
-
entropy: any;
|
|
66
|
-
stamp: number;
|
|
67
|
-
epoch: number;
|
|
68
|
-
};
|
|
64
|
+
_rotation: any;
|
|
69
65
|
_healTimer: any;
|
|
70
66
|
_healedFor: any;
|
|
71
67
|
applyOverride: (nodes: any, view: any, host: any) => Promise<void>;
|
|
@@ -138,8 +134,6 @@ export class Database extends ReadyResource {
|
|
|
138
134
|
* @returns {() => void} disposer
|
|
139
135
|
*/
|
|
140
136
|
onUpdate(fn: () => void, scope?: string): () => void;
|
|
141
|
-
_touch(nodes: any): void;
|
|
142
|
-
_byVerb: Map<any, any>;
|
|
143
137
|
/**
|
|
144
138
|
* Observe every applied op — local AND replicated (apply processes the merged
|
|
145
139
|
* log). The callback receives `{ op, name, row, writerKey, seq }` and runs
|
|
@@ -156,7 +150,6 @@ export class Database extends ReadyResource {
|
|
|
156
150
|
writerKey: any;
|
|
157
151
|
seq: number;
|
|
158
152
|
}) => void): () => void;
|
|
159
|
-
_observe(nodes: any): void;
|
|
160
153
|
/**
|
|
161
154
|
* Run all registered `before:op` hooks and emit the corresponding event.
|
|
162
155
|
*
|
|
@@ -223,41 +216,8 @@ export class Database extends ReadyResource {
|
|
|
223
216
|
rotate(retried?: boolean): Promise<{
|
|
224
217
|
epoch: number;
|
|
225
218
|
}>;
|
|
226
|
-
|
|
227
|
-
_randomStamp(): number;
|
|
228
|
-
/**
|
|
229
|
-
* Per-peer side of an applied rotation: open our envelope, learn the epoch
|
|
230
|
-
* secret, persist it locally. Peers without an envelope (removed members)
|
|
231
|
-
* simply stop here — every block after the announcement is noise to them.
|
|
232
|
-
* Our own in-flight rotation is deferred to `rotate()` (see above).
|
|
233
|
-
*
|
|
234
|
-
* @param {{ epoch: number, wrapped: Uint8Array, createdAt: number }} row
|
|
235
|
-
*/
|
|
236
|
-
_onEpoch(row: {
|
|
237
|
-
epoch: number;
|
|
238
|
-
wrapped: Uint8Array;
|
|
239
|
-
createdAt: number;
|
|
240
|
-
}): Promise<void>;
|
|
241
|
-
/**
|
|
242
|
-
* Safety net after boot (userData priming happens in EpochAutobee's
|
|
243
|
-
* `_bootState`): scan the epochs collection for anything applied but never
|
|
244
|
-
* hydrated — e.g. a crash between a rotation's append and its save.
|
|
245
|
-
*/
|
|
219
|
+
_onepoch(row: any): Promise<void>;
|
|
246
220
|
_loadEpochs(): Promise<void>;
|
|
247
|
-
/** Persist known epoch secrets to local userData (device-only, never replicates). */
|
|
248
|
-
_saveEpochs(): any;
|
|
249
|
-
/** Debounced trigger for the epoch/membership consistency check. */
|
|
250
|
-
_scheduleHeal(): void;
|
|
251
|
-
/**
|
|
252
|
-
* Convergence rotation: rotations author their envelope set against the
|
|
253
|
-
* rotator's possibly-stale local view, so after linearization the current
|
|
254
|
-
* epoch may include a since-removed member (who then still holds the
|
|
255
|
-
* current key) or miss a since-added one (who is locked out). Every
|
|
256
|
-
* REMOVE-capable writable device audits the current epoch's recipients
|
|
257
|
-
* against canonical membership and re-keys on mismatch. Only rooms that
|
|
258
|
-
* have rotated at least once are audited — rotation stays opt-in.
|
|
259
|
-
*/
|
|
260
|
-
_healEpochs(): Promise<void>;
|
|
261
221
|
/**
|
|
262
222
|
* Batch every write made through the transaction handle passed to `fn`
|
|
263
223
|
* into a single autobee append. The handle is this database with its own
|
|
@@ -281,14 +241,6 @@ export class Database extends ReadyResource {
|
|
|
281
241
|
* @returns {Promise<void>}
|
|
282
242
|
*/
|
|
283
243
|
write(ops: Array<[string, any]>): Promise<void>;
|
|
284
|
-
/**
|
|
285
|
-
* Record that the log contains ops from a newer app version than this
|
|
286
|
-
* peer understands. Fires `'behind'` once per version so apps can prompt
|
|
287
|
-
* an upgrade; the marker survives restarts via local core userData.
|
|
288
|
-
*
|
|
289
|
-
* @param {number} version
|
|
290
|
-
*/
|
|
291
|
-
_onFuture(version: number): void;
|
|
292
244
|
/**
|
|
293
245
|
* Validate ops against the committed view before appending: each op runs in
|
|
294
246
|
* a throwaway transaction with host effects stubbed, so a throwing handler
|
|
@@ -359,19 +311,21 @@ export class Database extends ReadyResource {
|
|
|
359
311
|
}>;
|
|
360
312
|
/**
|
|
361
313
|
* Claim writership on an existing room by signing our writer key with the
|
|
362
|
-
* member identity
|
|
363
|
-
* is named separately (bootstrap → set-device).
|
|
314
|
+
* member identity; the claim rides in the device core as an optimistic node.
|
|
315
|
+
* Admission only — the device is named separately (bootstrap → set-device).
|
|
364
316
|
*
|
|
365
317
|
* @returns {Promise<void>}
|
|
366
318
|
*/
|
|
367
319
|
claim(): Promise<void>;
|
|
320
|
+
/** The claim-writer op for this device, signed by the member identity. */
|
|
321
|
+
claimOp(): any;
|
|
368
322
|
/**
|
|
369
323
|
* Resolve once the bee becomes writable, or reject after `timeout` ms.
|
|
370
324
|
*
|
|
371
325
|
* @param {{ timeout?: number }} [opts]
|
|
372
326
|
* @returns {Promise<void>}
|
|
373
327
|
*/
|
|
374
|
-
whenWritable(
|
|
328
|
+
whenWritable(opts?: {
|
|
375
329
|
timeout?: number;
|
|
376
330
|
}): Promise<void>;
|
|
377
331
|
/**
|
|
@@ -423,7 +377,6 @@ export class Database extends ReadyResource {
|
|
|
423
377
|
lte: object;
|
|
424
378
|
};
|
|
425
379
|
} | null;
|
|
426
|
-
_addHook(map: any, op: any, fn: any): () => void;
|
|
427
380
|
_write(verb: any, hook: any, publicKey: any): Promise<void>;
|
|
428
381
|
}
|
|
429
382
|
export type DatabaseOpts = {
|
|
@@ -522,6 +475,5 @@ export type Ref = {
|
|
|
522
475
|
};
|
|
523
476
|
export type HookFn = (ctx: any) => any | Promise<any>;
|
|
524
477
|
import ReadyResource from 'ready-resource';
|
|
525
|
-
import { Identity } from '../identity/index.js';
|
|
526
478
|
import { Keyring } from './encryption.js';
|
|
527
479
|
import { EpochAutobee } from './encryption.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function claim(db: any): Promise<void>;
|
|
2
|
+
export function claimOp(db: any): any;
|
|
3
|
+
export function whenWritable(db: any, { timeout }?: {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}): Promise<any>;
|
|
6
|
+
export function addWriter(db: any, publicKey: any): Promise<any>;
|
|
7
|
+
export function removeWriter(db: any, publicKey: any): Promise<any>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function rotate(db: any, retried?: boolean): Promise<any>;
|
|
2
|
+
/**
|
|
3
|
+
* Per-peer side of an applied rotation: open our envelope, learn the epoch
|
|
4
|
+
* secret, persist it locally. Peers without an envelope (removed members)
|
|
5
|
+
* simply stop here — every block after the announcement is noise to them.
|
|
6
|
+
* Our own in-flight rotation is deferred to `rotate()` (see above).
|
|
7
|
+
*
|
|
8
|
+
* @param {import('./index.js').Database} db
|
|
9
|
+
* @param {{ epoch: number, wrapped: Uint8Array, createdAt: number }} row
|
|
10
|
+
*/
|
|
11
|
+
export function onepoch(db: import("./index.js").Database, row: {
|
|
12
|
+
epoch: number;
|
|
13
|
+
wrapped: Uint8Array;
|
|
14
|
+
createdAt: number;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Safety net after boot (userData priming happens in EpochAutobee's
|
|
18
|
+
* `_bootState`): scan the epochs collection for anything applied but never
|
|
19
|
+
* hydrated — e.g. a crash between a rotation's append and its save.
|
|
20
|
+
*/
|
|
21
|
+
export function hydrateEpochs(db: any): Promise<void>;
|
|
22
|
+
/** Debounced trigger for the epoch/membership consistency check. */
|
|
23
|
+
export function scheduleHeal(db: any): void;
|
|
24
|
+
/**
|
|
25
|
+
* Record that the log contains ops from a newer app version than this
|
|
26
|
+
* peer understands. Fires `'behind'` once per version so apps can prompt
|
|
27
|
+
* an upgrade; the marker survives restarts via local core userData.
|
|
28
|
+
*
|
|
29
|
+
* @param {import('./index.js').Database} db
|
|
30
|
+
* @param {number} version
|
|
31
|
+
*/
|
|
32
|
+
export function onfuture(db: import("./index.js").Database, version: number): void;
|
package/types/lib/utils.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* @returns {string}
|
|
5
5
|
*/
|
|
6
6
|
export function genId(): string;
|
|
7
|
+
export function addWriterPayload(dbKey: Uint8Array, writer: Uint8Array, appender: Uint8Array): Uint8Array;
|
|
8
|
+
export function claimWriterPayload(dbKey: Uint8Array, writer: Uint8Array): Uint8Array;
|
|
7
9
|
/**
|
|
8
10
|
* Whether `role` is granted `perm` under the default policy.
|
|
9
11
|
*
|
|
@@ -12,6 +14,9 @@ export function genId(): string;
|
|
|
12
14
|
* @returns {boolean}
|
|
13
15
|
*/
|
|
14
16
|
export function can(role: string, perm: string): boolean;
|
|
17
|
+
export function isRank(role: any): boolean;
|
|
18
|
+
export function grants(a: any, b: any): boolean;
|
|
19
|
+
export function outranks(a: any, b: any): boolean;
|
|
15
20
|
/**
|
|
16
21
|
* Stream-of-snapshots primitive. Couples a `get` (returns the latest value)
|
|
17
22
|
* with a `watch` (re-fires on change) and emits the newest snapshot every
|
|
@@ -40,10 +45,4 @@ export const toId: (key: Uint8Array) => string;
|
|
|
40
45
|
* @type {(id: string) => Uint8Array}
|
|
41
46
|
*/
|
|
42
47
|
export const toKey: (id: string) => Uint8Array;
|
|
43
|
-
|
|
44
|
-
export const addWriterPayload: (dbKey: Uint8Array, writer: Uint8Array, appender: Uint8Array) => Uint8Array;
|
|
45
|
-
/** @type {(dbKey: Uint8Array, writer: Uint8Array) => Uint8Array} */
|
|
46
|
-
export const claimWriterPayload: (dbKey: Uint8Array, writer: Uint8Array) => Uint8Array;
|
|
47
|
-
export function isRank(role: any): boolean;
|
|
48
|
-
export function grants(a: any, b: any): boolean;
|
|
49
|
-
export function outranks(a: any, b: any): boolean;
|
|
48
|
+
export { WRITE, INVITE, ASSIGN, REMOVE } from "./constants.js";
|
package/types/network/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ export class Network extends ReadyResource {
|
|
|
32
32
|
mirrors: any[];
|
|
33
33
|
_swarm: any;
|
|
34
34
|
wakeup: any;
|
|
35
|
+
info: any;
|
|
36
|
+
_peerInfo: Map<any, any>;
|
|
37
|
+
_infoSenders: Set<any>;
|
|
35
38
|
_replicateables: Set<any>;
|
|
36
39
|
_discoveries: Set<any>;
|
|
37
40
|
_injected: Set<any>;
|
|
@@ -72,6 +75,22 @@ export class Network extends ReadyResource {
|
|
|
72
75
|
* @returns {Promise<void>}
|
|
73
76
|
*/
|
|
74
77
|
refreshInjected(): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Declare this peer's self-reported info ({ name, ... }). Sent over an
|
|
80
|
+
* encrypted channel on every live and future connection — never on the
|
|
81
|
+
* radio advertisement or the DHT.
|
|
82
|
+
*
|
|
83
|
+
* @param {object | null} info
|
|
84
|
+
*/
|
|
85
|
+
setInfo(info: object | null): void;
|
|
86
|
+
/**
|
|
87
|
+
* Info a connected peer declared about itself, or null.
|
|
88
|
+
*
|
|
89
|
+
* @param {Uint8Array | string} key Peer public key (bytes or hex).
|
|
90
|
+
* @returns {object | null}
|
|
91
|
+
*/
|
|
92
|
+
getInfo(key: Uint8Array | string): object | null;
|
|
93
|
+
_attachInfo(conn: any): void;
|
|
75
94
|
/** @returns {Map<string, any>} Known peers keyed by public-key string. */
|
|
76
95
|
get peers(): Map<string, any>;
|
|
77
96
|
/** @returns {Set<any>} Live connection streams — swarm and injected. */
|
package/types/pairing/index.d.ts
CHANGED