@cero-base/core 2.3.3 → 2.4.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.
@@ -7,7 +7,7 @@ import hid from 'hypercore-id-encoding'
7
7
  import Autobee from 'autobee'
8
8
 
9
9
  import { Invite } from './invite.js'
10
- import { Request, Response, STATUS_ACCEPTED, STATUS_DENIED } from './request.js'
10
+ import { Response, STATUS_ACCEPTED, STATUS_DENIED } from './response.js'
11
11
  import { Mailbox } from '../mailbox/index.js'
12
12
  import { Post } from '../mailbox/post.js'
13
13
  import { wrap } from '../database/envelope.js'
@@ -33,12 +33,16 @@ const MAX_DELAY = 2 ** 31 - 1
33
33
  * @property {boolean} [confirm] Its joins wait for a member to accept them, as requests.
34
34
  * @property {Uint8Array | null} [data] The app's payload in the invite, readable before joining: `Invite.parse(invite).data`.
35
35
  *
36
+ * @typedef {object} AcceptOpts
37
+ * @property {string} [role] Role granted: the invite's by default, at most the invite's.
38
+ *
36
39
  * @typedef {object} JoinOpts
37
40
  * @property {import('../identity/index.js').Identity} identity Who joins: the member they become, and who signs the join.
38
41
  * @property {{ dispatch: { encode: Function }, meta?: { ns?: string, version?: number } }} spec The database's spec: the join is one of its ops.
39
42
  * @property {KeyPair} [writer] Their writer keypair in the database, a fresh one by default. The join is its first block and its secret key owns the reply address: pass the same one to resume a join after a restart.
40
43
  * @property {number} [timeout] Deadline for the reply, in ms; `0` waits until the invite expires, or for good. Defaults to 30000.
41
44
  * @property {AbortSignal} [signal] Stops the join, rejecting it with `CLOSED`, as closing the mailbox does.
45
+ * @property {(answer: JoinResult | Error) => Promise<unknown>} [keep] Saves the answer, the keys or the `DENIED`, before the join settles: the reply stays in the mailbox until it resolves, so a join resumed with the same writer after a crash gets it again.
42
46
  *
43
47
  * @typedef {object} JoinResult
44
48
  * @property {Uint8Array} key
@@ -54,7 +58,7 @@ const MAX_DELAY = 2 ** 31 - 1
54
58
  * that may invite offers them while online, and the first one read settles it for all. A join
55
59
  * turned away with an invite the database knows, spent, revoked or older than the joiner's
56
60
  * removal, is answered the same way with `DENIED` and the reason. A `confirm` invite's joins wait
57
- * as requests until a member accepts or denies them; `'request'` fires for each new one.
61
+ * as rows of `requests` until a member accepts or denies one by its id.
58
62
  * `Pairing.join` is the other side: write the join, wait for the reply.
59
63
  */
60
64
  export class Pairing extends ReadyResource {
@@ -66,13 +70,9 @@ export class Pairing extends ReadyResource {
66
70
 
67
71
  this.mailbox = mailbox
68
72
  this.db = db
69
- /** @type {Set<Request>} requests not answered yet: whoever attaches after one fired goes through these first */
70
- this.pending = new Set()
71
73
  /** Whether this device answers the database's joins: it may invite, and invites or joiners owed an answer exist. */
72
74
  this.serving = false
73
75
 
74
- /** @private */
75
- this._requests = new Map() // writer id → Request
76
76
  /** @private */
77
77
  this._replies = new Map() // writer id → the Post offering its keys
78
78
  /** @private */
@@ -157,20 +157,49 @@ export class Pairing extends ReadyResource {
157
157
  }
158
158
 
159
159
  /**
160
- * A join waiting on a `confirm` invite, by its id in the `requests` collection.
160
+ * Admit a join waiting on a `confirm` invite, by its id in `requests`. Every device of an
161
+ * inviter then replies with the keys.
162
+ *
163
+ * @param {string} id
164
+ * @param {AcceptOpts} [opts]
165
+ * @returns {Promise<void>}
166
+ */
167
+ async accept(id, { role } = {}) {
168
+ const invite = await this._waiting(id)
169
+ // apply has no clock: it would admit past the expiry
170
+ if (expired(invite)) throw CeroError.EXPIRED()
171
+ role = role || invite.role
172
+ if (!isRank(role)) {
173
+ throw CeroError.INVALID(`role '${role}' is not a rank (owner, admin, member, reader)`)
174
+ }
175
+ if (!grants(invite.role, role)) {
176
+ throw CeroError.INVALID(`role '${role}' exceeds the invite role '${invite.role}'`)
177
+ }
178
+ await this.db.call('accept', { id, role })
179
+ }
180
+
181
+ /**
182
+ * Refuse a join waiting on a `confirm` invite, by its id in `requests`, with an optional reason.
161
183
  *
162
184
  * @param {string} id
163
- * @returns {Promise<Request>}
185
+ * @param {string} [reason]
186
+ * @returns {Promise<void>}
164
187
  */
165
- async request(id) {
166
- // the row can be read before this device has caught up with it
167
- if (!this._requests.has(id)) await this._sync()
168
- const request = this._requests.get(id)
169
- if (!request) throw CeroError.UNKNOWN('request', id)
170
- return request
188
+ async deny(id, reason = '') {
189
+ await this._waiting(id)
190
+ await this.db.call('deny', { id, reason })
171
191
  }
172
192
 
173
- // follow the log: the invites that ran out, the joins waiting for a member, the answers owed
193
+ // the invite of a join nobody has answered yet
194
+ /** @private */
195
+ async _waiting(id) {
196
+ const { data: row } = await this.db.get('requests', id)
197
+ const invite = row && !row.admitted && (await this.db.get('invites', row.invite)).data
198
+ if (!invite) throw CeroError.UNKNOWN('request', id)
199
+ return invite
200
+ }
201
+
202
+ // follow the log: the invites that ran out, the answers owed
174
203
  /** @private */
175
204
  async _sync() {
176
205
  const me = await this._me()
@@ -191,7 +220,6 @@ export class Pairing extends ReadyResource {
191
220
  const inviter = can(role, INVITE)
192
221
  const owed = inviter ? requests.filter((row) => row.admitted) : []
193
222
  const refused = inviter ? refusals : []
194
- this._pending(inviter ? requests.filter((row) => !row.admitted) : [], invites)
195
223
  await this._answer(owed, refused, role)
196
224
  const live = invites.some((row) => !expired(row))
197
225
  this.serving = inviter && (live || owed.length > 0 || refused.length > 0)
@@ -211,25 +239,6 @@ export class Pairing extends ReadyResource {
211
239
  )
212
240
  }
213
241
 
214
- /** @private */
215
- _pending(rows, invites) {
216
- const live = new Set(rows.map((row) => row.id))
217
- // settled elsewhere: accepted or denied by another member, or its invite revoked
218
- for (const [id, request] of this._requests) {
219
- if (live.has(id)) continue
220
- this._requests.delete(id)
221
- this.pending.delete(request)
222
- }
223
- for (const row of rows) {
224
- const invite = invites.find((i) => i.id === row.invite)
225
- if (!invite || this._requests.has(row.id)) continue
226
- const request = new Request({ pairing: this, invite, row })
227
- this._requests.set(row.id, request)
228
- this.pending.add(request)
229
- this.emit('request', request)
230
- }
231
- }
232
-
233
242
  // an admitted joiner is offered its keys, and a refused one the reason, by every inviter device
234
243
  // online, until one is read. Past the invite's expiry the joiner has given up: a member who can
235
244
  // remove drops an admitted one instead, and a refused one is forgotten
@@ -330,7 +339,14 @@ export class Pairing extends ReadyResource {
330
339
  static async join(
331
340
  mailbox,
332
341
  invite,
333
- { identity, spec, writer = crypto.keyPair(), timeout = 30000, signal = null } = {}
342
+ {
343
+ identity,
344
+ spec,
345
+ writer = crypto.keyPair(),
346
+ timeout = 30000,
347
+ signal = null,
348
+ keep = async () => {}
349
+ } = {}
334
350
  ) {
335
351
  if (!mailbox) throw CeroError.REQUIRED('mailbox')
336
352
  if (typeof identity?.sign !== 'function') throw CeroError.REQUIRED('identity')
@@ -348,12 +364,17 @@ export class Pairing extends ReadyResource {
348
364
  resolve = res
349
365
  fail = rej
350
366
  })
351
- const onreply = (message) => {
367
+ const settle = async (answer, done) => {
368
+ await keep(answer)
369
+ done(answer)
370
+ }
371
+ const onreply = async (message) => {
352
372
  const response = decode(Response, message)
353
- if (response?.status === STATUS_DENIED) fail(CeroError.DENIED(response.reason || null))
354
- else if (response?.key && b4a.equals(response.key, parsed.key)) {
373
+ if (response?.status === STATUS_DENIED) {
374
+ await settle(CeroError.DENIED(response.reason || null), fail)
375
+ } else if (response?.key && b4a.equals(response.key, parsed.key)) {
355
376
  const { key, encryptionKey, epochs } = response
356
- resolve({ key, encryptionKey, epochs: epochs || [], writer })
377
+ await settle({ key, encryptionKey, epochs: epochs || [], writer }, resolve)
357
378
  }
358
379
  }
359
380
 
@@ -0,0 +1,8 @@
1
+ import { getEncoding } from '../lib/spec/index.js'
2
+
3
+ export const STATUS_ACCEPTED = 0
4
+ export const STATUS_DENIED = 1
5
+
6
+ // an accept and a deny both ride this response
7
+ /** @type {import('compact-encoding').Encoder<{ status: number, reason?: string, key?: Uint8Array | null, encryptionKey?: Uint8Array | null, epochs?: Array<{ epoch: number, stamp: number, entropy: Uint8Array }> | null }>} */
8
+ export const Response = getEncoding('@cero/confirm')
@@ -127,6 +127,7 @@ export class Storage extends ReadyResource {
127
127
  async put(name, row) {
128
128
  this._guard()
129
129
  const ref = this._ref(name)
130
+ if (ref.kind === SINGLE) throw CeroError.INVALID(`${name} is a single: write it with set`)
130
131
  checkFields(name, this.refs[name], row)
131
132
  const was = row.id == null ? null : await this._read(ref, row.id)
132
133
  const stored = stamp({ ...row, id: row.id ?? genId() }, was?.createdAt)
@@ -149,8 +150,10 @@ export class Storage extends ReadyResource {
149
150
  checkFields(name, this.refs[name], row)
150
151
  const existing = await this._read(ref, row?.id)
151
152
  if (!upsert && !existing) return null
153
+ // a single is one record with no fields of Cero's
154
+ const merged = { ...existing, ...row }
152
155
  /** @type {Row} */
153
- const stored = stamp({ ...existing, ...row }, existing?.createdAt)
156
+ const stored = ref.kind === SINGLE ? merged : stamp(merged, existing?.createdAt)
154
157
  checkRequired(name, this.refs[name], stored)
155
158
  if (ref.kind === COLLECTION && !stored.id) stored.id = genId()
156
159
  await this._write(ref, stored)
@@ -6,11 +6,7 @@ export type BlobsOpts = {
6
6
  */
7
7
  store: object;
8
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.
9
+ * Optional network on this store: the core rides its connections and mirrors.
14
10
  */
15
11
  network?: import('../network/index.js').Network;
16
12
  /**
@@ -18,9 +14,9 @@ export type BlobsOpts = {
18
14
  */
19
15
  key?: Uint8Array;
20
16
  /**
21
- * Explicit encryption key, overrides `identity.encryptionKey`.
17
+ * Encrypts the core.
22
18
  */
23
- encryptionKey?: Uint8Array;
19
+ encryptionKey: Uint8Array;
24
20
  /**
25
21
  * Core name in the store when no `key` is given; `blobs` by default.
26
22
  */
@@ -30,10 +26,9 @@ export type RawBlobId = import('./codec.js').RawBlobId;
30
26
  /**
31
27
  * @typedef {object} BlobsOpts
32
28
  * @property {object} store Corestore (or compatible) used to host the blob core.
33
- * @property {import('../identity/index.js').Identity} [identity] Identity supplying the default encryption key.
34
- * @property {import('../network/index.js').Network} [network] Optional network used to announce + replicate the core.
29
+ * @property {import('../network/index.js').Network} [network] Optional network on this store: the core rides its connections and mirrors.
35
30
  * @property {Uint8Array} [key] Pre-existing blob core key — joins an existing blob feed.
36
- * @property {Uint8Array} [encryptionKey] Explicit encryption key, overrides `identity.encryptionKey`.
31
+ * @property {Uint8Array} encryptionKey Encrypts the core.
37
32
  * @property {string} [name] Core name in the store when no `key` is given; `blobs` by default.
38
33
  *
39
34
  * @typedef {import('./codec.js').RawBlobId} RawBlobId
@@ -41,7 +36,6 @@ export type RawBlobId = import('./codec.js').RawBlobId;
41
36
  /** Thin wrapper over a single Hyperblobs core; deals only in raw blobIds. */
42
37
  export declare class Blobs extends ReadyResource {
43
38
  store: object;
44
- identity: import("../index.js").Identity;
45
39
  network: import("../index.js").Network;
46
40
  encryptionKey: Uint8Array<ArrayBufferLike>;
47
41
  name: string;
@@ -51,10 +45,8 @@ export declare class Blobs extends ReadyResource {
51
45
  core: import('hypercore') | null;
52
46
  /** @type {import('hyperblobs') | null} */
53
47
  hyperblobs: import('hyperblobs') | null;
54
- /** @private */
55
- _discovery;
56
48
  /** @param {BlobsOpts} [opts] */
57
- constructor({ store, identity, network, key, encryptionKey, name }?: BlobsOpts);
49
+ constructor({ store, network, key, encryptionKey, name }?: BlobsOpts);
58
50
  /**
59
51
  * Canonical z32 id of the underlying core (null until ready).
60
52
  *
@@ -61,8 +61,10 @@ export declare class Keyring {
61
61
  current: number;
62
62
  /** highest adopted apply-order sequence (0 = base era) */
63
63
  seq: number;
64
- /** bumped on every add/remove — cheap change detection for retries */
64
+ /** bumped on every add/remove — cheap change detection */
65
65
  version: number;
66
+ /** @type {(() => void) | null} called when an epoch is learned or dropped */
67
+ onchange: (() => void) | null;
66
68
  constructor();
67
69
  /** @returns {Array<{ epoch: number, stamp: number, entropy: Uint8Array }>} ascending by seq */
68
70
  all(): Array<{
@@ -99,11 +101,9 @@ export declare class EpochAutobee extends Autobee {
99
101
  /** @private */
100
102
  _epochStalled;
101
103
  /** @private */
102
- _epochRetry;
104
+ _epochParked;
103
105
  /** @private */
104
- _epochRetryDelay;
105
- /** @private */
106
- _epochRetrySeen;
106
+ _epochWake;
107
107
  /**
108
108
  * @param {import('corestore')} store
109
109
  * @param {Uint8Array | null} key
@@ -119,11 +119,9 @@ export declare class EpochAutobee extends Autobee {
119
119
  key?: Uint8Array;
120
120
  }): Promise<Uint8Array>;
121
121
  /** @private */
122
- private _close;
123
- /** @private */
124
122
  private _bumpPendingWriters;
125
123
  /** @private */
126
124
  private _applyWakeupHints;
127
125
  /** @private */
128
- private _scheduleEpochRetry;
126
+ private _scheduleEpochWake;
129
127
  }
@@ -7,13 +7,12 @@
7
7
  */
8
8
  export declare function wrap(version: number, body: Uint8Array): Uint8Array;
9
9
  /**
10
- * Split an op into contract version and payload. Ops written before the
11
- * envelope existed carry no sentinel and read as version 0.
10
+ * Split an op into contract version and payload, or `null` for bytes with no envelope or a cut one.
12
11
  *
13
12
  * @param {Uint8Array} buf
14
- * @returns {{ version: number, body: Uint8Array }}
13
+ * @returns {{ version: number, body: Uint8Array } | null}
15
14
  */
16
15
  export declare function unwrap(buf: Uint8Array): {
17
16
  version: number;
18
17
  body: Uint8Array;
19
- };
18
+ } | null;
@@ -12,7 +12,7 @@ export type DatabaseOpts = {
12
12
  */
13
13
  identity: import('../identity/index.js').Identity;
14
14
  /**
15
- * Optional swarm; required for multi-writer replication.
15
+ * Optional swarm; required for multi-writer replication; `store` is its store or a session of it.
16
16
  */
17
17
  network?: import('../network/index.js').Network;
18
18
  /**
@@ -42,9 +42,9 @@ export type DatabaseOpts = {
42
42
  */
43
43
  namespace?: string;
44
44
  /**
45
- * Optional encryption key; falls back to identity's key.
45
+ * Encrypts it; a join hands it out, so never the identity's on a database you pair.
46
46
  */
47
- encryptionKey?: Uint8Array | null;
47
+ encryptionKey: Uint8Array;
48
48
  /**
49
49
  * Rotation epochs to prime the keyring with (delivered at join).
50
50
  */
@@ -147,10 +147,10 @@ export type HookFn = (ctx: HookContext) => unknown;
147
147
  * @typedef {object} DatabaseOpts
148
148
  * @property {import('corestore')} store Corestore (or compatible) used to materialize the autobee.
149
149
  * @property {import('../identity/index.js').Identity} identity Long-lived member identity used to sign writer changes.
150
- * @property {import('../network/index.js').Network} [network] Optional swarm; required for multi-writer replication.
150
+ * @property {import('../network/index.js').Network} [network] Optional swarm; required for multi-writer replication; `store` is its store or a session of it.
151
151
  * @property {{ database: object, dispatch: { Router: new () => object, encode: (name: string, value: unknown) => Uint8Array, decode: (buf: Uint8Array) => { name: string, value: unknown } }, meta?: { ns?: string, version?: number, refs?: Record<string, { kind?: string, verb?: string }> } }} spec Generated hyperdb + hyperdispatch spec.
152
152
  * @property {string} [namespace] Corestore namespace; defaults to `cero`.
153
- * @property {Uint8Array | null} [encryptionKey] Optional encryption key; falls back to identity's key.
153
+ * @property {Uint8Array} encryptionKey Encrypts it; a join hands it out, so never the identity's on a database you pair.
154
154
  * @property {Array<{ epoch: number, entropy: Uint8Array }> | null} [epochs] Rotation epochs to prime the keyring with (delivered at join).
155
155
  * @property {Uint8Array | null} [key] Existing autobee key to reopen.
156
156
  * @property {boolean} [pinned] Always search and announce, outside the network's presence budget. The root.
@@ -417,12 +417,16 @@ export declare class Database extends ReadyResource {
417
417
  writer: import('../identity/index.js').KeyPair;
418
418
  }>;
419
419
  /**
420
- * Claim writership on an existing room by signing our writer key with the member identity;
421
- * the claim rides in the device core as an optimistic node.
420
+ * Seat this device's writer where its identity is a member: wait for the member row, append
421
+ * the add-writer the identity signs from this device's own core, and resolve once it writes.
422
+ * A member whose role cannot write takes no seat.
422
423
  *
424
+ * @param {{ timeout?: number }} [opts]
423
425
  * @returns {Promise<void>}
424
426
  */
425
- claim(): Promise<void>;
427
+ claim({ timeout }?: {
428
+ timeout?: number;
429
+ }): Promise<void>;
426
430
  /**
427
431
  * Resolve once the bee becomes writable, or reject after `timeout` ms.
428
432
  *
@@ -511,9 +515,7 @@ export declare class Database extends ReadyResource {
511
515
  /** @private */
512
516
  private _total;
513
517
  /** @private */
514
- private _optimistic;
515
- /** @private */
516
- private _backfilled;
518
+ private _member;
517
519
  /** @private */
518
520
  private _admission;
519
521
  /** @private */
@@ -10,9 +10,7 @@ export declare const OWNER = "owner";
10
10
  export declare const ADMIN = "admin";
11
11
  export declare const MEMBER = "member";
12
12
  export declare const READER = "reader";
13
- export declare const READ = "read";
14
13
  export declare const WRITE = "write";
15
- export declare const DELETE = "delete";
16
14
  export declare const INVITE = "invite";
17
15
  export declare const REMOVE = "remove";
18
16
  export declare const ASSIGN = "assign";
@@ -20,7 +18,7 @@ export declare const ROLE_PERMS: {
20
18
  owner: string[];
21
19
  admin: string[];
22
20
  member: string[];
23
- reader: string[];
21
+ reader: any[];
24
22
  };
25
23
  export declare const RANK: {
26
24
  owner: number;
@@ -1,8 +1,6 @@
1
1
  export { WRITE, INVITE, ASSIGN, REMOVE } from './constants.js';
2
2
  /** @type {(dbKey: Uint8Array, writer: Uint8Array, appender: Uint8Array) => Uint8Array} */
3
3
  export declare function admission(dbKey: Uint8Array<ArrayBufferLike>, writer: Uint8Array<ArrayBufferLike>, appender: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
4
- /** @type {(dbKey: Uint8Array, writer: Uint8Array) => Uint8Array} */
5
- export declare function ownership(dbKey: Uint8Array<ArrayBufferLike>, writer: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
6
4
  /** @type {(dbKey: Uint8Array, invite: Uint8Array, writer: Uint8Array, reply: Uint8Array) => Uint8Array} */
7
5
  export declare function joining(dbKey: Uint8Array<ArrayBufferLike>, invite: Uint8Array<ArrayBufferLike>, writer: Uint8Array<ArrayBufferLike>, reply: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
8
6
  /**
@@ -65,7 +65,7 @@ export declare class Mailbox extends ReadyResource {
65
65
  /** @private */
66
66
  _resources;
67
67
  /**
68
- * @param {import('../network/index.js').Network} network Needs a store: messages travel as cores in it.
68
+ * @param {import('../network/index.js').Network} network Messages travel as cores in its store.
69
69
  * @param {MailboxOpts} [opts]
70
70
  */
71
71
  constructor(network: import('../network/index.js').Network, { inbox, outbox, onerror }?: MailboxOpts);
@@ -32,11 +32,11 @@ export type NetworkOpts = {
32
32
  */
33
33
  channel?: string;
34
34
  /**
35
- * Corestore; required for mirrors (blind peers replicate its cores).
35
+ * Corestore; every connection replicates it, so every core it holds rides every peer.
36
36
  */
37
- store?: import('corestore');
37
+ store: import('corestore');
38
38
  /**
39
- * Blind-peer public keys; each attached room/blob core is mirrored through them for offline sync.
39
+ * Blind-peer public keys; each attached database/blob core is mirrored through them for offline sync.
40
40
  */
41
41
  mirrors?: Array<string | Uint8Array>;
42
42
  /**
@@ -52,9 +52,6 @@ export type NetworkOpts = {
52
52
  idle?: number;
53
53
  };
54
54
  };
55
- export type Replicable = {
56
- replicate: (stream: import('@hyperswarm/secret-stream')) => unknown;
57
- };
58
55
  /**
59
56
  * @typedef {object} NetworkOpts
60
57
  * @property {import('../identity/index.js').Identity} [identity] Long-lived keypair used as the swarm identity.
@@ -63,16 +60,14 @@ export type Replicable = {
63
60
  * @property {Uint8Array[]} [relayThrough] Relay public keys to tunnel through.
64
61
  * @property {number[]} [backoffs] Reconnect backoff tiers in ms; the default escalates to ~10min, far too slow for local nets.
65
62
  * @property {string} [channel] Optional network-isolation label; only same-channel peers meet.
66
- * @property {import('corestore')} [store] Corestore; required for mirrors (blind peers replicate its cores).
67
- * @property {Array<string | Uint8Array>} [mirrors] Blind-peer public keys; each attached room/blob core is mirrored through them for offline sync.
63
+ * @property {import('corestore')} store Corestore; every connection replicates it, so every core it holds rides every peer.
64
+ * @property {Array<string | Uint8Array>} [mirrors] Blind-peer public keys; each attached database/blob core is mirrored through them for offline sync.
68
65
  * @property {(err: Error) => void} [onerror] Background-task error handler.
69
66
  * @property {{ active?: number, announced?: number, idle?: number }} [presence] Swarm budget for attached databases: how many search, how many only announce, and the idle ms before the rest leave.
70
- *
71
- * @typedef {{ replicate: (stream: import('@hyperswarm/secret-stream')) => unknown }} Replicable
72
67
  */
73
68
  /**
74
- * Hyperswarm peer-discovery + replication multiplexer. Wraps a swarm and a
75
- * shared wakeup channel, replicating any attached resource onto every peer.
69
+ * Hyperswarm peer discovery plus a shared wakeup channel. Every connection, swarm or injected,
70
+ * replicates the store.
76
71
  */
77
72
  export declare class Network extends ReadyResource {
78
73
  identity: import("../index.js").Identity;
@@ -84,8 +79,8 @@ export declare class Network extends ReadyResource {
84
79
  relayThrough: Uint8Array<ArrayBufferLike>[];
85
80
  backoffs: number[];
86
81
  channel: string;
87
- /** @type {import('corestore') | null} */
88
- store: import('corestore') | null;
82
+ /** @type {import('corestore')} */
83
+ store: import('corestore');
89
84
  /** @type {Uint8Array[]} */
90
85
  mirrors: Uint8Array[];
91
86
  /** @private */
@@ -93,13 +88,6 @@ export declare class Network extends ReadyResource {
93
88
  /** @type {import('protomux-wakeup')} */
94
89
  wakeup: import('protomux-wakeup');
95
90
  presence: Presence;
96
- info: object;
97
- /** @private */
98
- _peerInfo;
99
- /** @private */
100
- _infoSenders;
101
- /** @private */
102
- _replicateables;
103
91
  /** @private */
104
92
  _discoveries;
105
93
  /** @private */
@@ -112,7 +100,7 @@ export declare class Network extends ReadyResource {
112
100
  _relookup;
113
101
  /** @private */
114
102
  _onerror;
115
- /** @param {NetworkOpts} [opts] */
103
+ /** @param {NetworkOpts} opts */
116
104
  constructor({ identity, bootstrap, firewall, relayThrough, backoffs, channel, store, mirrors, presence, onerror }?: NetworkOpts);
117
105
  /** @returns {import('hyperswarm') | null} The underlying hyperswarm, or null before ready / after close. */
118
106
  get swarm(): import('hyperswarm') | null;
@@ -137,6 +125,8 @@ export declare class Network extends ReadyResource {
137
125
  inject(stream: import('streamx').Duplex, { isInitiator }?: {
138
126
  isInitiator?: boolean;
139
127
  }): import('@hyperswarm/secret-stream');
128
+ /** @private */
129
+ private _add;
140
130
  /**
141
131
  * The blind-peering client, built on first use: a mailbox post names mirrors this network
142
132
  * may not have been given.
@@ -144,19 +134,6 @@ export declare class Network extends ReadyResource {
144
134
  * @returns {import('blind-peering')}
145
135
  */
146
136
  peering(): import('blind-peering');
147
- /**
148
- * Declare this peer's self-reported info ({ name, ... }) to the peers of injected streams.
149
- *
150
- * @param {object | null} info
151
- */
152
- setInfo(info: object | null): void;
153
- /**
154
- * Info a connected peer declared about itself, or null.
155
- *
156
- * @param {Uint8Array | string} key Peer public key (bytes or hex).
157
- * @returns {object | null}
158
- */
159
- getInfo(key: Uint8Array | string): object | null;
160
137
  /**
161
138
  * Wait for pending DHT announces and lookups to settle, bounded by timeout.
162
139
  *
@@ -189,35 +166,24 @@ export declare class Network extends ReadyResource {
189
166
  mode?: 'active' | 'passive';
190
167
  }): Discovery;
191
168
  /**
192
- * Register a replicable resource (hypercore, autobee, hyperdb).
193
- * It is replicated on every current and future swarm connection.
169
+ * Whether `store` replicates on this network's connections: the network's store or a session of it.
194
170
  *
195
- * @param {Replicable} core
196
- * @returns {void}
197
- */
198
- attach(core: Replicable): void;
199
- /** @private */
200
- private _mirror;
201
- /**
202
- * Unregister a previously attached resource. New connections will no
203
- * longer replicate it (existing replication streams continue).
204
- *
205
- * @param {Replicable} core
206
- * @returns {void}
171
+ * @param {import('corestore')} store
172
+ * @returns {boolean}
207
173
  */
208
- detach(core: Replicable): void;
174
+ replicates(store: import('corestore')): boolean;
209
175
  /**
210
- * Replicate a one-off resource onto every current swarm connection
211
- * without registering it as a long-lived attachment.
176
+ * Keep a core or an autobee on the mirrors, so it stays reachable while its writers are
177
+ * offline. It rides the connections already, from the store; a mirror drops it once it closes.
212
178
  *
213
- * @param {Replicable} target
179
+ * @param {import('hypercore') | import('autobee')} core
214
180
  * @returns {void}
215
181
  */
216
- replicate(target: Replicable): void;
182
+ attach(core: import('hypercore') | import('autobee')): void;
183
+ /** @private */
184
+ private _mirror;
217
185
  /** @private */
218
186
  private _lose;
219
187
  /** @private */
220
188
  private _relook;
221
- /** @private */
222
- private _attachInfo;
223
189
  }