@cero-base/core 1.16.1 → 1.18.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.
@@ -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
- /** Fresh nonzero uint32 block-header stamp not already used by a known epoch. */
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
@@ -297,8 +249,9 @@ export class Database extends ReadyResource {
297
249
  * linearization time.
298
250
  *
299
251
  * @param {Uint8Array[]} encoded
252
+ * @returns {Promise<boolean>} whether the ops change anything
300
253
  */
301
- _dryRun(encoded: Uint8Array[]): Promise<void>;
254
+ _dryRun(encoded: Uint8Array[]): Promise<boolean>;
302
255
  /**
303
256
  * Read a row. With no `query`: list all (collection) or fetch the one
304
257
  * record (single). With a string id: fetch that specific row.
@@ -358,19 +311,21 @@ export class Database extends ReadyResource {
358
311
  }>;
359
312
  /**
360
313
  * Claim writership on an existing room by signing our writer key with the
361
- * member identity and appending optimistically. Admission only — the device
362
- * 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).
363
316
  *
364
317
  * @returns {Promise<void>}
365
318
  */
366
319
  claim(): Promise<void>;
320
+ /** The claim-writer op for this device, signed by the member identity. */
321
+ claimOp(): any;
367
322
  /**
368
323
  * Resolve once the bee becomes writable, or reject after `timeout` ms.
369
324
  *
370
325
  * @param {{ timeout?: number }} [opts]
371
326
  * @returns {Promise<void>}
372
327
  */
373
- whenWritable({ timeout }?: {
328
+ whenWritable(opts?: {
374
329
  timeout?: number;
375
330
  }): Promise<void>;
376
331
  /**
@@ -422,7 +377,6 @@ export class Database extends ReadyResource {
422
377
  lte: object;
423
378
  };
424
379
  } | null;
425
- _addHook(map: any, op: any, fn: any): () => void;
426
380
  _write(verb: any, hook: any, publicKey: any): Promise<void>;
427
381
  }
428
382
  export type DatabaseOpts = {
@@ -521,6 +475,5 @@ export type Ref = {
521
475
  };
522
476
  export type HookFn = (ctx: any) => any | Promise<any>;
523
477
  import ReadyResource from 'ready-resource';
524
- import { Identity } from '../identity/index.js';
525
478
  import { Keyring } from './encryption.js';
526
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;
@@ -98,6 +98,16 @@ export class CeroError extends Error {
98
98
  * @param {string} [msg]
99
99
  */
100
100
  static DENIED(reason?: string | null, msg?: string): CeroError;
101
+ /**
102
+ * An apply-time rule refused the op. Every peer reaches this verdict from the
103
+ * same node and the same view, so it aborts the writer's whole batch — which
104
+ * is what makes a transaction atomic. Reserve it for deterministic decisions:
105
+ * anything that could differ between peers must not abort, or they fork.
106
+ *
107
+ * @param {string} rule Which rule refused, e.g. 'write' or 'own'.
108
+ * @param {string} [msg]
109
+ */
110
+ static REFUSED(rule: string, msg?: string): CeroError;
101
111
  /**
102
112
  * Pairing handshake did not complete in time.
103
113
  *
@@ -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
- /** @type {(dbKey: Uint8Array, writer: Uint8Array, appender: Uint8Array) => Uint8Array} */
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";
@@ -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. */
@@ -141,7 +141,7 @@ export class Pairing extends ReadyResource {
141
141
  * @returns {Promise<void>}
142
142
  */
143
143
  resume(): Promise<void>;
144
- _onCandidate(req: any): Promise<void>;
144
+ _oncandidate(req: any): Promise<void>;
145
145
  }
146
146
  export type PairingOpts = {
147
147
  /**