@cero-base/core 2.10.0 → 2.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cero-base/core",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "cero p2p primitives — identity, storage, network, database, blobs, rpc, pairing.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -146,32 +146,32 @@
146
146
  "pretest": "npm run build:test",
147
147
  "prepublishOnly": "npm run build:types",
148
148
  "test": "npm run test:bare",
149
- "test:bare": "find test -name '*.test.js' | sort | xargs -P4 -n1 brittle-bare",
149
+ "test:bare": "find test -name '*.test.js' ! -name network.test.js | sort | xargs -P4 -n1 brittle-bare && brittle-bare test/network/network.test.js",
150
150
  "pretest:bare": "npm run build:test",
151
151
  "test:node": "find test -name '*.test.js' | sort | xargs -P4 -n1 brittle-node"
152
152
  },
153
153
  "dependencies": {
154
154
  "@hyperswarm/secret-stream": "^6.9.2",
155
- "autobee": "2.13.0",
155
+ "autobee": "2.13.3",
156
156
  "b4a": "^1.9.0",
157
157
  "bare-crypto": "^1.15.4",
158
158
  "bare-fs": "^4.8.4",
159
159
  "bare-path": "^3.1.2",
160
160
  "bip39-mnemonic": "^2.5.0",
161
- "blind-peering": "^2.12.2",
162
- "blind-push": "^1.0.2",
161
+ "blind-peering": "^2.13.1",
162
+ "blind-push": "^1.2.0",
163
163
  "compact-encoding": "^3.5.2",
164
164
  "corestore": "^7.16.1",
165
165
  "framed-stream": "^1.0.1",
166
166
  "hrpc": "^4.3.1",
167
167
  "hyperblobs": "^2.13.0",
168
- "hypercore": "^11.39.6",
168
+ "hypercore": "^11.40.0",
169
169
  "hypercore-blob-server": "^1.15.1",
170
170
  "hypercore-crypto": "^3.7.0",
171
171
  "hypercore-id-encoding": "^1.3.0",
172
172
  "hypercore-storage": "^3.4.0",
173
173
  "hyperdb": "^6.11.1",
174
- "hyperdht": "^6.35.0",
174
+ "hyperdht": "^6.36.0",
175
175
  "hyperdispatch": "^1.6.0",
176
176
  "hyperschema": "^1.26.2",
177
177
  "hyperswarm": "^4.17.2",
@@ -191,8 +191,8 @@
191
191
  "bare-fetch": "^3.4.1",
192
192
  "bare-process": "^4.5.1",
193
193
  "bare-subprocess": "^6.2.2",
194
- "bare-url": "^2.5.5",
195
- "blind-peer": "^3.16.0",
194
+ "bare-url": "^2.5.6",
195
+ "blind-peer": "^3.18.1",
196
196
  "blind-push-gateway": "^1.0.0",
197
197
  "brittle": "^4.5.0",
198
198
  "protomux": "^3.13.0",
@@ -378,6 +378,11 @@ export function makeDispatcher({ spec, ns, onerror, key, onepoch, room, hooks, t
378
378
  const minted = (await ctx.view.get(countersCol, { name: 'invites' }))?.value ?? 0
379
379
  await ctx.view.insert(removals, { id: hid.encode(device.key), index: minted })
380
380
  }
381
+ // a member who left, apart from one removed and from a revoked device: ids never hold ':'
382
+ function leftId(memberId) {
383
+ return `left:${memberId}`
384
+ }
385
+
381
386
  // the devices of the chain, not the identity it starts with: a member's removal is ordered by
382
387
  // its invites, a device's is for good
383
388
  async function revoked(view, proof) {
@@ -447,7 +452,9 @@ export function makeDispatcher({ spec, ns, onerror, key, onepoch, room, hooks, t
447
452
  const existing = await getMember(ctx.view, op.id)
448
453
  if (!existing) return
449
454
  let decided = null
450
- if (op.id !== (await getSignerMember(ctx.view, ctx.key))) {
455
+ // leaving is hers: only someone else taking her out turns her older codes away
456
+ const leaving = op.id === (await getSignerMember(ctx.view, ctx.key))
457
+ if (!leaving) {
451
458
  // the last owner stays, whatever a rule grants: without her nobody outranks the rest
452
459
  if (existing.role === OWNER && (await orphans(ctx.view, op.id))) {
453
460
  throw CeroError.INVALID(
@@ -474,9 +481,11 @@ export function makeDispatcher({ spec, ns, onerror, key, onepoch, room, hooks, t
474
481
  } else {
475
482
  await drop(ctx, 'members', op.id)
476
483
  }
477
- // an invite they could hold, or saw, does not bring them back
484
+ // an invite they could hold, or saw, does not bring them back on its own: after a removal it is turned away, after
485
+ // leaving it waits for a member to accept her again, so leaving first never dodges a removal. Either row re-keys
486
+ // the handle at its first removal (rotation.js)
478
487
  const minted = (await ctx.view.get(countersCol, { name: 'invites' }))?.value ?? 0
479
- await ctx.view.insert(removals, { id: op.id, index: minted })
488
+ await ctx.view.insert(removals, { id: leaving ? leftId(op.id) : op.id, index: minted })
480
489
  })
481
490
 
482
491
  add('rotate-key', async (op, ctx) => {
@@ -690,7 +699,9 @@ export function makeDispatcher({ spec, ns, onerror, key, onepoch, room, hooks, t
690
699
  (removal && (invite.index ?? 0) <= removal.index) || (await revoked(ctx.view, join.proof))
691
700
  if (out) return refuse(ctx, { id, reply: join.reply, expires: invite.expires || 0 }, 'removed')
692
701
  await ctx.view.delete(refusals, { id })
693
- if (invite.confirm && !known) {
702
+ const gone = known ? null : await ctx.view.get(removals, { id: leftId(memberId) })
703
+ const older = gone && (invite.index ?? 0) <= gone.index
704
+ if ((invite.confirm || older) && !known) {
694
705
  const waiting = request(invite, join.identity, signed.device, ctx.key, join.reply, ts)
695
706
  return save(ctx, 'put', 'requests', waiting)
696
707
  }
@@ -245,6 +245,9 @@ export class Database extends ReadyResource {
245
245
  })
246
246
  // without a listener autobee escalates apply/view errors to a process crash
247
247
  this.bee.on('error', this._onerror)
248
+ // a failed background remap is only a warning: the store reads its old cores until a reopen or a fast-forward
249
+ // tries again
250
+ this.bee.on('warning', this._onerror)
248
251
 
249
252
  // with no mirror to hold the database, every member holds it: any member serves a joiner, offline
250
253
  if (this.network && !this.network.mirrors.length) {
@@ -120,10 +120,18 @@ export class Mailbox extends ReadyResource {
120
120
  * @returns {Promise<void>}
121
121
  */
122
122
  async send(address, message, { mirrors = this.network.mirrors, keep = true } = {}) {
123
+ // a send racing the close fails as the mailbox closing, never as the storage under it
124
+ if (this.closing) throw CeroError.CLOSED('Mailbox')
123
125
  if (!this.opened) await this.ready()
124
126
  const name = b4a.toHex(crypto.randomBytes(32))
125
127
  const mail = { id: b4a.toHex(crypto.randomBytes(16)), name, address, message, mirrors, keep }
126
- await this.outbox.put(mail)
128
+ try {
129
+ await this.outbox.put(mail)
130
+ } catch (err) {
131
+ if (this.closing) throw CeroError.CLOSED('Mailbox')
132
+ throw err
133
+ }
134
+ if (this.closing) throw CeroError.CLOSED('Mailbox')
127
135
  this._deliver(mail)
128
136
  }
129
137
 
@@ -83,6 +83,8 @@ export class Network extends ReadyResource {
83
83
  /** @private */
84
84
  this._blindPeering = null
85
85
  /** @private */
86
+ this._peeringClosed = false
87
+ /** @private */
86
88
  this._lost = new Set()
87
89
  /** @private */
88
90
  this._relookup = null
@@ -222,6 +224,18 @@ export class Network extends ReadyResource {
222
224
  this.emit('connection', conn, info)
223
225
  }
224
226
 
227
+ /**
228
+ * Stop mirroring, before the databases close: blind peering reads storage for every database it
229
+ * mirrors, so once it is closed none of its work outlives storage. `peering()` throws CLOSED
230
+ * after it; closing the network does it too.
231
+ *
232
+ * @returns {Promise<void>}
233
+ */
234
+ async closePeering() {
235
+ this._peeringClosed = true
236
+ await this._blindPeering?.close()
237
+ }
238
+
225
239
  /**
226
240
  * The blind-peering client, built on first use: a mailbox post names mirrors this network
227
241
  * may not have been given.
@@ -229,7 +243,7 @@ export class Network extends ReadyResource {
229
243
  * @returns {import('blind-peering')}
230
244
  */
231
245
  peering() {
232
- if (this.closing || this.closed) throw CeroError.CLOSED('Network')
246
+ if (this.closing || this.closed || this._peeringClosed) throw CeroError.CLOSED('Network')
233
247
  if (!this._blindPeering) {
234
248
  this._blindPeering = new BlindPeering(this.swarm.dht, this.store, {
235
249
  blindPeers: this.mirrors.map((key) => ({ key })),
@@ -89,6 +89,8 @@ export declare class Network extends ReadyResource {
89
89
  /** @private */
90
90
  _blindPeering;
91
91
  /** @private */
92
+ _peeringClosed;
93
+ /** @private */
92
94
  _lost;
93
95
  /** @private */
94
96
  _relookup;
@@ -121,6 +123,14 @@ export declare class Network extends ReadyResource {
121
123
  }): import('@hyperswarm/secret-stream');
122
124
  /** @private */
123
125
  private _add;
126
+ /**
127
+ * Stop mirroring, before the databases close: blind peering reads storage for every database it
128
+ * mirrors, so once it is closed none of its work outlives storage. `peering()` throws CLOSED
129
+ * after it; closing the network does it too.
130
+ *
131
+ * @returns {Promise<void>}
132
+ */
133
+ closePeering(): Promise<void>;
124
134
  /**
125
135
  * The blind-peering client, built on first use: a mailbox post names mirrors this network
126
136
  * may not have been given.