@cero-base/core 1.19.0 → 2.0.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 +8 -5
- package/src/blobs/index.js +15 -15
- package/src/blobs/server.js +0 -2
- package/src/database/changes.js +3 -7
- package/src/database/dispatch.js +128 -203
- package/src/database/encryption.js +22 -52
- package/src/database/envelope.js +1 -3
- package/src/database/index.js +336 -387
- package/src/database/rotation.js +56 -70
- package/src/identity/index.js +5 -9
- package/src/index.js +5 -9
- package/src/lib/constants.js +3 -12
- package/src/lib/errors.js +6 -10
- package/src/lib/schema.js +2 -5
- package/src/lib/utils.js +9 -24
- package/src/network/index.js +138 -166
- package/src/pairing/candidate.js +2 -4
- package/src/pairing/index.js +41 -55
- package/src/pairing/invite.js +3 -4
- package/src/pairing/request.js +3 -9
- package/src/rpc/index.js +4 -14
- package/src/rpc/peer.js +3 -7
- package/src/storage/index.js +25 -31
- package/types/blobs/index.d.ts +5 -5
- package/types/blobs/server.d.ts +0 -2
- package/types/database/changes.d.ts +2 -5
- package/types/database/dispatch.d.ts +2 -6
- package/types/database/encryption.d.ts +8 -20
- package/types/database/index.d.ts +79 -96
- package/types/database/rotation.d.ts +14 -20
- package/types/identity/index.d.ts +5 -9
- package/types/index.d.ts +4 -3
- package/types/lib/errors.d.ts +6 -10
- package/types/lib/schema.d.ts +2 -5
- package/types/lib/utils.d.ts +3 -7
- package/types/network/index.d.ts +16 -26
- package/types/pairing/candidate.d.ts +1 -2
- package/types/pairing/index.d.ts +22 -30
- package/types/pairing/invite.d.ts +3 -3
- package/types/pairing/request.d.ts +1 -3
- package/types/rpc/index.d.ts +1 -4
- package/types/rpc/peer.d.ts +2 -4
- package/types/storage/index.d.ts +17 -20
|
@@ -8,16 +8,13 @@ import { CeroError } from '../lib/errors.js'
|
|
|
8
8
|
|
|
9
9
|
const { AutobeeEncryption, WriterEncryption } = autobeeEncryption
|
|
10
10
|
|
|
11
|
-
// same derivation constant autobee-encryption uses
|
|
12
|
-
// 'autobase' namespace) — epoch keys must hash with the identical hash-key ns
|
|
11
|
+
// the same derivation constant autobee-encryption uses
|
|
13
12
|
const NS_HASH_KEY = crypto.namespace('autobase', 4)[2]
|
|
14
13
|
|
|
15
14
|
const NS_BLOBS = crypto.namespace('cero/blobs', 1)[0]
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
|
-
* Encryption key for a rotation epoch's blob cores.
|
|
19
|
-
* keyed by the epoch entropy, so file confidentiality rotates with the room:
|
|
20
|
-
* only holders of the epoch secret can derive the core key.
|
|
17
|
+
* Encryption key for a rotation epoch's blob cores.
|
|
21
18
|
*
|
|
22
19
|
* @param {Uint8Array} entropy
|
|
23
20
|
* @returns {Uint8Array}
|
|
@@ -26,17 +23,9 @@ export function blobEpochKey(entropy) {
|
|
|
26
23
|
return crypto.hash([NS_BLOBS, entropy])
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
// autobee
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// the provider base class itself, so the epoch awareness is patched onto the
|
|
33
|
-
// autobee-encryption prototype. The pin MUST stay on the version autobee's own
|
|
34
|
-
// range resolves to — pin them apart and npm installs two copies, autobee uses
|
|
35
|
-
// the unpatched one, and every rotation silently writes epoch-0 blocks that a
|
|
36
|
-
// removed member can still read. Epoch 0 keeps the upstream
|
|
37
|
-
// GENESIS_ENTROPY derivation byte-for-byte; epoch n derives from the
|
|
38
|
-
// keyring's entropy. Without a keyring (auto.keyring unset) behavior is
|
|
39
|
-
// identical to upstream. Removable once autobee accepts a provider factory.
|
|
26
|
+
// autobee news WriterEncryption directly, so epoch awareness is patched onto the
|
|
27
|
+
// autobee-encryption prototype. Epoch 0 keeps the upstream derivation, epoch n derives
|
|
28
|
+
// from the keyring; without a keyring behaviour is identical to upstream
|
|
40
29
|
const baseGetKeys = AutobeeEncryption.prototype.getKeys
|
|
41
30
|
|
|
42
31
|
AutobeeEncryption.prototype.getKeys = async function (id, ctx) {
|
|
@@ -45,8 +34,7 @@ AutobeeEncryption.prototype.getKeys = async function (id, ctx) {
|
|
|
45
34
|
const keyring = this.auto?.keyring
|
|
46
35
|
const entropy = keyring && keyring.entropy(id)
|
|
47
36
|
if (!entropy) {
|
|
48
|
-
//
|
|
49
|
-
// over this throw detaches silently, and only a wakeup() re-adds it
|
|
37
|
+
// a writer autobee freezes over this throw and only wakeup() re-adds it
|
|
50
38
|
if (ctx?.key && this.auto?._epochStalled) {
|
|
51
39
|
this.auto._epochStalled.add(b4a.toString(ctx.key, 'hex'))
|
|
52
40
|
this.auto._scheduleEpochRetry()
|
|
@@ -94,8 +82,6 @@ export const wraps = c.array({
|
|
|
94
82
|
|
|
95
83
|
/**
|
|
96
84
|
* Wire codec for locally persisted / pairing-delivered epoch secrets.
|
|
97
|
-
* `epoch` is the apply-order sequence; `stamp` is the content-addressed
|
|
98
|
-
* uint32 written into block headers.
|
|
99
85
|
*/
|
|
100
86
|
export const epochEntries = c.array({
|
|
101
87
|
preencode(state, e) {
|
|
@@ -118,14 +104,7 @@ export const epochEntries = c.array({
|
|
|
118
104
|
})
|
|
119
105
|
|
|
120
106
|
/**
|
|
121
|
-
* Per-database registry of rotation epochs.
|
|
122
|
-
* (no entry needed — it derives from the upstream GENESIS_ENTROPY path).
|
|
123
|
-
* Every rotation adds an entry keyed by its content-addressed `stamp` (the
|
|
124
|
-
* uint32 written into block headers, chosen randomly by the rotator and
|
|
125
|
-
* validated unique at apply) alongside its apply-order `seq`. Because the
|
|
126
|
-
* stamp is chosen before any block is written and can never be renumbered
|
|
127
|
-
* by linearization, a block's header always identifies its true key —
|
|
128
|
-
* concurrent rotations cannot make blocks undecryptable.
|
|
107
|
+
* Per-database registry of rotation epochs.
|
|
129
108
|
*/
|
|
130
109
|
export class Keyring {
|
|
131
110
|
constructor() {
|
|
@@ -199,16 +178,15 @@ export class Keyring {
|
|
|
199
178
|
}
|
|
200
179
|
|
|
201
180
|
/**
|
|
202
|
-
* The epoch-aware provider — the class itself is upstream WriterEncryption;
|
|
203
|
-
*
|
|
204
|
-
* call sites and tests.
|
|
181
|
+
* The epoch-aware provider — the class itself is upstream WriterEncryption; the epoch
|
|
182
|
+
* behavior lives on the (patched) base prototype above.
|
|
205
183
|
*/
|
|
206
184
|
export class EpochEncryption extends WriterEncryption {}
|
|
207
185
|
|
|
208
186
|
/**
|
|
209
|
-
* Autobee with a rotation keyring. Every provider autobee constructs
|
|
210
|
-
*
|
|
211
|
-
*
|
|
187
|
+
* Autobee with a rotation keyring. Every provider autobee constructs (view/system factory,
|
|
188
|
+
* foreign cores, ActiveWriters) picks the epochs up through the patched base class and
|
|
189
|
+
* this `keyring` property.
|
|
212
190
|
*/
|
|
213
191
|
export class EpochAutobee extends Autobee {
|
|
214
192
|
constructor(store, key, handlers = {}) {
|
|
@@ -220,12 +198,14 @@ export class EpochAutobee extends Autobee {
|
|
|
220
198
|
this._epochRetrySeen = 0
|
|
221
199
|
}
|
|
222
200
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
201
|
+
async _close() {
|
|
202
|
+
if (this._epochRetry) clearTimeout(this._epochRetry)
|
|
203
|
+
this._epochRetry = null
|
|
204
|
+
return super._close()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// an UNKNOWN_EPOCH from the drain parks the pass; the retry wakes the stalled cores once the
|
|
208
|
+
// announcement lands. Forward the arguments: the local drain passes { local: true }
|
|
229
209
|
async _bumpPendingWriters(...args) {
|
|
230
210
|
try {
|
|
231
211
|
return await super._bumpPendingWriters(...args)
|
|
@@ -236,8 +216,7 @@ export class EpochAutobee extends Autobee {
|
|
|
236
216
|
}
|
|
237
217
|
}
|
|
238
218
|
|
|
239
|
-
// hints read the system bee outside
|
|
240
|
-
// UNKNOWN_EPOCH would close the bee; park and retry like everything else
|
|
219
|
+
// hints read the system bee outside the guarded drain; park and retry like everything else
|
|
241
220
|
async _applyWakeupHints() {
|
|
242
221
|
try {
|
|
243
222
|
return await super._applyWakeupHints()
|
|
@@ -248,10 +227,7 @@ export class EpochAutobee extends Autobee {
|
|
|
248
227
|
}
|
|
249
228
|
}
|
|
250
229
|
|
|
251
|
-
// a stalled core produces no wake-up of its own
|
|
252
|
-
// over one only comes back through wakeup(), update() never re-adds it.
|
|
253
|
-
// Exponential backoff (reset when the keyring advances) so a removed member,
|
|
254
|
-
// who will never learn the epoch, settles into a slow idle poll
|
|
230
|
+
// a stalled core produces no wake-up of its own, only wakeup() re-adds it; exponential backoff
|
|
255
231
|
_scheduleEpochRetry() {
|
|
256
232
|
if (this._epochRetry || this.closing) return
|
|
257
233
|
const version = this.keyring ? this.keyring.version : 0
|
|
@@ -270,12 +246,6 @@ export class EpochAutobee extends Autobee {
|
|
|
270
246
|
}, this._epochRetryDelay)
|
|
271
247
|
this._epochRetryDelay = Math.min(this._epochRetryDelay * 2, 60000)
|
|
272
248
|
}
|
|
273
|
-
|
|
274
|
-
async _close() {
|
|
275
|
-
if (this._epochRetry) clearTimeout(this._epochRetry)
|
|
276
|
-
this._epochRetry = null
|
|
277
|
-
return super._close()
|
|
278
|
-
}
|
|
279
249
|
}
|
|
280
250
|
|
|
281
251
|
function noop() {}
|
package/src/database/envelope.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a'
|
|
2
2
|
import c from 'compact-encoding'
|
|
3
3
|
|
|
4
|
-
// 0xff is
|
|
5
|
-
// hyperdispatch routes, so it safely marks a version-enveloped op. Peers too
|
|
6
|
-
// old to know the envelope throw on it and skip deterministically.
|
|
4
|
+
// 0xff is unreachable as a hyperdispatch route prefix, so it marks a version-enveloped op
|
|
7
5
|
const SENTINEL = 0xff
|
|
8
6
|
|
|
9
7
|
/**
|