@cero-base/core 2.2.0 → 2.3.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/README.md +32 -212
- package/package.json +19 -10
- package/src/blobs/index.js +9 -0
- package/src/blobs/server.js +2 -0
- package/src/database/changes.js +1 -1
- package/src/database/dispatch.js +341 -209
- package/src/database/encryption.js +83 -33
- package/src/database/index.js +184 -83
- package/src/database/rotation.js +43 -30
- package/src/identity/index.js +20 -78
- package/src/index.js +3 -10
- package/src/lib/constants.js +2 -0
- package/src/lib/errors.js +3 -11
- package/src/lib/spec/index.js +136 -132
- package/src/lib/spec/schema.json +84 -99
- package/src/lib/utils.js +57 -3
- package/src/mailbox/inbox.js +103 -0
- package/src/mailbox/index.js +146 -0
- package/src/mailbox/post.js +69 -0
- package/src/network/discovery.js +26 -1
- package/src/network/index.js +105 -64
- package/src/network/presence.js +6 -2
- package/src/pairing/index.js +330 -254
- package/src/pairing/invite.js +83 -144
- package/src/pairing/request.js +54 -56
- package/src/rpc/index.js +18 -93
- package/src/rpc/peer.js +4 -1
- package/src/storage/index.js +78 -39
- package/types/blobs/index.d.ts +22 -9
- package/types/blobs/server.d.ts +4 -2
- package/types/database/changes.d.ts +2 -2
- package/types/database/dispatch.d.ts +19 -13
- package/types/database/encryption.d.ts +67 -29
- package/types/database/index.d.ts +144 -119
- package/types/database/rotation.d.ts +32 -13
- package/types/identity/index.d.ts +6 -47
- package/types/index.d.ts +3 -16
- package/types/lib/constants.d.ts +1 -0
- package/types/lib/errors.d.ts +3 -9
- package/types/lib/spec/index.d.ts +52 -16
- package/types/lib/utils.d.ts +40 -8
- package/types/mailbox/inbox.d.ts +52 -0
- package/types/mailbox/index.d.ts +111 -0
- package/types/mailbox/post.d.ts +37 -0
- package/types/network/discovery.d.ts +21 -5
- package/types/network/index.d.ts +64 -48
- package/types/network/presence.d.ts +17 -4
- package/types/pairing/index.d.ts +143 -134
- package/types/pairing/invite.d.ts +70 -114
- package/types/pairing/request.d.ts +58 -98
- package/types/rpc/index.d.ts +26 -44
- package/types/rpc/peer.d.ts +10 -7
- package/types/storage/index.d.ts +64 -54
- package/src/pairing/candidate.js +0 -123
- package/types/pairing/candidate.d.ts +0 -36
package/src/storage/index.js
CHANGED
|
@@ -7,22 +7,21 @@ import ReadyResource from 'ready-resource'
|
|
|
7
7
|
|
|
8
8
|
import { ROCKS, BEE, SINGLE, COLLECTION, QUERY_RESERVED } from '../lib/constants.js'
|
|
9
9
|
import { genId } from '../lib/ids.js'
|
|
10
|
-
import { subscribe, filter } from '../lib/utils.js'
|
|
10
|
+
import { subscribe, filter, checkFields, checkRequired, stamp } from '../lib/utils.js'
|
|
11
11
|
import { CeroError } from '../lib/errors.js'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @typedef {object} StorageOpts
|
|
15
|
-
* @property {{ database:
|
|
15
|
+
* @property {{ database: object, meta?: { ns?: string, refs?: Record<string, { kind?: string }> } }} spec
|
|
16
16
|
* @property {'rocks' | 'bee'} backend
|
|
17
|
-
* @property {
|
|
18
|
-
* @property {
|
|
17
|
+
* @property {import('hypercore-storage')} [root] Pre-existing HypercoreStorage to reuse.
|
|
18
|
+
* @property {import('corestore')} [store] Pre-existing Corestore to reuse.
|
|
19
19
|
* @property {Uint8Array} [storageKey] 32-byte key encrypting the backing core at rest (bee backend only).
|
|
20
20
|
*
|
|
21
21
|
* @typedef {{ name: string, kind: string }} Ref
|
|
22
|
-
* @typedef {
|
|
23
|
-
* @typedef {
|
|
24
|
-
* @typedef {
|
|
25
|
-
* @typedef {{ data: any | null }} GetByIdResult
|
|
22
|
+
* @typedef {import('../database/index.js').Row} Row
|
|
23
|
+
* @typedef {import('../database/index.js').SingleResult} SingleResult
|
|
24
|
+
* @typedef {import('../database/index.js').ListResult} ListResult
|
|
26
25
|
*/
|
|
27
26
|
|
|
28
27
|
/**
|
|
@@ -57,14 +56,23 @@ export class Storage extends ReadyResource {
|
|
|
57
56
|
this.ns = spec.meta?.ns || 'cero'
|
|
58
57
|
this.refs = spec.meta?.refs || {}
|
|
59
58
|
|
|
59
|
+
/** @private */
|
|
60
60
|
this._cf = `${this.ns}/local`
|
|
61
|
+
/** @private */
|
|
61
62
|
this._ownsRoot = !root && !store
|
|
63
|
+
/** @private */
|
|
62
64
|
this._ownsStore = !store
|
|
65
|
+
/** @type {import('hypercore-storage') | null} */
|
|
63
66
|
this.root = root || null
|
|
67
|
+
/** @type {import('corestore') | null} */
|
|
64
68
|
this.store = store || null
|
|
69
|
+
/** @type {import('hyperdb') | null} */
|
|
65
70
|
this.db = null
|
|
71
|
+
/** @private */
|
|
72
|
+
this._writing = null
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
/** @private */
|
|
68
76
|
async _open() {
|
|
69
77
|
if (this._ownsRoot) {
|
|
70
78
|
this.root = new HypercoreStorage(this.dir, { columnFamilies: [this._cf] })
|
|
@@ -91,9 +99,11 @@ export class Storage extends ReadyResource {
|
|
|
91
99
|
await this.db.ready()
|
|
92
100
|
}
|
|
93
101
|
|
|
102
|
+
/** @private */
|
|
94
103
|
async _close() {
|
|
95
104
|
if (this.db) {
|
|
96
|
-
|
|
105
|
+
// after the writes already queued
|
|
106
|
+
if (this.db.flush) await this._serial(() => this.db.flush())
|
|
97
107
|
await this.db.close()
|
|
98
108
|
this.db = null
|
|
99
109
|
}
|
|
@@ -111,15 +121,16 @@ export class Storage extends ReadyResource {
|
|
|
111
121
|
* Insert (or overwrite by id) a row, stamping `id`/`createdAt`/`updatedAt`.
|
|
112
122
|
*
|
|
113
123
|
* @param {string} name
|
|
114
|
-
* @param {Record<string,
|
|
124
|
+
* @param {Record<string, unknown>} row
|
|
115
125
|
* @returns {Promise<SingleResult>}
|
|
116
126
|
*/
|
|
117
127
|
async put(name, row) {
|
|
118
128
|
this._guard()
|
|
119
129
|
const ref = this._ref(name)
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
const stored = {
|
|
130
|
+
checkFields(name, this.refs[name], row)
|
|
131
|
+
const was = row.id == null ? null : await this._read(ref, row.id)
|
|
132
|
+
const stored = stamp({ ...row, id: row.id ?? genId() }, was?.createdAt)
|
|
133
|
+
checkRequired(name, this.refs[name], stored)
|
|
123
134
|
await this._write(ref, stored)
|
|
124
135
|
return { data: stored }
|
|
125
136
|
}
|
|
@@ -128,23 +139,19 @@ export class Storage extends ReadyResource {
|
|
|
128
139
|
* Upsert by merging with the existing row, preserving `createdAt`.
|
|
129
140
|
*
|
|
130
141
|
* @param {string} name
|
|
131
|
-
* @param {Record<string,
|
|
142
|
+
* @param {Record<string, unknown>} row
|
|
132
143
|
* @param {{ upsert?: boolean }} [opts]
|
|
133
144
|
* @returns {Promise<SingleResult | null>}
|
|
134
145
|
*/
|
|
135
146
|
async set(name, row, { upsert = true } = {}) {
|
|
136
147
|
this._guard()
|
|
137
148
|
const ref = this._ref(name)
|
|
138
|
-
|
|
149
|
+
checkFields(name, this.refs[name], row)
|
|
139
150
|
const existing = await this._read(ref, row?.id)
|
|
140
151
|
if (!upsert && !existing) return null
|
|
141
|
-
/** @type {
|
|
142
|
-
const stored = {
|
|
143
|
-
|
|
144
|
-
...row,
|
|
145
|
-
createdAt: existing?.createdAt ?? ts,
|
|
146
|
-
updatedAt: ts
|
|
147
|
-
}
|
|
152
|
+
/** @type {Row} */
|
|
153
|
+
const stored = stamp({ ...existing, ...row }, existing?.createdAt)
|
|
154
|
+
checkRequired(name, this.refs[name], stored)
|
|
148
155
|
if (ref.kind === COLLECTION && !stored.id) stored.id = genId()
|
|
149
156
|
await this._write(ref, stored)
|
|
150
157
|
return { data: stored }
|
|
@@ -161,8 +168,10 @@ export class Storage extends ReadyResource {
|
|
|
161
168
|
this._guard()
|
|
162
169
|
const ref = this._ref(name)
|
|
163
170
|
const col = this._col(ref)
|
|
164
|
-
await this.
|
|
165
|
-
|
|
171
|
+
await this._serial(async () => {
|
|
172
|
+
await this.db.delete(col, id != null ? { id } : {})
|
|
173
|
+
await this.db.flush()
|
|
174
|
+
})
|
|
166
175
|
}
|
|
167
176
|
|
|
168
177
|
/**
|
|
@@ -170,8 +179,8 @@ export class Storage extends ReadyResource {
|
|
|
170
179
|
* record (single). With a string id: fetch that specific row.
|
|
171
180
|
*
|
|
172
181
|
* @param {string} name
|
|
173
|
-
* @param {string | Record<string,
|
|
174
|
-
* @returns {Promise<SingleResult | ListResult
|
|
182
|
+
* @param {string | Record<string, unknown>} [query]
|
|
183
|
+
* @returns {Promise<SingleResult | ListResult>}
|
|
175
184
|
*/
|
|
176
185
|
async get(name, query) {
|
|
177
186
|
this._guard()
|
|
@@ -194,12 +203,13 @@ export class Storage extends ReadyResource {
|
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
const data = await this.db.find(col, range(query)).toArray()
|
|
197
|
-
// a
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
// a full page leaves the count unknown unless asked, so a limited read stops at the page
|
|
207
|
+
const full = query?.limit != null && data.length >= query.limit
|
|
208
|
+
if (!full) return { data, total: data.length, size: data.length }
|
|
209
|
+
const all = query.total
|
|
210
|
+
? await this.db.find(col, range({ ...query, limit: undefined })).toArray()
|
|
211
|
+
: null
|
|
212
|
+
return { data, total: all?.length ?? null, size: data.length }
|
|
203
213
|
}
|
|
204
214
|
|
|
205
215
|
/**
|
|
@@ -207,7 +217,7 @@ export class Storage extends ReadyResource {
|
|
|
207
217
|
* underlying mutation. Destroy the stream to stop watching.
|
|
208
218
|
*
|
|
209
219
|
* @param {string} name
|
|
210
|
-
* @param {Record<string,
|
|
220
|
+
* @param {Record<string, unknown>} [query]
|
|
211
221
|
* @returns {import('streamx').Readable}
|
|
212
222
|
*/
|
|
213
223
|
watch(name, query) {
|
|
@@ -222,12 +232,16 @@ export class Storage extends ReadyResource {
|
|
|
222
232
|
})
|
|
223
233
|
}
|
|
224
234
|
|
|
235
|
+
/** @private */
|
|
225
236
|
_guard() {
|
|
226
237
|
if (this.closing || this.closed) throw CeroError.CLOSED('Storage')
|
|
227
238
|
if (!this.db) throw CeroError.NOT_READY('Storage', 'storage')
|
|
228
239
|
}
|
|
229
240
|
|
|
230
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* @param {string} name @returns {Ref}
|
|
243
|
+
* @private
|
|
244
|
+
*/
|
|
231
245
|
_ref(name) {
|
|
232
246
|
if (typeof name !== 'string' || !name) {
|
|
233
247
|
throw CeroError.INVALID('name must be a non-empty string')
|
|
@@ -237,22 +251,47 @@ export class Storage extends ReadyResource {
|
|
|
237
251
|
return { name, kind: ref.kind || COLLECTION }
|
|
238
252
|
}
|
|
239
253
|
|
|
240
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* @param {Ref} ref @returns {string}
|
|
256
|
+
* @private
|
|
257
|
+
*/
|
|
241
258
|
_col(ref) {
|
|
242
259
|
return `@${this.ns}/${ref.name}`
|
|
243
260
|
}
|
|
244
261
|
|
|
245
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* @param {Ref} ref @param {string} [id] @returns {Promise<Row | null>}
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
246
266
|
async _read(ref, id) {
|
|
247
267
|
if (ref.kind === SINGLE) return this.db.findOne(this._col(ref), {})
|
|
248
268
|
if (id == null) return null
|
|
249
269
|
return (await this.db.get(this._col(ref), { id })) ?? null
|
|
250
270
|
}
|
|
251
271
|
|
|
252
|
-
/**
|
|
272
|
+
/**
|
|
273
|
+
* @param {Ref} ref @param {Row} row @returns {Promise<void>}
|
|
274
|
+
* @private
|
|
275
|
+
*/
|
|
253
276
|
async _write(ref, row) {
|
|
254
|
-
await this.
|
|
255
|
-
|
|
277
|
+
await this._serial(async () => {
|
|
278
|
+
await this.db.insert(this._col(ref), row)
|
|
279
|
+
await this.db.flush()
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// one write at a time: hyperdb refuses a flush while another write is in progress
|
|
284
|
+
/** @private */
|
|
285
|
+
async _serial(write) {
|
|
286
|
+
const previous = this._writing
|
|
287
|
+
const current = (async () => {
|
|
288
|
+
try {
|
|
289
|
+
await previous
|
|
290
|
+
} catch {}
|
|
291
|
+
await write()
|
|
292
|
+
})()
|
|
293
|
+
this._writing = current
|
|
294
|
+
await current
|
|
256
295
|
}
|
|
257
296
|
|
|
258
297
|
/**
|
package/types/blobs/index.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export type BlobsOpts = {
|
|
|
21
21
|
* Explicit encryption key, overrides `identity.encryptionKey`.
|
|
22
22
|
*/
|
|
23
23
|
encryptionKey?: Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Core name in the store when no `key` is given; `blobs` by default.
|
|
26
|
+
*/
|
|
27
|
+
name?: string;
|
|
24
28
|
};
|
|
25
29
|
export type RawBlobId = import('./codec.js').RawBlobId;
|
|
26
30
|
/**
|
|
@@ -30,6 +34,7 @@ export type RawBlobId = import('./codec.js').RawBlobId;
|
|
|
30
34
|
* @property {import('../network/index.js').Network} [network] Optional network used to announce + replicate the core.
|
|
31
35
|
* @property {Uint8Array} [key] Pre-existing blob core key — joins an existing blob feed.
|
|
32
36
|
* @property {Uint8Array} [encryptionKey] Explicit encryption key, overrides `identity.encryptionKey`.
|
|
37
|
+
* @property {string} [name] Core name in the store when no `key` is given; `blobs` by default.
|
|
33
38
|
*
|
|
34
39
|
* @typedef {import('./codec.js').RawBlobId} RawBlobId
|
|
35
40
|
*/
|
|
@@ -39,11 +44,15 @@ export declare class Blobs extends ReadyResource {
|
|
|
39
44
|
identity: import("../index.js").Identity;
|
|
40
45
|
network: import("../index.js").Network;
|
|
41
46
|
encryptionKey: Uint8Array<ArrayBufferLike>;
|
|
42
|
-
name:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
name: string;
|
|
48
|
+
/** @private */
|
|
49
|
+
_coreKey;
|
|
50
|
+
/** @type {import('hypercore') | null} */
|
|
51
|
+
core: import('hypercore') | null;
|
|
52
|
+
/** @type {import('hyperblobs') | null} */
|
|
53
|
+
hyperblobs: import('hyperblobs') | null;
|
|
54
|
+
/** @private */
|
|
55
|
+
_discovery;
|
|
47
56
|
/** @param {BlobsOpts} [opts] */
|
|
48
57
|
constructor({ store, identity, network, key, encryptionKey, name }?: BlobsOpts);
|
|
49
58
|
/**
|
|
@@ -64,8 +73,10 @@ export declare class Blobs extends ReadyResource {
|
|
|
64
73
|
* @returns {Uint8Array | null}
|
|
65
74
|
*/
|
|
66
75
|
get discoveryKey(): Uint8Array | null;
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
/** @private */
|
|
77
|
+
private _open;
|
|
78
|
+
/** @private */
|
|
79
|
+
private _close;
|
|
69
80
|
/**
|
|
70
81
|
* Store a buffer or readable stream, returning its raw hyperblobs blobId.
|
|
71
82
|
*
|
|
@@ -99,8 +110,10 @@ export declare class Blobs extends ReadyResource {
|
|
|
99
110
|
/**
|
|
100
111
|
* @param {import('streamx').Readable} input
|
|
101
112
|
* @returns {Promise<RawBlobId>}
|
|
113
|
+
* @private
|
|
102
114
|
*/
|
|
103
|
-
_putStream
|
|
104
|
-
|
|
115
|
+
private _putStream;
|
|
116
|
+
/** @private */
|
|
117
|
+
private _guard;
|
|
105
118
|
}
|
|
106
119
|
export { encodeId, decodeId };
|
package/types/blobs/server.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export type Resolved = {
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class FileServer {
|
|
12
12
|
resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
|
|
13
|
-
server
|
|
13
|
+
/** @type {import('hypercore-blob-server')} */
|
|
14
|
+
server: import('hypercore-blob-server');
|
|
14
15
|
/**
|
|
15
16
|
* @param {object} opts
|
|
16
17
|
* @param {import('corestore')} opts.store
|
|
@@ -20,7 +21,8 @@ export declare class FileServer {
|
|
|
20
21
|
store: import('corestore');
|
|
21
22
|
resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
|
|
22
23
|
});
|
|
23
|
-
|
|
24
|
+
/** @returns {number} */
|
|
25
|
+
get port(): number;
|
|
24
26
|
listen(): Promise<void>;
|
|
25
27
|
/**
|
|
26
28
|
* Build a renderable localhost URL for a string file id.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @param {import('./index.js').Database} db
|
|
6
6
|
* @param {string} name Ref name (scopes the update ticks).
|
|
7
7
|
* @param {string} col Collection path (`@ns/name`).
|
|
8
|
-
* @param {(row:
|
|
8
|
+
* @param {(row: Record<string, unknown>) => boolean} matches
|
|
9
9
|
* @returns {import('streamx').Readable}
|
|
10
10
|
*/
|
|
11
|
-
export declare function makeChanges(db: import('./index.js').Database, name: string, col: string, matches: (row:
|
|
11
|
+
export declare function makeChanges(db: import('./index.js').Database, name: string, col: string, matches: (row: Record<string, unknown>) => boolean): import('streamx').Readable;
|
|
@@ -1,35 +1,38 @@
|
|
|
1
|
+
export declare const BESPOKE: Set<string>;
|
|
1
2
|
/**
|
|
2
3
|
* Build the hyperdispatch router for a spec: wires membership, builtin, and
|
|
3
4
|
* spec-defined collection/action ops, returning the router plus an apply loop.
|
|
4
5
|
*
|
|
5
6
|
* @param {object} opts
|
|
6
|
-
* @param {{ dispatch: { Router: Function }, meta?: { refs?: Record<string, { kind?: string,
|
|
7
|
+
* @param {{ dispatch: { Router: Function, encode: (name: string, value: unknown) => Uint8Array }, meta?: { refs?: Record<string, { kind?: string, internal?: boolean, own?: boolean, verb?: string, fields?: string[], required?: Record<string, string> }> } }} opts.spec Generated hyperdispatch spec.
|
|
7
8
|
* @param {string} opts.ns Namespace prefix for collection and op names.
|
|
8
|
-
* @param {Record<string, Function>} opts.routes Custom action handlers keyed by route name.
|
|
9
9
|
* @param {(err: Error) => void} opts.onerror Called when a malformed node is skipped.
|
|
10
10
|
* @param {() => Uint8Array | null} opts.key The database key, null until the bee booted.
|
|
11
11
|
* @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).
|
|
12
|
-
* @param {(
|
|
13
|
-
* @param {(
|
|
14
|
-
* @param {(
|
|
15
|
-
* @param {(
|
|
12
|
+
* @param {() => { publicKey: Uint8Array, secretKey: Uint8Array } | null} opts.room The keypair behind the database's address, which joins are sealed to.
|
|
13
|
+
* @param {(phase: 'before' | 'after', op: string) => Function[]} opts.hooks Registered hooks for an op, run inside its transaction.
|
|
14
|
+
* @param {(name: string) => void} opts.touch Marks a ref written by a hook, so its watchers tick.
|
|
15
|
+
* @param {(view: object, name: string, query?: string | import('./index.js').Query) => Promise<import('./index.js').SingleResult | import('./index.js').ListResult>} opts.read Planned read against a given view, for a hook's `ctx.get`.
|
|
16
16
|
* @returns {{ dispatch: (value: Buffer, ctx: object) => Promise<void>, apply: (nodes: Array<{ value: Buffer, key: Buffer }>, view: object, host: object) => Promise<void> }}
|
|
17
17
|
*/
|
|
18
|
-
export declare function makeDispatcher({ spec, ns,
|
|
18
|
+
export declare function makeDispatcher({ spec, ns, onerror, key, onepoch, room, hooks, touch, read }: {
|
|
19
19
|
spec: {
|
|
20
20
|
dispatch: {
|
|
21
21
|
Router: Function;
|
|
22
|
+
encode: (name: string, value: unknown) => Uint8Array;
|
|
22
23
|
};
|
|
23
24
|
meta?: {
|
|
24
25
|
refs?: Record<string, {
|
|
25
26
|
kind?: string;
|
|
26
|
-
|
|
27
|
+
internal?: boolean;
|
|
28
|
+
own?: boolean;
|
|
27
29
|
verb?: string;
|
|
30
|
+
fields?: string[];
|
|
31
|
+
required?: Record<string, string>;
|
|
28
32
|
}>;
|
|
29
33
|
};
|
|
30
34
|
};
|
|
31
35
|
ns: string;
|
|
32
|
-
routes: Record<string, Function>;
|
|
33
36
|
onerror: (err: Error) => void;
|
|
34
37
|
key: () => Uint8Array | null;
|
|
35
38
|
onepoch: (row: {
|
|
@@ -38,10 +41,13 @@ export declare function makeDispatcher({ spec, ns, routes, onerror, key, onepoch
|
|
|
38
41
|
wrapped: Uint8Array;
|
|
39
42
|
commit: Uint8Array;
|
|
40
43
|
}) => Promise<void>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
room: () => {
|
|
45
|
+
publicKey: Uint8Array;
|
|
46
|
+
secretKey: Uint8Array;
|
|
47
|
+
} | null;
|
|
48
|
+
hooks: (phase: 'before' | 'after', op: string) => Function[];
|
|
49
|
+
touch: (name: string) => void;
|
|
50
|
+
read: (view: object, name: string, query?: string | import('./index.js').Query) => Promise<import('./index.js').SingleResult | import('./index.js').ListResult>;
|
|
45
51
|
}): {
|
|
46
52
|
dispatch: (value: Buffer, ctx: object) => Promise<void>;
|
|
47
53
|
apply: (nodes: Array<{
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import Autobee from 'autobee';
|
|
2
|
-
import c from 'compact-encoding';
|
|
3
|
-
declare const WriterEncryption: any;
|
|
4
2
|
/**
|
|
5
3
|
* Encryption key for a rotation epoch's blob cores.
|
|
6
4
|
*
|
|
@@ -8,24 +6,49 @@ declare const WriterEncryption: any;
|
|
|
8
6
|
* @returns {Uint8Array}
|
|
9
7
|
*/
|
|
10
8
|
export declare function blobEpochKey(entropy: Uint8Array): Uint8Array;
|
|
11
|
-
/**
|
|
12
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Prime a keyring from a local core's persisted epoch stash.
|
|
11
|
+
*
|
|
12
|
+
* @param {Keyring} keyring
|
|
13
|
+
* @param {import('hypercore')} local
|
|
14
|
+
* @returns {Promise<void>}
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadEpochs(keyring: Keyring, local: import('hypercore')): Promise<void>;
|
|
13
17
|
/**
|
|
14
18
|
* Wire codec for a rotation announcement's envelope list — one sealed box
|
|
15
19
|
* per remaining member, addressed by member id.
|
|
20
|
+
*
|
|
21
|
+
* @param {Array<{ id: string }>} members
|
|
22
|
+
* @param {Uint8Array} secret
|
|
23
|
+
* @returns {Array<{ id: string, box: Uint8Array }>}
|
|
24
|
+
*/
|
|
25
|
+
export declare function seal(members: Array<{
|
|
26
|
+
id: string;
|
|
27
|
+
}>, secret: Uint8Array): Array<{
|
|
28
|
+
id: string;
|
|
29
|
+
box: Uint8Array;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* @param {import('../identity/index.js').Identity} identity
|
|
33
|
+
* @param {Uint8Array} wrapped
|
|
34
|
+
* @returns {Generator<Uint8Array, void, unknown>}
|
|
16
35
|
*/
|
|
17
|
-
export declare
|
|
36
|
+
export declare function opened(identity: import('../identity/index.js').Identity, wrapped: Uint8Array): Generator<Uint8Array, void, unknown>;
|
|
37
|
+
/** @type {import('compact-encoding').Encoder<Array<{ id: string, box: Uint8Array }>>} */
|
|
38
|
+
export declare const wraps: import('compact-encoding').Encoder<Array<{
|
|
18
39
|
id: string;
|
|
19
|
-
box: Uint8Array
|
|
20
|
-
}
|
|
40
|
+
box: Uint8Array;
|
|
41
|
+
}>>;
|
|
21
42
|
/**
|
|
22
43
|
* Wire codec for locally persisted / pairing-delivered epoch secrets.
|
|
44
|
+
*
|
|
45
|
+
* @type {import('compact-encoding').Encoder<Array<{ epoch: number, stamp: number, entropy: Uint8Array }>>}
|
|
23
46
|
*/
|
|
24
|
-
export declare const epochEntries:
|
|
47
|
+
export declare const epochEntries: import('compact-encoding').Encoder<Array<{
|
|
25
48
|
epoch: number;
|
|
26
49
|
stamp: number;
|
|
27
|
-
entropy: Uint8Array
|
|
28
|
-
}
|
|
50
|
+
entropy: Uint8Array;
|
|
51
|
+
}>>;
|
|
29
52
|
/**
|
|
30
53
|
* Per-database registry of rotation epochs.
|
|
31
54
|
*/
|
|
@@ -65,27 +88,42 @@ export declare class Keyring {
|
|
|
65
88
|
*/
|
|
66
89
|
remove(stamp: number): void;
|
|
67
90
|
}
|
|
68
|
-
/**
|
|
69
|
-
* The epoch-aware provider — the class itself is upstream WriterEncryption; the epoch
|
|
70
|
-
* behavior lives on the (patched) base prototype above.
|
|
71
|
-
*/
|
|
72
|
-
export declare class EpochEncryption extends WriterEncryption {
|
|
73
|
-
}
|
|
74
91
|
/**
|
|
75
92
|
* Autobee with a rotation keyring. Every provider autobee constructs (view/system factory,
|
|
76
|
-
* foreign cores, ActiveWriters) picks the epochs up through the patched base class
|
|
77
|
-
* this `
|
|
93
|
+
* foreign cores, ActiveWriters) picks the epochs up through the patched base class, which asks
|
|
94
|
+
* this instance for `keyId` and `getEntropy`.
|
|
78
95
|
*/
|
|
79
96
|
export declare class EpochAutobee extends Autobee {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
/** @type {Keyring | null} */
|
|
98
|
+
keyring: Keyring | null;
|
|
99
|
+
/** @private */
|
|
100
|
+
_epochStalled;
|
|
101
|
+
/** @private */
|
|
102
|
+
_epochRetry;
|
|
103
|
+
/** @private */
|
|
104
|
+
_epochRetryDelay;
|
|
105
|
+
/** @private */
|
|
106
|
+
_epochRetrySeen;
|
|
107
|
+
/**
|
|
108
|
+
* @param {import('corestore')} store
|
|
109
|
+
* @param {Uint8Array | null} key
|
|
110
|
+
* @param {{ keyring?: Keyring } & Record<string, unknown>} [handlers] Autobee's options, plus the keyring.
|
|
111
|
+
*/
|
|
112
|
+
constructor(store: import('corestore'), key: Uint8Array | null, handlers?: {
|
|
113
|
+
keyring?: Keyring;
|
|
114
|
+
} & Record<string, unknown>);
|
|
115
|
+
/** @returns {number} the key id new blocks are written with */
|
|
116
|
+
get keyId(): number;
|
|
117
|
+
/** @param {number} id @param {{ key?: Uint8Array }} [ctx] @returns {Promise<Uint8Array>} */
|
|
118
|
+
getEntropy(id: number, ctx?: {
|
|
119
|
+
key?: Uint8Array;
|
|
120
|
+
}): Promise<Uint8Array>;
|
|
121
|
+
/** @private */
|
|
122
|
+
private _close;
|
|
123
|
+
/** @private */
|
|
124
|
+
private _bumpPendingWriters;
|
|
125
|
+
/** @private */
|
|
126
|
+
private _applyWakeupHints;
|
|
127
|
+
/** @private */
|
|
128
|
+
private _scheduleEpochRetry;
|
|
90
129
|
}
|
|
91
|
-
export {};
|