@cero-base/cero 2.12.0 → 3.0.1
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 +6 -5
- package/src/build/index.js +296 -57
- package/src/build/internal.js +80 -5
- package/src/build/schemas.js +118 -25
- package/src/extensions/profile-sync.js +17 -1
- package/src/handle/index.js +1221 -189
- package/src/index.js +68 -35
- package/src/lib/constants.js +4 -4
- package/src/lib/operators.js +53 -14
- package/src/lib/peek.js +14 -8
- package/src/lib/reserved.js +61 -0
- package/src/lib/spec.js +7 -1
- package/src/lib/swap.js +59 -6
- package/src/local/index.js +6 -2
- package/src/push/index.js +26 -13
- package/src/rpc/client.js +24 -10
- package/src/rpc/push.js +9 -3
- package/src/rpc/server.js +132 -51
- package/types/build/internal.d.ts +57 -0
- package/types/build/schemas.d.ts +58 -5
- package/types/extensions/index.d.ts +2 -0
- package/types/extensions/profile-sync.d.ts +1 -1
- package/types/handle/index.d.ts +121 -15
- package/types/index.d.ts +9 -6
- package/types/lib/constants.d.ts +2 -2
- package/types/lib/operators.d.ts +16 -6
- package/types/lib/peek.d.ts +7 -4
- package/types/lib/reserved.d.ts +1 -0
- package/types/lib/spec.d.ts +35 -2
- package/types/lib/swap.d.ts +28 -3
- package/types/push/index.d.ts +4 -12
- package/types/rpc/client.d.ts +34 -18
- package/types/rpc/server.d.ts +24 -3
- package/src/handle/join.js +0 -139
- package/types/handle/join.d.ts +0 -63
package/src/build/schemas.js
CHANGED
|
@@ -42,7 +42,9 @@ export const main = {
|
|
|
42
42
|
// the device key its admission proved: rotation seals to it
|
|
43
43
|
key: bytes,
|
|
44
44
|
// the chain to the identity, when a device of the member linked it here
|
|
45
|
-
proof: bytes
|
|
45
|
+
proof: bytes,
|
|
46
|
+
// the device keys of the chain its seat was verified with, 32 bytes each, back to back
|
|
47
|
+
chain: bytes
|
|
46
48
|
},
|
|
47
49
|
invite: {
|
|
48
50
|
id: required(string),
|
|
@@ -52,7 +54,10 @@ export const main = {
|
|
|
52
54
|
createdAt: int,
|
|
53
55
|
index: uint,
|
|
54
56
|
// its joins wait for a member to accept them
|
|
55
|
-
confirm: bool
|
|
57
|
+
confirm: bool,
|
|
58
|
+
// the secret behind its own address: every device that has the row opens its joins and proves
|
|
59
|
+
// their answers
|
|
60
|
+
secret: bytes
|
|
56
61
|
},
|
|
57
62
|
handle: {
|
|
58
63
|
id: required(string),
|
|
@@ -64,7 +69,15 @@ export const main = {
|
|
|
64
69
|
updatedAt: int,
|
|
65
70
|
index: uint,
|
|
66
71
|
// its rotation epochs, for a device of the identity opening it later
|
|
67
|
-
epochs: bytes
|
|
72
|
+
epochs: bytes,
|
|
73
|
+
// where the identity stands in it, none for `in`, why and by whom once it is over, and the
|
|
74
|
+
// invite it asked with
|
|
75
|
+
state: string,
|
|
76
|
+
reason: string,
|
|
77
|
+
by: string,
|
|
78
|
+
invite: string,
|
|
79
|
+
// the writer of the latest ask, the one request of the identity that stands
|
|
80
|
+
writer: string
|
|
68
81
|
},
|
|
69
82
|
file: {
|
|
70
83
|
id: required(string),
|
|
@@ -82,11 +95,15 @@ export const main = {
|
|
|
82
95
|
wrapped: required(bytes),
|
|
83
96
|
createdAt: int,
|
|
84
97
|
commit: bytes,
|
|
85
|
-
stamp: uint
|
|
98
|
+
stamp: uint,
|
|
99
|
+
// by a signer who may not remove: kept so what was written under it reads, never the key
|
|
100
|
+
aside: bool
|
|
86
101
|
},
|
|
87
|
-
// appended by the joiner's own writer core, sealed to the database's address
|
|
102
|
+
// appended by the joiner's own writer core, sealed to the database's address, or to its
|
|
103
|
+
// invite's own, which it then names
|
|
88
104
|
join: {
|
|
89
|
-
box: required(bytes)
|
|
105
|
+
box: required(bytes),
|
|
106
|
+
invite: bytes
|
|
90
107
|
},
|
|
91
108
|
accept: {
|
|
92
109
|
id: required(string),
|
|
@@ -95,7 +112,8 @@ export const main = {
|
|
|
95
112
|
proof: bytes
|
|
96
113
|
},
|
|
97
114
|
// a join from its arrival until the joiner has its keys: waiting for a member on a confirm
|
|
98
|
-
// invite, then admitted and owed its reply
|
|
115
|
+
// invite, then admitted and owed its reply, or promised and offered its keys until a device of
|
|
116
|
+
// the identity seats itself. `id` is the joiner's writer
|
|
99
117
|
request: {
|
|
100
118
|
id: required(string),
|
|
101
119
|
identity: required(bytes),
|
|
@@ -108,12 +126,28 @@ export const main = {
|
|
|
108
126
|
// what the join asks for, the invite's role; once admitted, the role granted
|
|
109
127
|
role: string,
|
|
110
128
|
// the device key the join's proof ends at
|
|
111
|
-
key: bytes
|
|
129
|
+
key: bytes,
|
|
130
|
+
// let in through an invite with an address of its own: no member until a device of the
|
|
131
|
+
// identity seats itself
|
|
132
|
+
promised: bool,
|
|
133
|
+
// the chain its join proved; once a member linked its device, the chain that link wrote, which
|
|
134
|
+
// the device's seat keeps
|
|
135
|
+
proof: bytes,
|
|
136
|
+
// a promise a member's accept made: a removal leaves it for a member to settle
|
|
137
|
+
accepted: bool
|
|
112
138
|
},
|
|
113
139
|
// a removed member comes back only through an invite minted after `index`
|
|
114
140
|
removal: {
|
|
115
141
|
id: required(string),
|
|
116
|
-
index: required(uint)
|
|
142
|
+
index: required(uint),
|
|
143
|
+
// the member whose device wrote it: herself when she left
|
|
144
|
+
by: string,
|
|
145
|
+
// what an identity's devices told of its device keys, 32 bytes each, back to back: those
|
|
146
|
+
// removed, and those that stand whatever linked them
|
|
147
|
+
removed: bytes,
|
|
148
|
+
standing: bytes,
|
|
149
|
+
// the open invites were spent when it was written
|
|
150
|
+
spent: bool
|
|
117
151
|
},
|
|
118
152
|
// this device's live view of a context: computed on read, never stored
|
|
119
153
|
status: {
|
|
@@ -123,14 +157,12 @@ export const main = {
|
|
|
123
157
|
suspended: bool,
|
|
124
158
|
// an app version this one cannot read ops from, 0 when current
|
|
125
159
|
behind: uint,
|
|
160
|
+
// the app version the context's data is at, what `supports` answers from
|
|
161
|
+
version: uint,
|
|
126
162
|
// the Bluetooth radio: 'on', 'off', 'waiting', 'unauthorized', 'unsupported', null without it
|
|
127
|
-
nearby: string
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
joining: {
|
|
131
|
-
id: required(string),
|
|
132
|
-
type: required(string),
|
|
133
|
-
invite: required(string)
|
|
163
|
+
nearby: string,
|
|
164
|
+
// this device asked for keys it lacks, and waits for them
|
|
165
|
+
owed: bool
|
|
134
166
|
},
|
|
135
167
|
// a person linked over Bluetooth, by the identity that signed their device's key, with the name
|
|
136
168
|
// and device type that device told
|
|
@@ -145,13 +177,29 @@ export const main = {
|
|
|
145
177
|
id: required(string),
|
|
146
178
|
reply: required(bytes),
|
|
147
179
|
reason: required(string),
|
|
148
|
-
expires: int
|
|
180
|
+
expires: int,
|
|
181
|
+
// the invite it joined with, whose secret proves the answer
|
|
182
|
+
invite: string,
|
|
183
|
+
// turned away by a spent invite, which keeps one: its next join takes this one's place
|
|
184
|
+
spent: bool,
|
|
185
|
+
// who joined, turned away as removed by a live invite, which keeps one for each of them
|
|
186
|
+
identity: bytes
|
|
149
187
|
},
|
|
150
188
|
// an invite spent or revoked, kept until it expires so a join with it hears why
|
|
151
189
|
spent: {
|
|
152
190
|
id: required(string),
|
|
153
191
|
reason: required(string),
|
|
154
|
-
expires: int
|
|
192
|
+
expires: int,
|
|
193
|
+
// kept from its invite, so a join with it is still opened and answered
|
|
194
|
+
secret: bytes,
|
|
195
|
+
// its invite waited for an accept: a promise made under it is one a member let in
|
|
196
|
+
confirm: bool
|
|
197
|
+
},
|
|
198
|
+
// a device that asked for the keys it lacks, until its own op closes it. `id` is its writer
|
|
199
|
+
owed: {
|
|
200
|
+
id: required(string),
|
|
201
|
+
// the address its keys are sent to
|
|
202
|
+
reply: required(bytes)
|
|
155
203
|
},
|
|
156
204
|
deny: {
|
|
157
205
|
id: required(string),
|
|
@@ -163,6 +211,17 @@ export const main = {
|
|
|
163
211
|
handle: required(string),
|
|
164
212
|
type: required(string),
|
|
165
213
|
name: string
|
|
214
|
+
},
|
|
215
|
+
// an owner raises the database's version to this; a lower one changes nothing
|
|
216
|
+
upgrade: {
|
|
217
|
+
version: required(uint)
|
|
218
|
+
},
|
|
219
|
+
// a device tells the room of its identity's device keys, 32 bytes each, back to back: those
|
|
220
|
+
// removed, and those that stand. One with no row there signs `proof` over its core
|
|
221
|
+
revoke: {
|
|
222
|
+
removed: bytes,
|
|
223
|
+
standing: bytes,
|
|
224
|
+
proof: bytes
|
|
166
225
|
}
|
|
167
226
|
}
|
|
168
227
|
|
|
@@ -188,7 +247,17 @@ export const local = {
|
|
|
188
247
|
id: required(string),
|
|
189
248
|
publicKey: required(bytes),
|
|
190
249
|
secretKey: required(bytes),
|
|
191
|
-
encryptionKey: bytes
|
|
250
|
+
encryptionKey: bytes,
|
|
251
|
+
// the invite this writer asks with, while its join is this device's to carry
|
|
252
|
+
invite: string,
|
|
253
|
+
// when an open last took it: the closed rooms are told the most recently used first
|
|
254
|
+
used: int,
|
|
255
|
+
// a digest of the device keys last told to the room, removed and standing
|
|
256
|
+
told: bytes,
|
|
257
|
+
// the extensions' stamp last told to the room
|
|
258
|
+
stamp: bytes,
|
|
259
|
+
// the device keys the room waits to be told, once its wait for a peer was reported
|
|
260
|
+
waited: bytes
|
|
192
261
|
},
|
|
193
262
|
// a handle with invites, reopened at boot so its joins are answered
|
|
194
263
|
serving: {
|
|
@@ -211,24 +280,29 @@ export const local = {
|
|
|
211
280
|
device: bytes,
|
|
212
281
|
proof: bytes
|
|
213
282
|
},
|
|
214
|
-
// mail the device's mailbox keeps: received until handled, sent until
|
|
283
|
+
// mail the device's mailbox keeps: received until handled, sent until stored. `mirrors` are
|
|
215
284
|
// 32-byte keys back to back
|
|
216
285
|
mail: {
|
|
217
286
|
id: required(string),
|
|
218
287
|
address: required(bytes),
|
|
219
288
|
message: required(bytes),
|
|
220
289
|
mirrors: bytes,
|
|
221
|
-
// sent: the core it travels in, and whether it goes once
|
|
290
|
+
// sent: the core it travels in, and whether it goes once it is stored
|
|
222
291
|
name: string,
|
|
223
292
|
erase: bool,
|
|
224
293
|
// received: the inbox fetched the core, so it may erase it once handled
|
|
225
|
-
fetched: bool
|
|
294
|
+
fetched: bool,
|
|
295
|
+
// received and handled, when: the row stays so a mirror announcing it again is ignored
|
|
296
|
+
handled: uint,
|
|
297
|
+
// sent: the message is sealed to the address; absent, it is in the clear and sealed to go out
|
|
298
|
+
sealed: bool
|
|
226
299
|
},
|
|
227
300
|
environment: {
|
|
228
301
|
channel: required(string)
|
|
229
302
|
},
|
|
230
303
|
// the handles rows a cold push process can read without the root: topic → handle, its keys and
|
|
231
|
-
// the epochs it learned, so a push's block opens there too
|
|
304
|
+
// the epochs it learned, so a push's block opens there too. `writers`, 32-byte keys back to back,
|
|
305
|
+
// are who may write to it as this device last had it open: a push from any other core is refused
|
|
232
306
|
subscription: {
|
|
233
307
|
id: required(string),
|
|
234
308
|
handle: required(string),
|
|
@@ -236,13 +310,32 @@ export const local = {
|
|
|
236
310
|
key: required(bytes),
|
|
237
311
|
name: string,
|
|
238
312
|
encryptionKey: bytes,
|
|
239
|
-
epochs: bytes
|
|
313
|
+
epochs: bytes,
|
|
314
|
+
writers: bytes
|
|
315
|
+
},
|
|
316
|
+
// the root's device lists, 32-byte keys back to back, and a digest of the extensions' stamp and
|
|
317
|
+
// the build, last told to the rooms: a launch with the same opens none of them
|
|
318
|
+
told: {
|
|
319
|
+
removed: bytes,
|
|
320
|
+
standing: bytes,
|
|
321
|
+
stamp: bytes
|
|
322
|
+
},
|
|
323
|
+
// a request this device's writer made: it stays until its row says how it ended, or the room
|
|
324
|
+
// holds it taken back
|
|
325
|
+
ask: {
|
|
326
|
+
id: required(string),
|
|
327
|
+
handle: required(string),
|
|
328
|
+
type: required(string),
|
|
329
|
+
invite: required(string),
|
|
330
|
+
publicKey: required(bytes),
|
|
331
|
+
secretKey: required(bytes),
|
|
332
|
+
createdAt: int
|
|
240
333
|
}
|
|
241
334
|
}
|
|
242
335
|
|
|
243
336
|
// what a write means to apply. A release that changes it without changing what is stored bumps
|
|
244
337
|
// this, so an app's next build raises its contract and devices on the old release skip the new writes
|
|
245
|
-
export const contract = { version:
|
|
338
|
+
export const contract = { version: 4 }
|
|
246
339
|
|
|
247
340
|
export const rpc = {
|
|
248
341
|
'req-empty': {
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { can, WRITE } from '@cero-base/core/utils'
|
|
2
|
+
|
|
1
3
|
import { t } from '../lib/spec.js'
|
|
2
4
|
import { get, watch } from '../lib/operators.js'
|
|
3
5
|
import { mirror } from './mirror.js'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
* Mirror your `profile` onto your `member` row in every handle you're in.
|
|
8
|
+
* Mirror your `profile` onto your `member` row in every handle you're in, open or closed here.
|
|
7
9
|
*
|
|
8
10
|
* @param {{ fields?: Record<string, object> }} [opts] Extra fields, as `t` types.
|
|
9
11
|
* @returns {import('./index.js').Extension}
|
|
10
12
|
*/
|
|
11
13
|
export function profileSync({ fields = { avatar: t.string } } = {}) {
|
|
14
|
+
const keys = ['name', ...Object.keys(fields)]
|
|
12
15
|
return {
|
|
13
16
|
name: 'profile-sync',
|
|
14
17
|
schema: {
|
|
@@ -18,6 +21,9 @@ export function profileSync({ fields = { avatar: t.string } } = {}) {
|
|
|
18
21
|
setup(me) {
|
|
19
22
|
const publish = async (child, profile) => {
|
|
20
23
|
try {
|
|
24
|
+
// a reader's row takes it in a room at the version where every release reads it alike
|
|
25
|
+
const { data: row } = await get(child.members, me.identity.id)
|
|
26
|
+
if (row && !can(row.role, WRITE) && !(await child.store._seatless())) return
|
|
21
27
|
await mirror(me.profile, profile, fields, child.members, me.identity.id)
|
|
22
28
|
} catch (err) {
|
|
23
29
|
// a handle that closed meanwhile has no member row left to update
|
|
@@ -33,6 +39,15 @@ export function profileSync({ fields = { avatar: t.string } } = {}) {
|
|
|
33
39
|
const onchild = (child) => onHandle(child).catch(me._onerror)
|
|
34
40
|
me.on('handle', onchild)
|
|
35
41
|
|
|
42
|
+
// the rooms closed here hear of a change through the root's pass over them
|
|
43
|
+
me._tellers.push({
|
|
44
|
+
async stamp() {
|
|
45
|
+
const { data } = await get(me.profile)
|
|
46
|
+
return data ? JSON.stringify(keys.map((k) => data[k]?.id ?? data[k] ?? null)) : null
|
|
47
|
+
},
|
|
48
|
+
tell: onHandle
|
|
49
|
+
})
|
|
50
|
+
|
|
36
51
|
// a local edit and one replicated from another device both land here
|
|
37
52
|
const stream = watch(me.profile, { changes: true }, { signal: me.signal })
|
|
38
53
|
stream.on('error', me._onerror)
|
|
@@ -40,6 +55,7 @@ export function profileSync({ fields = { avatar: t.string } } = {}) {
|
|
|
40
55
|
for (const { next } of batch) {
|
|
41
56
|
if (next) me.children.forEach((child) => publish(child, next).catch(me._onerror))
|
|
42
57
|
}
|
|
58
|
+
if (batch.length) me._tellClosed()
|
|
43
59
|
})
|
|
44
60
|
return () => me.off('handle', onchild)
|
|
45
61
|
}
|