@cero-base/core 1.15.0 → 1.15.2
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 +2 -2
- package/src/database/dispatch.js +11 -2
- package/src/database/index.js +21 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cero-base/core",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.2",
|
|
4
4
|
"description": "cero p2p primitives — identity, storage, network, database, blobs, rpc, pairing.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
},
|
|
137
137
|
"dependencies": {
|
|
138
138
|
"@hyperswarm/secret-stream": "^6.9.1",
|
|
139
|
-
"autobee": "2.0.0-rc.
|
|
139
|
+
"autobee": "2.0.0-rc.27",
|
|
140
140
|
"autobee-encryption": "0.1.3",
|
|
141
141
|
"b4a": "^1.8.1",
|
|
142
142
|
"bare-crypto": "^1.15.3",
|
package/src/database/dispatch.js
CHANGED
|
@@ -266,15 +266,24 @@ export function makeDispatcher(
|
|
|
266
266
|
const col = `@${ns}/${b.name}`
|
|
267
267
|
if (b.verb === 'member') continue
|
|
268
268
|
if (b.verb === 'device') {
|
|
269
|
+
// A device row IS the writer→role mapping: getSignerRole resolves a
|
|
270
|
+
// writer key through it to a member, and every permission check reads
|
|
271
|
+
// that role. So memberId is never taken off the wire — it stays whatever
|
|
272
|
+
// add-writer/claim-writer/add-member bound, and an unknown id can only
|
|
273
|
+
// ever bind to the signer's own member. Otherwise one unauthenticated op
|
|
274
|
+
// would re-point a writer at the owner and inherit their authority.
|
|
275
|
+
const bind = async (op, ctx, existing) =>
|
|
276
|
+
existing?.memberId ?? (await getSignerMember(ctx.view, ctx.key))
|
|
269
277
|
add(`add-${b.verb}`, async (op, ctx) => {
|
|
270
|
-
await
|
|
278
|
+
const existing = await getDevice(ctx.view, op.id)
|
|
279
|
+
await insert(ctx.view, b.name, col, { ...op, memberId: await bind(op, ctx, existing) })
|
|
271
280
|
})
|
|
272
281
|
add(`set-${b.verb}`, async (op, ctx) => {
|
|
273
282
|
const existing = await getDevice(ctx.view, op.id)
|
|
274
283
|
const ts = op.updatedAt || 0
|
|
275
284
|
await insert(ctx.view, b.name, col, {
|
|
276
285
|
...op,
|
|
277
|
-
memberId:
|
|
286
|
+
memberId: await bind(op, ctx, existing),
|
|
278
287
|
createdAt: existing?.createdAt || op.createdAt || ts,
|
|
279
288
|
updatedAt: ts
|
|
280
289
|
})
|
package/src/database/index.js
CHANGED
|
@@ -195,13 +195,16 @@ export class Database extends ReadyResource {
|
|
|
195
195
|
// no cero row records another writer's oplog length to fall back to.
|
|
196
196
|
isTrusted: async (writer, view) => {
|
|
197
197
|
try {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
198
|
+
const row = await bounded(view.get(`@${this.ns}/devices`, { id: toId(writer) }))
|
|
199
|
+
if (!row) return false
|
|
200
|
+
if (row.v) return true
|
|
201
|
+
// only where the view PROVABLY holds no device yet (a boot's
|
|
202
|
+
// genesis-era reference) may the genesis writer vouch — its core IS
|
|
203
|
+
// the db key, and its signatures are unforgeable. Everyone else
|
|
204
|
+
// stays refused: an empty view is the window an ex-member targets.
|
|
205
|
+
const any = await bounded(view.find(`@${this.ns}/devices`, { limit: 1 }).toArray())
|
|
206
|
+
if (!any) return false
|
|
207
|
+
return any.v.length === 0 && !!this.key && b4a.equals(writer, this.key)
|
|
205
208
|
} catch {
|
|
206
209
|
return false
|
|
207
210
|
}
|
|
@@ -1240,6 +1243,17 @@ export class Database extends ReadyResource {
|
|
|
1240
1243
|
}
|
|
1241
1244
|
}
|
|
1242
1245
|
|
|
1246
|
+
// A trust decision reads a historic checkout view, whose blocks may not be
|
|
1247
|
+
// servable yet — an unbounded read there wedges autobee's drain forever. The
|
|
1248
|
+
// value is wrapped so a timeout (null) is never mistaken for what the read
|
|
1249
|
+
// would have returned; undecidable in time means "not trusted", and the
|
|
1250
|
+
// caller retries.
|
|
1251
|
+
const bounded = (promise, ms = 2000) =>
|
|
1252
|
+
Promise.race([
|
|
1253
|
+
promise.then((v) => ({ v })),
|
|
1254
|
+
new Promise((resolve) => setTimeout(() => resolve(null), ms))
|
|
1255
|
+
])
|
|
1256
|
+
|
|
1243
1257
|
// Fields the write path stamps itself — always allowed even if not user-declared.
|
|
1244
1258
|
const SYSTEM_FIELDS = new Set(['id', 'memberId', 'index', 'createdAt', 'updatedAt'])
|
|
1245
1259
|
|