@cero-base/core 1.18.2 → 1.19.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.
Files changed (46) hide show
  1. package/README.md +5 -6
  2. package/package.json +8 -8
  3. package/src/blobs/index.js +2 -2
  4. package/src/database/changes.js +37 -59
  5. package/src/database/dispatch.js +31 -45
  6. package/src/database/index.js +395 -343
  7. package/src/database/rotation.js +201 -189
  8. package/src/identity/index.js +3 -3
  9. package/src/lib/utils.js +50 -18
  10. package/src/pairing/candidate.js +125 -0
  11. package/src/pairing/index.js +6 -223
  12. package/src/pairing/request.js +102 -0
  13. package/src/storage/index.js +11 -18
  14. package/types/blobs/codec.d.ts +8 -8
  15. package/types/blobs/index.d.ts +34 -33
  16. package/types/blobs/server.d.ts +8 -8
  17. package/types/database/changes.d.ts +5 -7
  18. package/types/database/dispatch.d.ts +30 -23
  19. package/types/database/encryption.d.ts +14 -10
  20. package/types/database/envelope.d.ts +2 -2
  21. package/types/database/index.d.ts +173 -181
  22. package/types/database/rotation.d.ts +53 -30
  23. package/types/identity/index.d.ts +81 -81
  24. package/types/index.d.ts +37 -51
  25. package/types/lib/constants.d.ts +34 -38
  26. package/types/lib/errors.d.ts +10 -10
  27. package/types/lib/schema.d.ts +47 -37
  28. package/types/lib/spec/index.d.ts +29 -55
  29. package/types/lib/utils.d.ts +27 -17
  30. package/types/network/discovery.d.ts +7 -7
  31. package/types/network/index.d.ts +50 -48
  32. package/types/pairing/candidate.d.ts +37 -0
  33. package/types/pairing/index.d.ts +87 -139
  34. package/types/pairing/invite.d.ts +88 -88
  35. package/types/pairing/request.d.ts +135 -0
  36. package/types/rpc/client.d.ts +2 -2
  37. package/types/rpc/index.d.ts +33 -33
  38. package/types/rpc/peer.d.ts +9 -7
  39. package/types/rpc/server.d.ts +2 -2
  40. package/types/storage/index.d.ts +70 -68
  41. package/src/database/bootstrap.js +0 -133
  42. package/src/database/hooks.js +0 -112
  43. package/src/database/membership.js +0 -67
  44. package/types/database/bootstrap.d.ts +0 -20
  45. package/types/database/hooks.d.ts +0 -8
  46. package/types/database/membership.d.ts +0 -7
@@ -1,3 +1,28 @@
1
+ import ReadyResource from 'ready-resource';
2
+ import { encodeId, decodeId } from './codec.js';
3
+ export type BlobsOpts = {
4
+ /**
5
+ * Corestore (or compatible) used to host the blob core.
6
+ */
7
+ store: object;
8
+ /**
9
+ * Identity supplying the default encryption key.
10
+ */
11
+ identity?: import('../identity/index.js').Identity;
12
+ /**
13
+ * Optional network used to announce + replicate the core.
14
+ */
15
+ network?: import('../network/index.js').Network;
16
+ /**
17
+ * Pre-existing blob core key — joins an existing blob feed.
18
+ */
19
+ key?: Uint8Array;
20
+ /**
21
+ * Explicit encryption key, overrides `identity.encryptionKey`.
22
+ */
23
+ encryptionKey?: Uint8Array;
24
+ };
25
+ export type RawBlobId = import('./codec.js').RawBlobId;
1
26
  /**
2
27
  * @typedef {object} BlobsOpts
3
28
  * @property {object} store Corestore (or compatible) used to host the blob core.
@@ -9,10 +34,8 @@
9
34
  * @typedef {import('./codec.js').RawBlobId} RawBlobId
10
35
  */
11
36
  /** Thin wrapper over a single Hyperblobs core; deals only in raw blobIds. */
12
- export class Blobs extends ReadyResource {
13
- /** @param {BlobsOpts} [opts] */
14
- constructor({ store, identity, network, key, encryptionKey, name }?: BlobsOpts);
15
- store: any;
37
+ export declare class Blobs extends ReadyResource {
38
+ store: object;
16
39
  identity: import("../index.js").Identity;
17
40
  network: import("../index.js").Network;
18
41
  encryptionKey: Uint8Array<ArrayBufferLike>;
@@ -21,6 +44,8 @@ export class Blobs extends ReadyResource {
21
44
  core: any;
22
45
  hyperblobs: any;
23
46
  _discovery: import("../network/discovery.js").Discovery;
47
+ /** @param {BlobsOpts} [opts] */
48
+ constructor({ store, identity, network, key, encryptionKey, name }?: BlobsOpts);
24
49
  /**
25
50
  * Canonical z32 id of the underlying core (null until ready).
26
51
  *
@@ -39,18 +64,20 @@ export class Blobs extends ReadyResource {
39
64
  * @returns {Uint8Array | null}
40
65
  */
41
66
  get discoveryKey(): Uint8Array | null;
67
+ _open(): Promise<void>;
68
+ _close(): Promise<void>;
42
69
  /**
43
70
  * Store a buffer or readable stream, returning its raw hyperblobs blobId.
44
71
  *
45
72
  * @param {Uint8Array | import('streamx').Readable} input
46
73
  * @returns {Promise<RawBlobId>}
47
74
  */
48
- put(input: Uint8Array | import("streamx").Readable): Promise<RawBlobId>;
75
+ put(input: Uint8Array | import('streamx').Readable): Promise<RawBlobId>;
49
76
  /**
50
77
  * @param {import('streamx').Readable} input
51
78
  * @returns {Promise<RawBlobId>}
52
79
  */
53
- _putStream(input: import("streamx").Readable): Promise<RawBlobId>;
80
+ _putStream(input: import('streamx').Readable): Promise<RawBlobId>;
54
81
  /**
55
82
  * Resolve the blob bytes for a raw blobId. Fetches from peers if not local.
56
83
  *
@@ -66,7 +93,7 @@ export class Blobs extends ReadyResource {
66
93
  * @param {object} [opts]
67
94
  * @returns {import('streamx').Readable}
68
95
  */
69
- createReadStream(blobId: RawBlobId, opts?: object): import("streamx").Readable;
96
+ createReadStream(blobId: RawBlobId, opts?: object): import('streamx').Readable;
70
97
  /**
71
98
  * Clear the blocks backing a raw blobId from the local core.
72
99
  *
@@ -76,30 +103,4 @@ export class Blobs extends ReadyResource {
76
103
  clear(blobId: RawBlobId): Promise<void>;
77
104
  _guard(): void;
78
105
  }
79
- export type BlobsOpts = {
80
- /**
81
- * Corestore (or compatible) used to host the blob core.
82
- */
83
- store: object;
84
- /**
85
- * Identity supplying the default encryption key.
86
- */
87
- identity?: import("../identity/index.js").Identity;
88
- /**
89
- * Optional network used to announce + replicate the core.
90
- */
91
- network?: import("../network/index.js").Network;
92
- /**
93
- * Pre-existing blob core key — joins an existing blob feed.
94
- */
95
- key?: Uint8Array;
96
- /**
97
- * Explicit encryption key, overrides `identity.encryptionKey`.
98
- */
99
- encryptionKey?: Uint8Array;
100
- };
101
- export type RawBlobId = import("./codec.js").RawBlobId;
102
- import ReadyResource from 'ready-resource';
103
- import { encodeId } from './codec.js';
104
- import { decodeId } from './codec.js';
105
106
  export { encodeId, decodeId };
@@ -1,3 +1,7 @@
1
+ export type Resolved = {
2
+ key: Buffer;
3
+ encryptionKey: Buffer | null;
4
+ };
1
5
  /**
2
6
  * @typedef {{ key: Buffer, encryptionKey: Buffer | null }} Resolved
3
7
  */
@@ -6,18 +10,18 @@
6
10
  * Wraps hypercore-blob-server; the underlying store session is owned by
7
11
  * BlobServer and closed when `close()` is called.
8
12
  */
9
- export class FileServer {
13
+ export declare class FileServer {
14
+ resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
15
+ server: any;
10
16
  /**
11
17
  * @param {object} opts
12
18
  * @param {import('corestore')} opts.store
13
19
  * @param {(coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>} opts.resolve
14
20
  */
15
21
  constructor({ store, resolve }: {
16
- store: any;
22
+ store: import('corestore');
17
23
  resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
18
24
  });
19
- resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
20
- server: any;
21
25
  get port(): any;
22
26
  listen(): Promise<void>;
23
27
  /**
@@ -29,7 +33,3 @@ export class FileServer {
29
33
  getLink(id: string): string;
30
34
  close(): Promise<void>;
31
35
  }
32
- export type Resolved = {
33
- key: Buffer;
34
- encryptionKey: Buffer | null;
35
- };
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * Pull-driven delta stream over a collection: batches of `{ prev, next }`
3
- * pairs diffed between per-stream head cursors (`db.diff(col, { from })`).
4
- * Update ticks only mark the stream dirty — the diff runs when the reader
5
- * demands, so backpressure folds bursts into one bigger batch and nothing is
6
- * ever dropped. The first batch, and any batch after the view is swapped or
7
- * fast-forwarded to a new core, carries the full matching state as inserts
8
- * with `reset: true`.
3
+ * pairs diffed from the head this stream last reported. Update ticks only
4
+ * mark the stream dirty, the diff runs when the reader asks, so bursts fold
5
+ * into one batch and nothing is dropped. The first batch, and any batch after
6
+ * the view moved to another core, is the full matching state with `reset: true`.
9
7
  *
10
8
  * @param {import('./index.js').Database} db
11
9
  * @param {string} name Ref name (scopes the update ticks).
@@ -13,4 +11,4 @@
13
11
  * @param {(row: any) => boolean} matches
14
12
  * @returns {import('streamx').Readable}
15
13
  */
16
- export function makeChanges(db: import("./index.js").Database, name: string, col: string, matches: (row: any) => boolean): import("streamx").Readable;
14
+ export declare function makeChanges(db: import('./index.js').Database, name: string, col: string, matches: (row: any) => boolean): import('streamx').Readable;
@@ -1,31 +1,42 @@
1
+ export declare const BUILTINS: {
2
+ name: string;
3
+ verb: string;
4
+ }[];
1
5
  /**
2
6
  * Build the hyperdispatch router for a spec: wires membership, builtin, and
3
7
  * spec-defined collection/action ops, returning the router plus an apply loop.
4
8
  *
5
- * @param {{ dispatch: { Router: Function }, meta?: { refs?: Record<string, { kind?: string, builtin?: boolean, verb?: string }> } }} spec Generated hyperdispatch spec.
6
- * @param {string} ns Namespace prefix for collection and op names.
7
- * @param {Record<string, Function>} routes Custom action handlers keyed by route name.
8
- * @param {(err: Error) => void} [onerror] Called when a malformed node is skipped.
9
- * @param {() => Uint8Array | null} [getDbKey]
10
- * @param {{ onEpoch?: (row: { epoch: number, wrapped: Uint8Array, createdAt: number }) => Promise<void> }} [hooks] Per-peer side effects fired after an op applies (skipped in dry runs).
9
+ * @param {object} opts
10
+ * @param {{ dispatch: { Router: Function }, meta?: { refs?: Record<string, { kind?: string, builtin?: boolean, verb?: string }> } }} opts.spec Generated hyperdispatch spec.
11
+ * @param {string} opts.ns Namespace prefix for collection and op names.
12
+ * @param {Record<string, Function>} opts.routes Custom action handlers keyed by route name.
13
+ * @param {(err: Error) => void} opts.onerror Called when a malformed node is skipped.
14
+ * @param {() => Uint8Array | null} opts.key The database key, null until the bee booted.
15
+ * @param {(row: { epoch: number, stamp: number, wrapped: Uint8Array, commit: Uint8Array }) => Promise<void>} opts.onepoch Per-peer side of an applied rotation (skipped in dry runs).
11
16
  * @returns {{ dispatcher: object, apply: (nodes: Array<{ value: Buffer, key: Buffer }>, view: object, host: object) => Promise<void> }}
12
17
  */
13
- export function makeDispatcher(spec: {
14
- dispatch: {
15
- Router: Function;
16
- };
17
- meta?: {
18
- refs?: Record<string, {
19
- kind?: string;
20
- builtin?: boolean;
21
- verb?: string;
22
- }>;
18
+ export declare function makeDispatcher({ spec, ns, routes, onerror, key, onepoch }: {
19
+ spec: {
20
+ dispatch: {
21
+ Router: Function;
22
+ };
23
+ meta?: {
24
+ refs?: Record<string, {
25
+ kind?: string;
26
+ builtin?: boolean;
27
+ verb?: string;
28
+ }>;
29
+ };
23
30
  };
24
- }, ns: string, routes: Record<string, Function>, onerror?: (err: Error) => void, getDbKey?: () => Uint8Array | null, hooks?: {
25
- onEpoch?: (row: {
31
+ ns: string;
32
+ routes: Record<string, Function>;
33
+ onerror: (err: Error) => void;
34
+ key: () => Uint8Array | null;
35
+ onepoch: (row: {
26
36
  epoch: number;
37
+ stamp: number;
27
38
  wrapped: Uint8Array;
28
- createdAt: number;
39
+ commit: Uint8Array;
29
40
  }) => Promise<void>;
30
41
  }): {
31
42
  dispatcher: object;
@@ -34,7 +45,3 @@ export function makeDispatcher(spec: {
34
45
  key: Buffer;
35
46
  }>, view: object, host: object) => Promise<void>;
36
47
  };
37
- export const BUILTINS: {
38
- name: string;
39
- verb: string;
40
- }[];
@@ -1,3 +1,6 @@
1
+ import Autobee from 'autobee';
2
+ import c from 'compact-encoding';
3
+ declare const WriterEncryption: any;
1
4
  /**
2
5
  * Encryption key for a rotation epoch's blob cores. New files land in a core
3
6
  * keyed by the epoch entropy, so file confidentiality rotates with the room:
@@ -6,14 +9,14 @@
6
9
  * @param {Uint8Array} entropy
7
10
  * @returns {Uint8Array}
8
11
  */
9
- export function blobEpochKey(entropy: Uint8Array): Uint8Array;
12
+ export declare function blobEpochKey(entropy: Uint8Array): Uint8Array;
10
13
  /** Prime a keyring from a local core's persisted epoch stash. */
11
- export function loadEpochs(keyring: any, local: any): Promise<void>;
14
+ export declare function loadEpochs(keyring: any, local: any): Promise<void>;
12
15
  /**
13
16
  * Wire codec for a rotation announcement's envelope list — one sealed box
14
17
  * per remaining member, addressed by member id.
15
18
  */
16
- export const wraps: c.Encoder<any[], {
19
+ export declare const wraps: c.Encoder<any[], {
17
20
  id: string;
18
21
  box: Uint8Array<ArrayBufferLike>;
19
22
  }[]>;
@@ -22,7 +25,7 @@ export const wraps: c.Encoder<any[], {
22
25
  * `epoch` is the apply-order sequence; `stamp` is the content-addressed
23
26
  * uint32 written into block headers.
24
27
  */
25
- export const epochEntries: c.Encoder<any[], {
28
+ export declare const epochEntries: c.Encoder<any[], {
26
29
  epoch: number;
27
30
  stamp: number;
28
31
  entropy: Uint8Array<ArrayBufferLike>;
@@ -37,7 +40,7 @@ export const epochEntries: c.Encoder<any[], {
37
40
  * by linearization, a block's header always identifies its true key —
38
41
  * concurrent rotations cannot make blocks undecryptable.
39
42
  */
40
- export class Keyring {
43
+ export declare class Keyring {
41
44
  /** @type {Map<number, Uint8Array>} stamp → entropy */
42
45
  entropies: Map<number, Uint8Array>;
43
46
  /** @type {Map<number, number>} stamp → apply-order sequence */
@@ -48,6 +51,7 @@ export class Keyring {
48
51
  seq: number;
49
52
  /** bumped on every add/remove — cheap change detection for retries */
50
53
  version: number;
54
+ constructor();
51
55
  /** @returns {Array<{ epoch: number, stamp: number, entropy: Uint8Array }>} ascending by seq */
52
56
  all(): Array<{
53
57
  epoch: number;
@@ -77,23 +81,23 @@ export class Keyring {
77
81
  * the epoch behavior lives on the (patched) base prototype above. Named for
78
82
  * call sites and tests.
79
83
  */
80
- export class EpochEncryption {
84
+ export declare class EpochEncryption extends WriterEncryption {
81
85
  }
82
86
  /**
83
87
  * Autobee with a rotation keyring. Every provider autobee constructs
84
88
  * (view/system factory, foreign cores, ActiveWriters) picks the epochs up
85
89
  * through the patched base class and this `keyring` property.
86
90
  */
87
- export class EpochAutobee {
88
- constructor(store: any, key: any, handlers?: {});
91
+ export declare class EpochAutobee extends Autobee {
89
92
  keyring: any;
90
93
  _epochStalled: Set<any>;
91
- _epochRetry: any;
94
+ _epochRetry: number;
92
95
  _epochRetryDelay: number;
93
96
  _epochRetrySeen: number;
97
+ constructor(store: any, key: any, handlers?: {});
94
98
  _bumpPendingWriters(...args: any[]): Promise<any>;
95
99
  _applyWakeupHints(): Promise<any>;
96
100
  _scheduleEpochRetry(): void;
97
101
  _close(): Promise<any>;
98
102
  }
99
- import c from 'compact-encoding';
103
+ export {};
@@ -5,7 +5,7 @@
5
5
  * @param {Uint8Array} body
6
6
  * @returns {Uint8Array}
7
7
  */
8
- export function wrap(version: number, body: Uint8Array): Uint8Array;
8
+ export declare function wrap(version: number, body: Uint8Array): Uint8Array;
9
9
  /**
10
10
  * Split an op into contract version and payload. Ops written before the
11
11
  * envelope existed carry no sentinel and read as version 0.
@@ -13,7 +13,7 @@ export function wrap(version: number, body: Uint8Array): Uint8Array;
13
13
  * @param {Uint8Array} buf
14
14
  * @returns {{ version: number, body: Uint8Array }}
15
15
  */
16
- export function unwrap(buf: Uint8Array): {
16
+ export declare function unwrap(buf: Uint8Array): {
17
17
  version: number;
18
18
  body: Uint8Array;
19
19
  };