@cero-base/core 2.4.1 → 2.6.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.
@@ -35,6 +35,7 @@ const MAX_DELAY = 2 ** 31 - 1
35
35
  *
36
36
  * @typedef {object} AcceptOpts
37
37
  * @property {string} [role] Role granted: the invite's by default, at most the invite's.
38
+ * @property {Uint8Array | null} [proof] The joiner's chain to your identity, from `identity.link`: it joins as a device of yours, not as a member.
38
39
  *
39
40
  * @typedef {object} JoinOpts
40
41
  * @property {import('../identity/index.js').Identity} identity Who joins: the member they become, and who signs the join.
@@ -49,6 +50,7 @@ const MAX_DELAY = 2 ** 31 - 1
49
50
  * @property {Uint8Array | null} encryptionKey
50
51
  * @property {Array<{ epoch: number, stamp: number, entropy: Uint8Array }>} epochs
51
52
  * @property {KeyPair} writer The writer the join admitted: open the database with it.
53
+ * @property {Uint8Array | null} proof A device's chain to the identity it was linked under, null for a member.
52
54
  */
53
55
 
54
56
  /**
@@ -164,7 +166,7 @@ export class Pairing extends ReadyResource {
164
166
  * @param {AcceptOpts} [opts]
165
167
  * @returns {Promise<void>}
166
168
  */
167
- async accept(id, { role } = {}) {
169
+ async accept(id, { role, proof = null } = {}) {
168
170
  const invite = await this._waiting(id)
169
171
  // apply has no clock: it would admit past the expiry
170
172
  if (expired(invite)) throw CeroError.EXPIRED()
@@ -175,7 +177,7 @@ export class Pairing extends ReadyResource {
175
177
  if (!grants(invite.role, role)) {
176
178
  throw CeroError.INVALID(`role '${role}' exceeds the invite role '${invite.role}'`)
177
179
  }
178
- await this.db.call('accept', { id, role })
180
+ await this.db.call('accept', { id, role, proof })
179
181
  }
180
182
 
181
183
  /**
@@ -244,12 +246,18 @@ export class Pairing extends ReadyResource {
244
246
  // remove drops an admitted one instead, and a refused one is forgotten
245
247
  /** @private */
246
248
  async _answer(owed, refused, role) {
247
- const keys = () => ({
249
+ // a device linked under a member reads its chain off its row
250
+ const proofs = new Map()
251
+ for (const { id } of owed) {
252
+ proofs.set(id, (await this.db.get('devices', id)).data?.proof ?? null)
253
+ }
254
+ const keys = ({ id }) => ({
248
255
  status: STATUS_ACCEPTED,
249
256
  reason: '',
250
257
  key: this.db.key,
251
258
  encryptionKey: this.db.encryptionKey,
252
- epochs: this.db.keyring.all()
259
+ epochs: this.db.keyring.all(),
260
+ proof: proofs.get(id)
253
261
  })
254
262
  const denied = ({ reason }) => ({
255
263
  status: STATUS_DENIED,
@@ -373,8 +381,8 @@ export class Pairing extends ReadyResource {
373
381
  if (response?.status === STATUS_DENIED) {
374
382
  await settle(CeroError.DENIED(response.reason || null), fail)
375
383
  } else if (response?.key && b4a.equals(response.key, parsed.key)) {
376
- const { key, encryptionKey, epochs } = response
377
- await settle({ key, encryptionKey, epochs: epochs || [], writer }, resolve)
384
+ const { key, encryptionKey, epochs, proof = null } = response
385
+ await settle({ key, encryptionKey, epochs: epochs || [], writer, proof }, resolve)
378
386
  }
379
387
  }
380
388
 
@@ -415,7 +423,8 @@ export class Pairing extends ReadyResource {
415
423
 
416
424
  /**
417
425
  * A join's payload: sealed to the database's address, so only its members read who joins; proven
418
- * by the invite over the writer; signed by the joiner's identity for this writer and reply address.
426
+ * by the invite over the writer; signed by the joiner's device, under its chain to the identity,
427
+ * for this writer and reply address.
419
428
  *
420
429
  * @param {Invite} invite
421
430
  * @param {import('../identity/index.js').Identity} identity
@@ -427,9 +436,8 @@ export function sealJoin(invite, identity, writer, reply) {
427
436
  const join = {
428
437
  invite: invite.id,
429
438
  reply,
430
- proof: invite.prove(writer),
431
- identity: identity.publicKey,
432
- signature: identity.sign(joining(invite.key, invite.id, writer, reply)),
439
+ signature: invite.prove(writer),
440
+ proof: identity.sign(joining(invite.key, invite.id, writer, reply)),
433
441
  ts: Date.now()
434
442
  }
435
443
  return { box: crypto.encrypt(c.encode(Join, join), invite.address) }
@@ -0,0 +1,37 @@
1
+ import { decode, readNotification } from 'blind-push'
2
+ import crypto from 'hypercore-crypto'
3
+ import b4a from 'b4a'
4
+
5
+ /**
6
+ * @typedef {{ id: string, key: Uint8Array }} Handle A handle this device holds: its id and its database key.
7
+ * @typedef {Handle & { length: number, newer: boolean, ref: string | null }} Hit The handle a push is about, the length it proves, whether this device is behind it, and the ref the write was on.
8
+ */
9
+
10
+ /**
11
+ * Verify a push payload against this device's storage: the one the gateway sent, decoded from the
12
+ * platform's message. Null when it is about no handle given, is forged, or does not decode.
13
+ *
14
+ * @param {import('hypercore-storage')} storage The corestore's storage; may be opened read-only.
15
+ * @param {Uint8Array} payload
16
+ * @param {Handle[]} handles
17
+ * @returns {Promise<Hit | null>}
18
+ */
19
+ export async function verify(storage, payload, handles) {
20
+ let push
21
+ try {
22
+ push = decode(payload)
23
+ } catch {
24
+ return null
25
+ }
26
+ const handle = handles.find((h) => b4a.equals(crypto.discoveryKey(h.key), push.discoveryKey))
27
+ if (!handle) return null
28
+ let read
29
+ try {
30
+ read = await readNotification(storage, handle.key, push.payload)
31
+ } catch {
32
+ return null
33
+ }
34
+ if (!read) return null
35
+ const ref = read.extra?.length ? b4a.toString(read.extra) : null
36
+ return { ...handle, length: read.result.length, newer: read.result.newer, ref }
37
+ }
@@ -15,25 +15,27 @@ export declare function blobEpochKey(entropy: Uint8Array): Uint8Array;
15
15
  */
16
16
  export declare function loadEpochs(keyring: Keyring, local: import('hypercore')): Promise<void>;
17
17
  /**
18
- * Wire codec for a rotation announcement's envelope list — one sealed box
19
- * per remaining member, addressed by member id.
18
+ * A rotation announcement's envelope list — one box per device row, sealed to its device key and
19
+ * addressed by its writer id.
20
20
  *
21
- * @param {Array<{ id: string }>} members
21
+ * @param {Array<{ id: string, key: Uint8Array }>} devices
22
22
  * @param {Uint8Array} secret
23
23
  * @returns {Array<{ id: string, box: Uint8Array }>}
24
24
  */
25
- export declare function seal(members: Array<{
25
+ export declare function seal(devices: Array<{
26
26
  id: string;
27
+ key: Uint8Array;
27
28
  }>, secret: Uint8Array): Array<{
28
29
  id: string;
29
30
  box: Uint8Array;
30
31
  }>;
31
32
  /**
32
- * @param {import('../identity/index.js').Identity} identity
33
+ * @param {import('../identity/index.js').Identity} identity Whose device key opens the box.
34
+ * @param {string} id This device's writer id in the database.
33
35
  * @param {Uint8Array} wrapped
34
36
  * @returns {Generator<Uint8Array, void, unknown>}
35
37
  */
36
- export declare function opened(identity: import('../identity/index.js').Identity, wrapped: Uint8Array): Generator<Uint8Array, void, unknown>;
38
+ export declare function opened(identity: import('../identity/index.js').Identity, id: string, wrapped: Uint8Array): Generator<Uint8Array, void, unknown>;
37
39
  /** @type {import('compact-encoding').Encoder<Array<{ id: string, box: Uint8Array }>>} */
38
40
  export declare const wraps: import('compact-encoding').Encoder<Array<{
39
41
  id: string;
@@ -60,6 +60,10 @@ export type DatabaseOpts = {
60
60
  * Always search and announce, outside the network's presence budget. The root.
61
61
  */
62
62
  pinned?: boolean;
63
+ /**
64
+ * Push a notification through the mirrors after a local write to a ref whose meta declares `push`, naming the ref, so members learn of it while their app is dead.
65
+ */
66
+ push?: boolean;
63
67
  /**
64
68
  * This device's writer keypair; a fresh random one by default. Never the identity's, never the database key.
65
69
  */
@@ -127,6 +131,10 @@ export type HookContext = {
127
131
  * The writer's role, null likewise.
128
132
  */
129
133
  role: string | null;
134
+ /**
135
+ * On removing a member or changing her rank: whether the writer's rank alone allows it. A rule answers `'grant'` to allow what rank refuses, `false` to refuse.
136
+ */
137
+ ranked?: boolean;
130
138
  get: (ref: string | {
131
139
  name: string;
132
140
  }, query?: string | Record<string, unknown>) => Promise<{
@@ -154,6 +162,7 @@ export type HookFn = (ctx: HookContext) => unknown;
154
162
  * @property {Array<{ epoch: number, entropy: Uint8Array }> | null} [epochs] Rotation epochs to prime the keyring with (delivered at join).
155
163
  * @property {Uint8Array | null} [key] Existing autobee key to reopen.
156
164
  * @property {boolean} [pinned] Always search and announce, outside the network's presence budget. The root.
165
+ * @property {boolean} [push] Push a notification through the mirrors after a local write to a ref whose meta declares `push`, naming the ref, so members learn of it while their app is dead.
157
166
  * @property {import('../identity/index.js').KeyPair} [keyPair] This device's writer keypair; a fresh random one by default. Never the identity's, never the database key.
158
167
  * @property {(err: Error) => void} [onerror] Called when a node is skipped or refused, or the bee errors.
159
168
  *
@@ -174,6 +183,7 @@ export type HookFn = (ctx: HookContext) => unknown;
174
183
  * @property {string | null} id The row id for a `del`.
175
184
  * @property {string | null} memberId The writer's member id, null for a core no member owns yet (a join, a claim, genesis).
176
185
  * @property {string | null} role The writer's role, null likewise.
186
+ * @property {boolean} [ranked] On removing a member or changing her rank: whether the writer's rank alone allows it. A rule answers `'grant'` to allow what rank refuses, `false` to refuse.
177
187
  * @property {(ref: string | { name: string }, query?: string | Record<string, unknown>) => Promise<{ data: unknown }>} get
178
188
  * @property {(ref: string | { name: string }, row: Record<string, unknown>) => Promise<void>} put
179
189
  * @property {(ref: string | { name: string }, row: Record<string, unknown>) => Promise<void>} set
@@ -231,6 +241,9 @@ export declare class Database extends ReadyResource {
231
241
  rotation: Rotation;
232
242
  key: Uint8Array<ArrayBufferLike>;
233
243
  pinned: boolean;
244
+ push: boolean;
245
+ /** @private */
246
+ _pushes;
234
247
  keyPair: import("../index.js").KeyPair;
235
248
  /** @private */
236
249
  _onerror;
@@ -247,6 +260,16 @@ export declare class Database extends ReadyResource {
247
260
  /** @private */
248
261
  _presence;
249
262
  /** @private */
263
+ _pushing;
264
+ /** @private */
265
+ _pushAgain;
266
+ /** @private */
267
+ _pushed;
268
+ /** @private */
269
+ _pushRef;
270
+ /** @private */
271
+ _onResume;
272
+ /** @private */
250
273
  _txChain;
251
274
  /** @private */
252
275
  _held;
@@ -372,6 +395,14 @@ export declare class Database extends ReadyResource {
372
395
  * @returns {Promise<void>}
373
396
  */
374
397
  write(ops: Array<[string, unknown]>): Promise<void>;
398
+ /** @returns {boolean} Whether a push notification is on its way to the mirrors. */
399
+ get pushing(): boolean;
400
+ /** @private */
401
+ private _push;
402
+ /** @private */
403
+ private _ref;
404
+ /** @private */
405
+ private _send;
375
406
  /**
376
407
  * Read a row. With no `query`: list all (collection) or fetch the one
377
408
  * record (single). With a string id: fetch that specific row.
@@ -437,12 +468,18 @@ export declare class Database extends ReadyResource {
437
468
  timeout?: number;
438
469
  }): Promise<void>;
439
470
  /**
440
- * Admit another device of this identity as a writer. Another member's device seats itself.
471
+ * Learn epochs handed over after the open, as a root carries them for a handle. One is kept
472
+ * once its announcement applied here and the secret meets the commitment it carries: hand them
473
+ * over again when an announcement applies.
441
474
  *
442
- * @param {Uint8Array} publicKey
475
+ * @param {Array<{ epoch: number, stamp: number, entropy: Uint8Array }>} epochs
443
476
  * @returns {Promise<void>}
444
477
  */
445
- addWriter(publicKey: Uint8Array): Promise<void>;
478
+ learn(epochs: Array<{
479
+ epoch: number;
480
+ stamp: number;
481
+ entropy: Uint8Array;
482
+ }>): Promise<void>;
446
483
  /**
447
484
  * Remove a peer's writer key from the indexer set.
448
485
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Epoch key rotation for a database: mint a secret, seal it to every member, announce it
2
+ * Epoch key rotation for a database: mint a secret, seal it to every device, announce it
3
3
  * through the log, and on every peer learn the secrets addressed to it.
4
4
  */
5
5
  export declare class Rotation {
@@ -48,7 +48,7 @@ export declare class Rotation {
48
48
  /** @private */
49
49
  private _rotate;
50
50
  /** @private */
51
- private _members;
51
+ private _devices;
52
52
  /** @private */
53
53
  private _announce;
54
54
  /** @private */
@@ -4,17 +4,47 @@ export type KeyPair = {
4
4
  id: string;
5
5
  };
6
6
  export type IdentityFields = {
7
+ /**
8
+ * The identity's public key.
9
+ */
7
10
  publicKey: Uint8Array;
8
- secretKey: Uint8Array;
11
+ /**
12
+ * Its root encryption key, derived from the seed.
13
+ */
9
14
  encryptionKey: Uint8Array;
10
- seed: Uint8Array;
15
+ /**
16
+ * This device's signing keypair.
17
+ */
18
+ device: KeyPair;
19
+ /**
20
+ * The device's chain of attestations back to the identity.
21
+ */
22
+ proof: Uint8Array;
23
+ /**
24
+ * The phrase's entropy: on the device that created or recovered the identity, never on a linked one.
25
+ */
26
+ seed?: Uint8Array | null;
27
+ };
28
+ export type Verified = {
29
+ identity: Uint8Array;
30
+ device: Uint8Array;
11
31
  };
12
32
  /**
13
33
  * @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array, id: string }} KeyPair
14
- * @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array, encryptionKey: Uint8Array, seed: Uint8Array }} IdentityFields
34
+ *
35
+ * @typedef {object} IdentityFields
36
+ * @property {Uint8Array} publicKey The identity's public key.
37
+ * @property {Uint8Array} encryptionKey Its root encryption key, derived from the seed.
38
+ * @property {KeyPair} device This device's signing keypair.
39
+ * @property {Uint8Array} proof The device's chain of attestations back to the identity.
40
+ * @property {Uint8Array | null} [seed] The phrase's entropy: on the device that created or recovered the identity, never on a linked one.
41
+ *
42
+ * @typedef {{ identity: Uint8Array, device: Uint8Array }} Verified
15
43
  */
16
44
  /**
17
- * Long-lived user identity derived from a BIP-39 seed phrase.
45
+ * A user identity, as one of its devices holds it. The identity's secret key signs exactly one
46
+ * thing, a device's first proof, and is never kept: everything else is signed by the device key
47
+ * and carries the proof, so a stolen device leaks only itself.
18
48
  */
19
49
  export declare class Identity {
20
50
  /**
@@ -25,8 +55,6 @@ export declare class Identity {
25
55
  id: string;
26
56
  /** @type {Uint8Array} */
27
57
  publicKey: Uint8Array;
28
- /** @type {Uint8Array} */
29
- secretKey: Uint8Array;
30
58
  /**
31
59
  * Symmetric key for encrypting per-identity payloads.
32
60
  *
@@ -39,17 +67,17 @@ export declare class Identity {
39
67
  * @type {Uint8Array}
40
68
  */
41
69
  topic: Uint8Array;
70
+ /** @type {KeyPair} */
71
+ device: KeyPair;
72
+ /** @type {Uint8Array} */
73
+ proof: Uint8Array;
74
+ /** @type {Uint8Array | null} */
75
+ seed: Uint8Array | null;
76
+ /** @param {IdentityFields} fields */
77
+ constructor({ publicKey, encryptionKey, device, proof, seed }: IdentityFields);
42
78
  /**
43
- * Original 16- or 32-byte entropy.
44
- *
45
- * @type {Uint8Array}
46
- */
47
- seed: Uint8Array;
48
- /** @param {IdentityFields} keys */
49
- constructor(keys: IdentityFields);
50
- /**
51
- * Redacted — secretKey/encryptionKey/seed must never reach JSON.stringify
52
- * or a structured logger.
79
+ * Redacted — the device secret, encryptionKey and seed must never reach JSON.stringify or a
80
+ * structured logger.
53
81
  *
54
82
  * @returns {{ id: string }}
55
83
  */
@@ -57,23 +85,36 @@ export declare class Identity {
57
85
  id: string;
58
86
  };
59
87
  /**
60
- * Detached Ed25519 signature over `message`.
88
+ * A proof over `data`: this device's signature, under its chain to the identity.
61
89
  *
62
- * @param {Uint8Array} message
90
+ * @param {Uint8Array} data
63
91
  * @returns {Uint8Array}
64
92
  */
65
- sign(message: Uint8Array): Uint8Array;
93
+ sign(data: Uint8Array): Uint8Array;
66
94
  /**
67
- * Verify a signature against this identity's public key.
95
+ * A proof for a new device: this device attests it, one link further down the chain.
68
96
  *
69
- * @param {Uint8Array} message
70
- * @param {Uint8Array} signature
71
- * @returns {boolean}
97
+ * @param {Uint8Array} publicKey
98
+ * @returns {Uint8Array}
72
99
  */
73
- verify(message: Uint8Array, signature: Uint8Array): boolean;
100
+ link(publicKey: Uint8Array): Uint8Array;
74
101
  /**
75
- * Open a sealed box addressed to this identity (any device holding the seed-derived
76
- * keypair can open it).
102
+ * A device with no identity yet: it signs as itself, its own key standing for the identity,
103
+ * until one attests it.
104
+ *
105
+ * @param {KeyPair} [device] A fresh keypair by default.
106
+ * @returns {Promise<Identity>}
107
+ */
108
+ static bare(device?: KeyPair): Promise<Identity>;
109
+ /**
110
+ * The keys a proof chains through: the identity, then each device down to the signer.
111
+ *
112
+ * @param {Uint8Array} proof
113
+ * @returns {Uint8Array[]} Empty when it is not a proof.
114
+ */
115
+ static chain(proof: Uint8Array): Uint8Array[];
116
+ /**
117
+ * Open a sealed box addressed to this device.
77
118
  *
78
119
  * @param {Uint8Array} sealed
79
120
  * @returns {Uint8Array | null}
@@ -86,15 +127,44 @@ export declare class Identity {
86
127
  */
87
128
  toPhrase(): string;
88
129
  /**
89
- * An identity from its seed, 16 or 32 bytes; a fresh one without.
130
+ * An identity from its seed, 16 or 32 bytes; a fresh one without. The identity key attests
131
+ * `device` and is dropped.
90
132
  *
91
- * @param {{ seed?: Uint8Array | null, words?: 12 | 24 }} [opts] `words` sizes a fresh one.
133
+ * @param {{ seed?: Uint8Array | null, words?: 12 | 24, device?: KeyPair }} [opts] `words` sizes a fresh seed; `device` is a fresh keypair by default.
92
134
  * @returns {Promise<Identity>}
93
135
  */
94
- static create({ seed, words }?: {
136
+ static create({ seed, words, device }?: {
95
137
  seed?: Uint8Array | null;
96
138
  words?: 12 | 24;
139
+ device?: KeyPair;
97
140
  }): Promise<Identity>;
141
+ /**
142
+ * The identity keypair a seed writes, for what only the identity itself may sign: the pointer
143
+ * core it is created with. Nothing else ever takes it.
144
+ *
145
+ * @param {Uint8Array} seed
146
+ * @returns {Promise<{ publicKey: Uint8Array, secretKey: Uint8Array }>}
147
+ */
148
+ static keyPair(seed: Uint8Array): Promise<{
149
+ publicKey: Uint8Array;
150
+ secretKey: Uint8Array;
151
+ }>;
152
+ /**
153
+ * The identity as a stored or linked device holds it. The proof must chain `device` to it.
154
+ *
155
+ * @param {IdentityFields} fields
156
+ * @returns {Identity}
157
+ */
158
+ static from({ publicKey, encryptionKey, device, proof, seed }: IdentityFields): Identity;
159
+ /**
160
+ * Who signed `data`: the identity a proof chains to and the device that signed, or null.
161
+ *
162
+ * @param {Uint8Array} proof
163
+ * @param {Uint8Array | null} [data] What the proof signs; null verifies the chain alone.
164
+ * @param {Uint8Array | null} [publicKey] The identity expected, any when omitted.
165
+ * @returns {Verified | null}
166
+ */
167
+ static verify(proof: Uint8Array, data?: Uint8Array | null, publicKey?: Uint8Array | null): Verified | null;
98
168
  /**
99
169
  * The seed a BIP-39 phrase writes out.
100
170
  *
@@ -110,17 +180,7 @@ export declare class Identity {
110
180
  */
111
181
  static toPhrase(seed: Uint8Array): string;
112
182
  /**
113
- * Verify a signature against an arbitrary public key.
114
- *
115
- * @param {Uint8Array} publicKey
116
- * @param {Uint8Array} message
117
- * @param {Uint8Array} signature
118
- * @returns {boolean}
119
- */
120
- static verify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
121
- /**
122
- * Seal a message to an identity's Ed25519 public key (sealed box over the curve25519
123
- * conversion).
183
+ * Seal a message to a device's Ed25519 public key (sealed box over the curve25519 conversion).
124
184
  *
125
185
  * @param {Uint8Array} publicKey
126
186
  * @param {Uint8Array} message
@@ -128,7 +188,7 @@ export declare class Identity {
128
188
  */
129
189
  static seal(publicKey: Uint8Array, message: Uint8Array): Uint8Array;
130
190
  /**
131
- * Generate a fresh Ed25519 keypair (for devices, blind invites, etc.).
191
+ * Generate a fresh Ed25519 keypair (for devices, writers, blind invites).
132
192
  *
133
193
  * @returns {KeyPair}
134
194
  */
@@ -5,6 +5,9 @@ export type Prim = {
5
5
  export type TypeDef = {
6
6
  kind: 'single' | 'collection' | 'action';
7
7
  fields: Record<string, Prim>;
8
+ indexes?: Record<string, string[]>;
9
+ own?: boolean;
10
+ push?: boolean;
8
11
  };
9
12
  export type SchemaDefs = {
10
13
  [name: string]: TypeDef | Record<string, TypeDef>;
@@ -39,28 +42,36 @@ export declare const t: {
39
42
  * Single-row table (one record, set/get by name).
40
43
  *
41
44
  * @param {Record<string, Prim>} fields
45
+ * @param {{ push?: boolean }} [opts] `push`: a write pushes a notification, see collection.
42
46
  * @returns {TypeDef}
43
47
  */
44
- single(fields: Record<string, Prim>): TypeDef;
48
+ single(fields: Record<string, Prim>, opts?: {
49
+ push?: boolean;
50
+ }): TypeDef;
45
51
  /**
46
52
  * Multi-row table keyed by `id`. `own` restricts a row to the member who wrote it — anyone
47
- * may add rows, but only the author changes or deletes theirs.
53
+ * may add rows, but only the author changes or deletes theirs. `push` makes a write to it push
54
+ * a notification to the other members' devices; what it says is the app's push worklet's.
48
55
  *
49
56
  * @param {Record<string, Prim>} fields
50
- * @param {{ indexes?: Record<string, string[]>, own?: boolean }} [opts]
57
+ * @param {{ indexes?: Record<string, string[]>, own?: boolean, push?: boolean }} [opts]
51
58
  * @returns {TypeDef}
52
59
  */
53
60
  collection(fields: Record<string, Prim>, opts?: {
54
61
  indexes?: Record<string, string[]>;
55
62
  own?: boolean;
63
+ push?: boolean;
56
64
  }): TypeDef;
57
65
  /**
58
66
  * RPC-style mutation that doesn't persist a row.
59
67
  *
60
68
  * @param {Record<string, Prim>} fields
69
+ * @param {{ push?: boolean }} [opts] `push`: a call pushes a notification, see collection.
61
70
  * @returns {TypeDef}
62
71
  */
63
- action(fields: Record<string, Prim>): TypeDef;
72
+ action(fields: Record<string, Prim>, opts?: {
73
+ push?: boolean;
74
+ }): TypeDef;
64
75
  /**
65
76
  * Add fields to a builtin type (members, devices, …). Merged into the
66
77
  * builtin's base fields at build time; redeclaring a base field throws.
@@ -16,9 +16,8 @@ declare function getEncoding(name: any): {
16
16
  decode(state: any): {
17
17
  invite: any;
18
18
  reply: any;
19
- proof: any;
20
- identity: any;
21
19
  signature: any;
20
+ proof: any;
22
21
  ts: any;
23
22
  };
24
23
  } | {
@@ -38,6 +37,7 @@ declare function getEncoding(name: any): {
38
37
  key: any;
39
38
  encryptionKey: any;
40
39
  epochs: any;
40
+ proof: any;
41
41
  };
42
42
  } | {
43
43
  preencode(state: any, m: any): void;
@@ -80,9 +80,8 @@ declare function getStruct(name: any, v?: number): {
80
80
  } | {
81
81
  invite: any;
82
82
  reply: any;
83
- proof: any;
84
- identity: any;
85
83
  signature: any;
84
+ proof: any;
86
85
  ts: any;
87
86
  } | {
88
87
  epoch: any;
@@ -94,6 +93,7 @@ declare function getStruct(name: any, v?: number): {
94
93
  key: any;
95
94
  encryptionKey: any;
96
95
  epochs: any;
96
+ proof: any;
97
97
  } | {
98
98
  data: any;
99
99
  } | {
@@ -4,10 +4,6 @@ import { Presence } from './presence.js';
4
4
  /** @type {(topic: Uint8Array, channel: string | null) => Uint8Array} */
5
5
  export declare function channelTopic(topic: Uint8Array<ArrayBufferLike>, channel: string): Uint8Array<ArrayBufferLike>;
6
6
  export type NetworkOpts = {
7
- /**
8
- * Long-lived keypair used as the swarm identity.
9
- */
10
- identity?: import('../identity/index.js').Identity;
11
7
  /**
12
8
  * Custom DHT bootstrap nodes.
13
9
  */
@@ -54,7 +50,6 @@ export type NetworkOpts = {
54
50
  };
55
51
  /**
56
52
  * @typedef {object} NetworkOpts
57
- * @property {import('../identity/index.js').Identity} [identity] Long-lived keypair used as the swarm identity.
58
53
  * @property {Array<{ host: string, port: number }>} [bootstrap] Custom DHT bootstrap nodes.
59
54
  * @property {(remotePublicKey: Uint8Array, payload: unknown) => boolean} [firewall] Incoming-connection filter.
60
55
  * @property {Uint8Array[]} [relayThrough] Relay public keys to tunnel through.
@@ -70,7 +65,6 @@ export type NetworkOpts = {
70
65
  * replicates the store.
71
66
  */
72
67
  export declare class Network extends ReadyResource {
73
- identity: import("../index.js").Identity;
74
68
  bootstrap: {
75
69
  host: string;
76
70
  port: number;
@@ -101,7 +95,7 @@ export declare class Network extends ReadyResource {
101
95
  /** @private */
102
96
  _onerror;
103
97
  /** @param {NetworkOpts} opts */
104
- constructor({ identity, bootstrap, firewall, relayThrough, backoffs, channel, store, mirrors, presence, onerror }?: NetworkOpts);
98
+ constructor({ bootstrap, firewall, relayThrough, backoffs, channel, store, mirrors, presence, onerror }?: NetworkOpts);
105
99
  /** @returns {import('hyperswarm') | null} The underlying hyperswarm, or null before ready / after close. */
106
100
  get swarm(): import('hyperswarm') | null;
107
101
  /** @returns {Map<string, object>} Known peers keyed by public-key string. */
@@ -42,6 +42,10 @@ export type AcceptOpts = {
42
42
  * Role granted: the invite's by default, at most the invite's.
43
43
  */
44
44
  role?: string;
45
+ /**
46
+ * The joiner's chain to your identity, from `identity.link`: it joins as a device of yours, not as a member.
47
+ */
48
+ proof?: Uint8Array | null;
45
49
  };
46
50
  export type JoinOpts = {
47
51
  /**
@@ -89,6 +93,10 @@ export type JoinResult = {
89
93
  * The writer the join admitted: open the database with it.
90
94
  */
91
95
  writer: KeyPair;
96
+ /**
97
+ * A device's chain to the identity it was linked under, null for a member.
98
+ */
99
+ proof: Uint8Array | null;
92
100
  };
93
101
  /**
94
102
  * @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array }} KeyPair
@@ -106,6 +114,7 @@ export type JoinResult = {
106
114
  *
107
115
  * @typedef {object} AcceptOpts
108
116
  * @property {string} [role] Role granted: the invite's by default, at most the invite's.
117
+ * @property {Uint8Array | null} [proof] The joiner's chain to your identity, from `identity.link`: it joins as a device of yours, not as a member.
109
118
  *
110
119
  * @typedef {object} JoinOpts
111
120
  * @property {import('../identity/index.js').Identity} identity Who joins: the member they become, and who signs the join.
@@ -120,6 +129,7 @@ export type JoinResult = {
120
129
  * @property {Uint8Array | null} encryptionKey
121
130
  * @property {Array<{ epoch: number, stamp: number, entropy: Uint8Array }>} epochs
122
131
  * @property {KeyPair} writer The writer the join admitted: open the database with it.
132
+ * @property {Uint8Array | null} proof A device's chain to the identity it was linked under, null for a member.
123
133
  */
124
134
  /**
125
135
  * Invites into a database. An invite is a record in the database; a joiner writes one signed
@@ -172,7 +182,7 @@ export declare class Pairing extends ReadyResource {
172
182
  * @param {AcceptOpts} [opts]
173
183
  * @returns {Promise<void>}
174
184
  */
175
- accept(id: string, { role }?: AcceptOpts): Promise<void>;
185
+ accept(id: string, { role, proof }?: AcceptOpts): Promise<void>;
176
186
  /**
177
187
  * Refuse a join waiting on a `confirm` invite, by its id in `requests`, with an optional reason.
178
188
  *
@@ -212,7 +222,8 @@ export declare class Pairing extends ReadyResource {
212
222
  }
213
223
  /**
214
224
  * A join's payload: sealed to the database's address, so only its members read who joins; proven
215
- * by the invite over the writer; signed by the joiner's identity for this writer and reply address.
225
+ * by the invite over the writer; signed by the joiner's device, under its chain to the identity,
226
+ * for this writer and reply address.
216
227
  *
217
228
  * @param {Invite} invite
218
229
  * @param {import('../identity/index.js').Identity} identity