@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
package/README.md CHANGED
@@ -86,7 +86,7 @@ db.before('put', (ctx) => {
86
86
  })
87
87
  ```
88
88
 
89
- `db.bootstrap(...)` swaps from the identity keypair to a fresh per-device writer. For a **second device** sharing the same identity, use `db.bootstrap({ recovering: true })` — it waits for the first peer append, then swaps off the identity-keyed bootstrap-writer slot so autobee correctly applies remote appends.
89
+ `db.bootstrap(...)` provisions this device. Its writer core was minted when the database opened and this device is its only author, ever. For a **second device** sharing the same identity, use `db.bootstrap({ recovering: true })` — it waits for the other devices' state, admits itself with a master-signed add-writer appended optimistically, then records the device.
90
90
 
91
91
  `db.claim()` is an alternative path: a second device claims its existing local writer; the host admits it via `add-writer` once it sees the claim.
92
92
 
@@ -146,14 +146,13 @@ await client.rpc.ping('hi') // → 'pong:hi'
146
146
  ## Utils
147
147
 
148
148
  ```js
149
- import { toId, toKey, isKeyId, genId, subscribe } from '@cero-base/core/utils'
149
+ import { genId, subscribe } from '@cero-base/core/utils'
150
150
 
151
- toId(bee.key) // 32-byte buffer → z32 string (validates length)
152
- toKey('a1b2…') // string → 32-byte buffer
153
- isKeyId('foo') // → false
154
151
  genId() // short z32 of 16 random bytes (for ids)
155
152
  ```
156
153
 
154
+ Keys travel as z32 strings through `hypercore-id-encoding` (`hid.encode(bee.key)` / `hid.decode(id)`).
155
+
157
156
  `subscribe({ get, watch })` builds a Readable that re-emits the latest `get()` on every `watch(fn)` tick — the primitive `Database.watch` is built on.
158
157
 
159
158
  ## Errors
@@ -218,7 +217,7 @@ Every factory produces a `CeroError` with `name === 'CeroError'`, `isCeroError =
218
217
  cd packages/core && npm test
219
218
  ```
220
219
 
221
- Runs `brittle-node test/*.test.js` (brittle v4). `npm run build:test` regenerates the test fixture spec.
220
+ Runs every `test/**/*.test.js` under brittle-node (brittle v4). `npm run build:test` regenerates the test fixture spec.
222
221
 
223
222
  ## Types
224
223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cero-base/core",
3
- "version": "1.18.2",
3
+ "version": "1.19.0",
4
4
  "description": "cero p2p primitives — identity, storage, network, database, blobs, rpc, pairing.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -125,14 +125,14 @@
125
125
  },
126
126
  "scripts": {
127
127
  "build": "node schema/build.js",
128
- "build:test": "rm -rf test/fixture/spec && node test/fixture/build.js",
128
+ "build:test": "rm -rf test/fixtures/spec && node test/fixtures/build.js",
129
129
  "build:types": "rm -rf types && tsc -p .",
130
130
  "pretest": "npm run build:test",
131
131
  "prepublishOnly": "npm run build:types",
132
132
  "test": "npm run test:bare",
133
- "test:bare": "brittle-bare test/bare.js test/*.test.js",
133
+ "test:bare": "brittle-bare test/bare.js $(find test -name '*.test.js' | sort)",
134
134
  "pretest:bare": "npm run build:test",
135
- "test:node": "brittle-node test/*.test.js"
135
+ "test:node": "brittle-node $(find test -name '*.test.js' | sort)"
136
136
  },
137
137
  "dependencies": {
138
138
  "@hyperswarm/secret-stream": "^6.9.1",
@@ -145,12 +145,12 @@
145
145
  "bip39-mnemonic": "^2.5.0",
146
146
  "blind-pairing": "^2.3.1",
147
147
  "blind-peering": "^2.7.0",
148
- "compact-encoding": "^3.3.2",
149
- "corestore": "^7.12.2",
148
+ "compact-encoding": "^3.4.0",
149
+ "corestore": "^7.12.3",
150
150
  "framed-stream": "^1.0.1",
151
151
  "hrpc": "^4.3.1",
152
152
  "hyperblobs": "^2.12.1",
153
- "hypercore": "^11.35.2",
153
+ "hypercore": "^11.35.4",
154
154
  "hypercore-blob-server": "^1.15.0",
155
155
  "hypercore-crypto": "^3.7.0",
156
156
  "hypercore-id-encoding": "^1.3.0",
@@ -177,7 +177,7 @@
177
177
  "bare-url": "^2.5.4",
178
178
  "blind-peer": "^3.14.1",
179
179
  "brittle": "^4.1.1",
180
- "typescript": "^5.9.3",
180
+ "typescript": "^7.0.2",
181
181
  "which-runtime": "^1.4.0"
182
182
  },
183
183
  "license": "Apache-2.0"
@@ -1,9 +1,9 @@
1
1
  import Hyperblobs from 'hyperblobs'
2
2
  import ReadyResource from 'ready-resource'
3
3
  import b4a from 'b4a'
4
+ import hid from 'hypercore-id-encoding'
4
5
 
5
6
  import { NAMESPACE } from '../lib/constants.js'
6
- import { toId } from '../lib/utils.js'
7
7
  import { CeroError } from '../lib/errors.js'
8
8
  import { encodeId, decodeId } from './codec.js'
9
9
 
@@ -46,7 +46,7 @@ export class Blobs extends ReadyResource {
46
46
  * @returns {string | null}
47
47
  */
48
48
  get id() {
49
- return this.key ? toId(this.key) : null
49
+ return this.key ? hid.encode(this.key) : null
50
50
  }
51
51
 
52
52
  /**
@@ -3,12 +3,10 @@ import b4a from 'b4a'
3
3
 
4
4
  /**
5
5
  * Pull-driven delta stream over a collection: batches of `{ prev, next }`
6
- * pairs diffed between per-stream head cursors (`db.diff(col, { from })`).
7
- * Update ticks only mark the stream dirty — the diff runs when the reader
8
- * demands, so backpressure folds bursts into one bigger batch and nothing is
9
- * ever dropped. The first batch, and any batch after the view is swapped or
10
- * fast-forwarded to a new core, carries the full matching state as inserts
11
- * with `reset: true`.
6
+ * pairs diffed from the head this stream last reported. Update ticks only
7
+ * mark the stream dirty, the diff runs when the reader asks, so bursts fold
8
+ * into one batch and nothing is dropped. The first batch, and any batch after
9
+ * the view moved to another core, is the full matching state with `reset: true`.
12
10
  *
13
11
  * @param {import('./index.js').Database} db
14
12
  * @param {string} name Ref name (scopes the update ticks).
@@ -17,74 +15,54 @@ import b4a from 'b4a'
17
15
  * @returns {import('streamx').Readable}
18
16
  */
19
17
  export function makeChanges(db, name, col, matches) {
20
- let cursor = null
21
- let cursorView = null
18
+ let at = null
22
19
  let dirty = true
23
- let busy = false
24
- let off = null
25
-
26
- const stream = new Readable({
27
- open(cb) {
28
- off = db.onUpdate(mark, name)
29
- pump()
30
- cb(null)
31
- },
32
- read(cb) {
33
- pump()
34
- cb(null)
35
- },
36
- predestroy() {
37
- if (off) off()
38
- }
39
- })
20
+ let wake = null
40
21
 
41
22
  const mark = () => {
42
23
  dirty = true
43
- pump()
44
- }
45
-
46
- const pump = () => {
47
- if (busy || !dirty || stream.destroyed) return
48
- busy = true
49
- run()
50
- .catch((err) => stream.destroy(err))
51
- .finally(() => {
52
- busy = false
53
- })
24
+ if (wake !== null) wake()
54
25
  }
26
+ const off = db.onUpdate(mark, name)
55
27
 
56
- const run = async () => {
57
- while (dirty && !stream.destroyed) {
58
- dirty = false
59
- const batch = await diff()
60
- if (batch && stream.push(batch) === false) return
28
+ const stream = new Readable({
29
+ async read(cb) {
30
+ try {
31
+ let batch = null
32
+ while (batch === null && !stream.destroying) {
33
+ if (!dirty) await new Promise((resolve) => (wake = resolve))
34
+ dirty = false
35
+ batch = await diff()
36
+ }
37
+ if (batch !== null) stream.push(batch)
38
+ cb(null)
39
+ } catch (err) {
40
+ cb(err)
41
+ }
42
+ },
43
+ predestroy() {
44
+ off()
45
+ mark()
61
46
  }
62
- }
47
+ })
63
48
 
64
49
  const diff = async () => {
65
50
  const view = db.view
66
- // snapshot() and engine.head() are synchronous — captured back to back
67
- // they describe the same state, so the cursor is exactly-once
51
+ // snapshot() and head() are synchronous, so back to back they describe
52
+ // the same state and the cursor is exactly-once
68
53
  const snap = view.snapshot()
69
54
  const head = view.engine.head()
55
+ const reset =
56
+ at === null || at.view !== view || head === null || !b4a.equals(at.head.key, head.key)
70
57
  try {
71
- const fresh = !cursor || cursorView !== view || !head || !b4a.equals(cursor.key, head.key)
72
58
  const changes = []
73
- if (fresh) {
74
- for (const next of await snap.find(col, {}).toArray()) {
75
- if (matches(next)) changes.push({ prev: null, next })
76
- }
77
- } else {
78
- for await (const { left, right } of snap.diff(col, { from: cursor })) {
79
- const prev = left && matches(left) ? left : null
80
- const next = right && matches(right) ? right : null
81
- if (prev || next) changes.push({ prev, next })
82
- }
59
+ for await (const { left, right } of snap.diff(col, reset ? {} : { from: at.head })) {
60
+ const prev = left && matches(left) ? left : null
61
+ const next = right && matches(right) ? right : null
62
+ if (prev || next) changes.push({ prev, next })
83
63
  }
84
- cursor = head
85
- cursorView = view
86
- if (fresh) return { changes, reset: true }
87
- return changes.length ? { changes, reset: false } : null
64
+ at = head && { head, view }
65
+ return reset || changes.length ? { changes, reset } : null
88
66
  } finally {
89
67
  await snap.close().catch(() => {})
90
68
  }
@@ -1,5 +1,5 @@
1
1
  import b4a from 'b4a'
2
- import safetyCatch from 'safety-catch'
2
+ import hid from 'hypercore-id-encoding'
3
3
 
4
4
  import {
5
5
  SINGLE,
@@ -12,15 +12,7 @@ import {
12
12
  ASSIGN,
13
13
  WRITE
14
14
  } from '../lib/constants.js'
15
- import {
16
- toId,
17
- toKey,
18
- can,
19
- grants,
20
- outranks,
21
- addWriterPayload,
22
- claimWriterPayload
23
- } from '../lib/utils.js'
15
+ import { can, grants, outranks, admission, ownership } from '../lib/utils.js'
24
16
  import { CeroError } from '../lib/errors.js'
25
17
  import { Identity } from '../identity/index.js'
26
18
 
@@ -34,7 +26,7 @@ export const BUILTINS = [
34
26
  ]
35
27
 
36
28
  // Remote op fields are variable-length buffers on the wire — reject wrong sizes
37
- // before they reach sodium/toId, which throw instead of returning false.
29
+ // before they reach sodium/hid.encode, which throw instead of returning false.
38
30
  const isKey = (b) => b?.byteLength === 32
39
31
  const isSig = (b) => b?.byteLength === 64
40
32
 
@@ -42,22 +34,16 @@ const isSig = (b) => b?.byteLength === 64
42
34
  * Build the hyperdispatch router for a spec: wires membership, builtin, and
43
35
  * spec-defined collection/action ops, returning the router plus an apply loop.
44
36
  *
45
- * @param {{ dispatch: { Router: Function }, meta?: { refs?: Record<string, { kind?: string, builtin?: boolean, verb?: string }> } }} spec Generated hyperdispatch spec.
46
- * @param {string} ns Namespace prefix for collection and op names.
47
- * @param {Record<string, Function>} routes Custom action handlers keyed by route name.
48
- * @param {(err: Error) => void} [onerror] Called when a malformed node is skipped.
49
- * @param {() => Uint8Array | null} [getDbKey]
50
- * @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).
37
+ * @param {object} opts
38
+ * @param {{ dispatch: { Router: Function }, meta?: { refs?: Record<string, { kind?: string, builtin?: boolean, verb?: string }> } }} opts.spec Generated hyperdispatch spec.
39
+ * @param {string} opts.ns Namespace prefix for collection and op names.
40
+ * @param {Record<string, Function>} opts.routes Custom action handlers keyed by route name.
41
+ * @param {(err: Error) => void} opts.onerror Called when a malformed node is skipped.
42
+ * @param {() => Uint8Array | null} opts.key The database key, null until the bee booted.
43
+ * @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).
51
44
  * @returns {{ dispatcher: object, apply: (nodes: Array<{ value: Buffer, key: Buffer }>, view: object, host: object) => Promise<void> }}
52
45
  */
53
- export function makeDispatcher(
54
- spec,
55
- ns,
56
- routes,
57
- onerror = safetyCatch,
58
- getDbKey = () => null,
59
- hooks = {}
60
- ) {
46
+ export function makeDispatcher({ spec, ns, routes, onerror, key, onepoch }) {
61
47
  const dispatcher = new spec.dispatch.Router()
62
48
 
63
49
  const countersCol = `@${ns}/${COUNTERS}`
@@ -65,16 +51,16 @@ export function makeDispatcher(
65
51
  const getDevice = (view, id) => view.get(`@${ns}/devices`, { id })
66
52
 
67
53
  const getRole = async (view, identityKey) =>
68
- identityKey ? ((await getMember(view, toId(identityKey)))?.role ?? null) : null
54
+ identityKey ? ((await getMember(view, hid.encode(identityKey)))?.role ?? null) : null
69
55
 
70
56
  const getSignerRole = async (view, writerKey) => {
71
57
  if (!writerKey) return null
72
- const d = await getDevice(view, toId(writerKey))
58
+ const d = await getDevice(view, hid.encode(writerKey))
73
59
  return d?.memberId ? ((await getMember(view, d.memberId))?.role ?? null) : null
74
60
  }
75
61
  const isGenesis = async (view) => !(await view.findOne(`@${ns}/members`, {}))
76
62
  const getSignerMember = async (view, key) =>
77
- (key ? (await getDevice(view, toId(key)))?.memberId : null) ?? null
63
+ (key ? (await getDevice(view, hid.encode(key)))?.memberId : null) ?? null
78
64
  const canRemoveMember = async (view, signerKey, targetMemberId) => {
79
65
  const r = await getSignerRole(view, signerKey)
80
66
  if (!can(r, REMOVE)) return false
@@ -120,7 +106,7 @@ export function makeDispatcher(
120
106
 
121
107
  const upsert = (name, col, kind, own) => async (op, ctx) => {
122
108
  await requireWrite(ctx)
123
- const d = ctx.key && (await getDevice(ctx.view, toId(ctx.key)))
109
+ const d = ctx.key && (await getDevice(ctx.view, hid.encode(ctx.key)))
124
110
  op.memberId = d?.memberId || null
125
111
  if (kind !== COLLECTION) return ctx.view.insert(col, op)
126
112
  // `add` on an id that already exists is an overwrite, so it answers to the
@@ -135,7 +121,7 @@ export function makeDispatcher(
135
121
  if (own) await requireOwn(ctx, existing)
136
122
  // memberId is attribution, so it is derived here and never merged off the
137
123
  // wire — otherwise an edit could leave the row credited to its victim
138
- const d = ctx.key && (await getDevice(ctx.view, toId(ctx.key)))
124
+ const d = ctx.key && (await getDevice(ctx.view, hid.encode(ctx.key)))
139
125
  await insert(ctx.view, name, col, { ...existing, ...op, memberId: d?.memberId || null })
140
126
  }
141
127
  const remove = (col, own) => async (op, ctx) => {
@@ -152,7 +138,7 @@ export function makeDispatcher(
152
138
 
153
139
  add('add-writer', async (op, ctx) => {
154
140
  if (!isKey(op.master) || !isKey(op.writer) || !isSig(op.sig)) return
155
- if (!Identity.verify(op.master, addWriterPayload(ctx.dbKey, op.writer, ctx.key), op.sig)) return
141
+ if (!Identity.verify(op.master, admission(ctx.dbKey, op.writer, ctx.key), op.sig)) return
156
142
  const genesis = await isGenesis(ctx.view)
157
143
  const inviter = await getRole(ctx.view, op.master)
158
144
  if (!genesis && !can(inviter, INVITE)) throw CeroError.REFUSED('invite')
@@ -165,10 +151,10 @@ export function makeDispatcher(
165
151
  await ctx.host.addWriter(op.writer, { isIndexer: true })
166
152
  const ts = op.ts || 0
167
153
  await insert(ctx.view, 'devices', `@${ns}/devices`, {
168
- id: toId(op.writer),
154
+ id: hid.encode(op.writer),
169
155
  // bind to the joiner when the op says so: if their member row never
170
156
  // lands the device resolves to nobody, instead of to the inviter
171
- memberId: op.memberId || toId(op.master),
157
+ memberId: op.memberId || hid.encode(op.master),
172
158
  createdAt: ts,
173
159
  updatedAt: ts
174
160
  })
@@ -176,28 +162,28 @@ export function makeDispatcher(
176
162
 
177
163
  add('del-writer', async (op, ctx) => {
178
164
  if (!isKey(op.writer)) return
179
- const target = await getDevice(ctx.view, toId(op.writer))
165
+ const target = await getDevice(ctx.view, hid.encode(op.writer))
180
166
  if (target?.memberId !== (await getSignerMember(ctx.view, ctx.key))) {
181
167
  if (!(await canRemoveMember(ctx.view, ctx.key, target?.memberId))) {
182
168
  throw CeroError.REFUSED('remove')
183
169
  }
184
170
  }
185
171
  await ctx.host.removeWriter(op.writer)
186
- await ctx.view.delete(`@${ns}/devices`, { id: toId(op.writer) })
172
+ await ctx.view.delete(`@${ns}/devices`, { id: hid.encode(op.writer) })
187
173
  })
188
174
 
189
175
  add('claim-writer', async (op, ctx) => {
190
176
  if (!isKey(op.identity) || !isKey(op.writer) || !isSig(op.sig)) return
191
- if (!Identity.verify(op.identity, claimWriterPayload(ctx.dbKey, op.writer), op.sig)) return
177
+ if (!Identity.verify(op.identity, ownership(ctx.dbKey, op.writer), op.sig)) return
192
178
  // a claim is only meaningful from the claiming core — from any other it is
193
179
  // inapplicable, not refused, so it must not abort that writer's batch
194
180
  if (!b4a.equals(ctx.key, op.writer)) return
195
- const memberId = toId(op.identity)
181
+ const memberId = hid.encode(op.identity)
196
182
  if (!can(await getRole(ctx.view, op.identity), WRITE)) throw CeroError.REFUSED('write')
197
183
  await ctx.host.addWriter(op.writer, { isIndexer: true })
198
184
  const ts = op.ts || 0
199
185
  await insert(ctx.view, 'devices', `@${ns}/devices`, {
200
- id: toId(op.writer),
186
+ id: hid.encode(op.writer),
201
187
  memberId,
202
188
  createdAt: ts,
203
189
  updatedAt: ts
@@ -211,7 +197,7 @@ export function makeDispatcher(
211
197
  if (!can(r, INVITE) || !grants(r, op.role)) throw CeroError.REFUSED('invite')
212
198
  }
213
199
  await insert(ctx.view, 'members', `@${ns}/members`, op)
214
- const deviceId = toId(op.key)
200
+ const deviceId = hid.encode(op.key)
215
201
  const existingDevice = await getDevice(ctx.view, deviceId)
216
202
  const ts = op.updatedAt || 0
217
203
  await insert(ctx.view, 'devices', `@${ns}/devices`, {
@@ -255,7 +241,7 @@ export function makeDispatcher(
255
241
  if (next.key) await ctx.host.removeWriter(next.key)
256
242
  for (const device of await ctx.view.find(`@${ns}/devices`, {}).toArray()) {
257
243
  if (device.memberId !== next.id) continue
258
- await ctx.host.removeWriter(toKey(device.id))
244
+ await ctx.host.removeWriter(hid.decode(device.id))
259
245
  }
260
246
  // the device rows stay: they are how a key resolves to a member, and
261
247
  // deleting them would leave the demoted writer unresolvable — which the
@@ -275,7 +261,7 @@ export function makeDispatcher(
275
261
  // leave writers admitted or stale device rows behind
276
262
  for (const device of await ctx.view.find(`@${ns}/devices`, {}).toArray()) {
277
263
  if (device.memberId !== op.id) continue
278
- await ctx.host.removeWriter(toKey(device.id))
264
+ await ctx.host.removeWriter(hid.decode(device.id))
279
265
  await ctx.view.delete(`@${ns}/devices`, { id: device.id })
280
266
  }
281
267
  await ctx.view.delete(`@${ns}/members`, op)
@@ -318,9 +304,9 @@ export function makeDispatcher(
318
304
  await ctx.view.insert(`@${ns}/${EPOCHS}`, row)
319
305
  // per-peer hydration (unseal own envelope → keyring) — never in a dry
320
306
  // run: the announcement itself must be appended under the OLD epoch
321
- if (hooks.onEpoch && !ctx.dryRun) {
307
+ if (!ctx.dryRun) {
322
308
  try {
323
- await hooks.onEpoch(row)
309
+ await onepoch(row)
324
310
  } catch (err) {
325
311
  onerror(err)
326
312
  }
@@ -338,7 +324,7 @@ export function makeDispatcher(
338
324
  throw CeroError.REFUSED('remove')
339
325
  }
340
326
  }
341
- await ctx.host.removeWriter(toKey(existing.id))
327
+ await ctx.host.removeWriter(hid.decode(existing.id))
342
328
  await ctx.view.delete(`@${ns}/devices`, op)
343
329
  })
344
330
 
@@ -455,7 +441,7 @@ export function makeDispatcher(
455
441
  return {
456
442
  dispatcher,
457
443
  async apply(nodes, view, host) {
458
- const dbKey = getDbKey()
444
+ const dbKey = key()
459
445
  // Nodes land in a transaction this loop owns, so a refusal can discard the
460
446
  // whole batch — a batch is one writer's contiguous run (autobee keys it on
461
447
  // batch[0].key), so an abort only ever drops the offending writer's ops.