@openlfcp/client 0.1.2 → 0.1.3
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 +1 -1
- package/dist/apply.d.ts +319 -0
- package/dist/apply.js +807 -0
- package/dist/checkpoint.d.ts +31 -0
- package/dist/checkpoint.js +50 -0
- package/dist/connection.d.ts +87 -0
- package/dist/connection.js +210 -0
- package/dist/data-unit.d.ts +50 -0
- package/dist/data-unit.js +39 -0
- package/dist/engine-guard.d.ts +58 -0
- package/dist/engine-guard.js +148 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +15 -0
- package/dist/invite.d.ts +174 -0
- package/dist/invite.js +402 -0
- package/dist/outbound.d.ts +245 -0
- package/dist/outbound.js +607 -0
- package/dist/queue.d.ts +38 -0
- package/dist/queue.js +116 -0
- package/dist/resource-state.d.ts +34 -0
- package/dist/resource-state.js +24 -0
- package/dist/snapshot.d.ts +42 -0
- package/dist/snapshot.js +40 -0
- package/dist/storage.d.ts +96 -0
- package/dist/storage.js +289 -0
- package/dist/sync-client.d.ts +258 -0
- package/dist/sync-client.js +1401 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Part of the OpenLFCP TypeScript SDK, which implements the OpenLFCP MVP 0.1
|
|
|
14
14
|
subset of [LFCP-WIRE-01](https://github.com/openlfcp/spec/blob/main/wire/LFCP-WIRE-01.md)
|
|
15
15
|
at `mvp-0.1-baseline.9`, not every deferred WIRE-01 feature. It does not
|
|
16
16
|
claim full LFCP-WIRE-01 conformance. This is the MVP 0.1 release
|
|
17
|
-
(`0.1.
|
|
17
|
+
(`0.1.3`, npm dist-tag `latest`). Until 1.0, minor versions may change APIs.
|
|
18
18
|
|
|
19
19
|
## Links
|
|
20
20
|
|
package/dist/apply.d.ts
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { type ActorSequence, type DataEpoch, type DataUnitId, type PrincipalId, type ResourceId } from "@openlfcp/core";
|
|
2
|
+
import { type ResourceDEK } from "@openlfcp/crypto";
|
|
3
|
+
import type { LfcpStorage } from "@openlfcp/storage";
|
|
4
|
+
import { type ControlView, type DataProfileCodec, type DataUnitCheckOptions, type DataUnitEquivocation, type DataUnitQuarantined, type ReceivedDataUnit } from "@openlfcp/wire";
|
|
5
|
+
/**
|
|
6
|
+
* Applying received Data Units to the Resource's Data Profile (LFCP-033).
|
|
7
|
+
*
|
|
8
|
+
* This is where LFCP security ends and application semantics begin. The
|
|
9
|
+
* LFCP side is receiveDataUnit (LFCP-025), unchanged and in its order:
|
|
10
|
+
* structure → actor → signature → equivocation → referenced head →
|
|
11
|
+
* data/write at that head → epoch and cutoff → DEK → AEAD → profile
|
|
12
|
+
* decode → actor hash chain (accepted or held). Only an accepted unit
|
|
13
|
+
* reaches the profile, and only once: the Data Unit ID is the idempotency
|
|
14
|
+
* boundary.
|
|
15
|
+
*
|
|
16
|
+
* The profile side is a DataProfileHandler, selected by the Resource's
|
|
17
|
+
* Genesis data_profile. The applier knows no profile: the Shared Objects
|
|
18
|
+
* handler lives in @openlfcp/shared-objects. A Resource whose profile has
|
|
19
|
+
* no handler is PROFILE_UNSUPPORTED: its units are verified without a DEK
|
|
20
|
+
* and kept, and their plaintext is never decrypted or applied.
|
|
21
|
+
*
|
|
22
|
+
* Three ways a valid unit can wait, kept apart:
|
|
23
|
+
* - held (§26.2, G-DP1): its actor chain does not link yet; retried here
|
|
24
|
+
* when the actor's previous unit is accepted;
|
|
25
|
+
* - profile-pending: LFCP-accepted, but the profile cannot merge it until
|
|
26
|
+
* other units' content arrives (Automerge dependencies); the handler
|
|
27
|
+
* buffers it and merges it when they do;
|
|
28
|
+
* - quarantined (STALE_DATA_EPOCH): never merged automatically.
|
|
29
|
+
*
|
|
30
|
+
* Crash-loop breaker (EngineGuard): every engine call on received units
|
|
31
|
+
* (decode and apply, also when replaying) runs with a durable record of
|
|
32
|
+
* the units it covers. After a crash those units are suspects, received
|
|
33
|
+
* and replayed alone; a unit that crashes the engine again by itself is
|
|
34
|
+
* quarantined locally (status local-failure, INVALID_AUTOMERGE_BYTES) and
|
|
35
|
+
* never given to the engine again. Exclusion and rebuild (G-EP7) work on
|
|
36
|
+
* units already merged once and are not guarded.
|
|
37
|
+
*/
|
|
38
|
+
/** An LFCP-accepted unit as the profile sees it. */
|
|
39
|
+
export interface ProfileUnit {
|
|
40
|
+
readonly unitId: DataUnitId;
|
|
41
|
+
readonly resourceId: ResourceId;
|
|
42
|
+
readonly actor: PrincipalId;
|
|
43
|
+
readonly seq: ActorSequence;
|
|
44
|
+
readonly epoch: DataEpoch;
|
|
45
|
+
}
|
|
46
|
+
/** A profile-level finding about the state after a merge (e.g. a PROFILE_INVALID object). */
|
|
47
|
+
export interface ProfileDiagnostic {
|
|
48
|
+
readonly objectId?: string;
|
|
49
|
+
readonly code: string;
|
|
50
|
+
readonly diagnostic?: string;
|
|
51
|
+
readonly pointer?: string;
|
|
52
|
+
readonly message: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ProfileApplyResult {
|
|
55
|
+
/** Units merged by this call: the unit itself when it merged now, and buffered units it unblocked. */
|
|
56
|
+
readonly merged: readonly DataUnitId[];
|
|
57
|
+
/** Objects whose state changed. */
|
|
58
|
+
readonly objects: readonly string[];
|
|
59
|
+
/** Findings about the merged state; they never undo the merge (profile §77 isolation). */
|
|
60
|
+
readonly diagnostics: readonly ProfileDiagnostic[];
|
|
61
|
+
/** Why the unit is buffered by the profile when it did not merge now. */
|
|
62
|
+
readonly pending?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Why the profile holds the unit (SHARED-OBJECTS-PROFILE-01 §14.1): a
|
|
65
|
+
* different change has its actor and sequence number. Never merged until
|
|
66
|
+
* a rebuild frees them.
|
|
67
|
+
*/
|
|
68
|
+
readonly held?: string;
|
|
69
|
+
}
|
|
70
|
+
/** What a handler's applyBatch reports: per unit merged, pending or rejected, and the objects once. */
|
|
71
|
+
export interface ProfileBatchResult {
|
|
72
|
+
/** Units merged now: the batch's and buffered units it unblocked. */
|
|
73
|
+
readonly merged: readonly DataUnitId[];
|
|
74
|
+
/** Units buffered by the profile (the batch's, and earlier ones still waiting). */
|
|
75
|
+
readonly pending: readonly DataUnitId[];
|
|
76
|
+
/** Units the profile holds (§14.1): a different change has their actor and sequence number. */
|
|
77
|
+
readonly held?: readonly DataUnitId[];
|
|
78
|
+
/** Units the profile refused, with the code and message apply would have thrown. */
|
|
79
|
+
readonly rejected: readonly {
|
|
80
|
+
readonly unitId: DataUnitId;
|
|
81
|
+
readonly code: string;
|
|
82
|
+
readonly message: string;
|
|
83
|
+
}[];
|
|
84
|
+
readonly objects: readonly string[];
|
|
85
|
+
readonly diagnostics: readonly ProfileDiagnostic[];
|
|
86
|
+
}
|
|
87
|
+
export interface ProfileExcludeResult {
|
|
88
|
+
/** Objects whose state changed. */
|
|
89
|
+
readonly objects: readonly string[];
|
|
90
|
+
/** Merged units that now wait for an excluded unit's content (profile-pending). */
|
|
91
|
+
readonly pending: readonly DataUnitId[];
|
|
92
|
+
/** Held units (§14.1) that merged after the rebuild freed their actor sequence. */
|
|
93
|
+
readonly released?: readonly DataUnitId[];
|
|
94
|
+
}
|
|
95
|
+
/** The application side of one Data Profile. Implemented by profile packages. */
|
|
96
|
+
export interface DataProfileHandler<T> {
|
|
97
|
+
/** The Genesis data_profile it implements (§15, §27). */
|
|
98
|
+
readonly dataProfile: string;
|
|
99
|
+
/**
|
|
100
|
+
* The codec for one unit's plaintext. The unit's Resource and signing
|
|
101
|
+
* actor are known before its plaintext is decoded, so the codec can bind
|
|
102
|
+
* the content to them; decode throws to reject (local-failure, never
|
|
103
|
+
* merged, never marked accepted).
|
|
104
|
+
*/
|
|
105
|
+
codecFor(unit: {
|
|
106
|
+
readonly resourceId: ResourceId;
|
|
107
|
+
readonly actor: PrincipalId;
|
|
108
|
+
}): DataProfileCodec<T>;
|
|
109
|
+
/** Merges one accepted unit's decoded value. Throws when the profile refuses it. */
|
|
110
|
+
apply(unit: ProfileUnit, value: T): ProfileApplyResult;
|
|
111
|
+
/**
|
|
112
|
+
* Merges many accepted units at once, as apply would one by one (a
|
|
113
|
+
* refusal rejects only its unit). Optional: with it, receiveBatch and
|
|
114
|
+
* replayStored hand the profile a whole catch-up at once, which an engine
|
|
115
|
+
* such as Automerge applies far faster than unit by unit.
|
|
116
|
+
*/
|
|
117
|
+
applyBatch?(units: readonly {
|
|
118
|
+
readonly unit: ProfileUnit;
|
|
119
|
+
readonly value: T;
|
|
120
|
+
}[]): ProfileBatchResult;
|
|
121
|
+
/**
|
|
122
|
+
* LFCP-WIRE-01 §19.1 (G-EP7): takes merged or buffered units out again, so that
|
|
123
|
+
* the state equals the state built from the remaining accepted units.
|
|
124
|
+
*/
|
|
125
|
+
exclude(unitIds: readonly DataUnitId[]): ProfileExcludeResult;
|
|
126
|
+
/**
|
|
127
|
+
* Whether the profile state holds this unit's content. With it, units
|
|
128
|
+
* merged after the last persisted checkpoint can be replayed from storage
|
|
129
|
+
* after a restart (DataUnitApplier.replayStored).
|
|
130
|
+
*/
|
|
131
|
+
has?(unitId: DataUnitId): boolean;
|
|
132
|
+
/** Forgets the whole profile state, to rebuild it from accepted units (SNAP-EP). */
|
|
133
|
+
reset?(): void;
|
|
134
|
+
}
|
|
135
|
+
interface Applied {
|
|
136
|
+
readonly unitId: DataUnitId;
|
|
137
|
+
readonly dataProfile: string;
|
|
138
|
+
readonly actor: PrincipalId;
|
|
139
|
+
readonly seq: ActorSequence;
|
|
140
|
+
readonly epoch: DataEpoch;
|
|
141
|
+
/**
|
|
142
|
+
* Whether the unit may be advertised in Haves. Always false here: a unit
|
|
143
|
+
* is advertised only once the sync layer knows its storage is durable
|
|
144
|
+
* (LFCP-036).
|
|
145
|
+
*/
|
|
146
|
+
readonly haveEligible: false;
|
|
147
|
+
/** Buffered units this one unblocked, merged now. */
|
|
148
|
+
readonly alsoMerged: readonly DataUnitId[];
|
|
149
|
+
/** Held units of the same actor that were retried after this one, with their outcomes. */
|
|
150
|
+
readonly released: readonly ApplyOutcome[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Two or more signature-valid units for one (resource, actor, seq).
|
|
154
|
+
* LFCP-WIRE-01 §26.2 (G-DP5): no unit of the set stays merged, since keeping the
|
|
155
|
+
* first one would choose by arrival order (§26.2 forbids choosing). Every
|
|
156
|
+
* unit is marked "equivocation" and un-accepted; merged ones were taken out
|
|
157
|
+
* of the profile state.
|
|
158
|
+
*/
|
|
159
|
+
export type EquivocationOutcome = DataUnitEquivocation & {
|
|
160
|
+
/** Units of the set that were merged and are now excluded from the profile state. */
|
|
161
|
+
readonly excluded: readonly DataUnitId[];
|
|
162
|
+
/** Objects whose state changed through the exclusion. */
|
|
163
|
+
readonly objects: readonly string[];
|
|
164
|
+
/** Merged units that now wait in the profile for an excluded unit's content. */
|
|
165
|
+
readonly pending: readonly DataUnitId[];
|
|
166
|
+
/** Held units of the actor retried after the exclusion (§26.2, G-DP1-GAP). */
|
|
167
|
+
readonly released: readonly ApplyOutcome[];
|
|
168
|
+
};
|
|
169
|
+
/** The outcome of one received Data Unit. */
|
|
170
|
+
export type ApplyOutcome =
|
|
171
|
+
/** Accepted by LFCP and merged into the profile state. */
|
|
172
|
+
(Applied & {
|
|
173
|
+
readonly kind: "applied";
|
|
174
|
+
readonly objects: readonly string[];
|
|
175
|
+
readonly diagnostics: readonly ProfileDiagnostic[];
|
|
176
|
+
})
|
|
177
|
+
/** Accepted by LFCP; the profile buffers it until the content it builds on arrives. */
|
|
178
|
+
| (Applied & {
|
|
179
|
+
readonly kind: "profile-pending";
|
|
180
|
+
readonly detail: string;
|
|
181
|
+
})
|
|
182
|
+
/**
|
|
183
|
+
* Accepted by LFCP and kept (a holding: advertised and relayed); the
|
|
184
|
+
* profile holds it because a different change has its actor and sequence
|
|
185
|
+
* number (SHARED-OBJECTS-PROFILE-01 §14.1, POST-001). It is retried after
|
|
186
|
+
* every rebuild that removes changes, and reported as applied then.
|
|
187
|
+
*/
|
|
188
|
+
| (Applied & {
|
|
189
|
+
readonly kind: "profile-held";
|
|
190
|
+
readonly detail: string;
|
|
191
|
+
})
|
|
192
|
+
/** Accepted by LFCP, refused by the profile when merging: never merged. */
|
|
193
|
+
| {
|
|
194
|
+
readonly kind: "profile-rejected";
|
|
195
|
+
readonly unitId: DataUnitId;
|
|
196
|
+
readonly dataProfile: string;
|
|
197
|
+
readonly code: string;
|
|
198
|
+
readonly message: string;
|
|
199
|
+
}
|
|
200
|
+
/** The Resource's Data Profile has no handler (§62 PROFILE_UNSUPPORTED): verified and kept, never decrypted. */
|
|
201
|
+
| {
|
|
202
|
+
readonly kind: "profile-unsupported";
|
|
203
|
+
readonly code: "PROFILE_UNSUPPORTED";
|
|
204
|
+
readonly unitId: DataUnitId;
|
|
205
|
+
readonly dataProfile: string;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A unit whose content a loaded Snapshot already holds: verified without
|
|
209
|
+
* a DEK and accepted, never decrypted or merged again (acceptCovered).
|
|
210
|
+
*/
|
|
211
|
+
| {
|
|
212
|
+
readonly kind: "covered";
|
|
213
|
+
readonly unitId: DataUnitId;
|
|
214
|
+
readonly dataProfile: string;
|
|
215
|
+
/** Held units of the same actor that were retried after this one, with their outcomes. */
|
|
216
|
+
readonly released: readonly ApplyOutcome[];
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The unit crashed the profile engine twice by itself (EngineGuard): it
|
|
220
|
+
* is quarantined on this device and never applied again. Local only: no
|
|
221
|
+
* wire code; the unit may be valid elsewhere.
|
|
222
|
+
*/
|
|
223
|
+
| {
|
|
224
|
+
readonly kind: "engine-crash";
|
|
225
|
+
readonly code: "INVALID_AUTOMERGE_BYTES";
|
|
226
|
+
readonly unitId: DataUnitId;
|
|
227
|
+
readonly message: string;
|
|
228
|
+
} | EquivocationOutcome | Exclude<ReceivedDataUnit<unknown>, {
|
|
229
|
+
readonly kind: "accepted" | "equivocation";
|
|
230
|
+
}>;
|
|
231
|
+
/** A merged unit that a newly known Key Epoch puts beyond its cutoff (G-EP7). */
|
|
232
|
+
export interface ExcludedUnit {
|
|
233
|
+
readonly unitId: DataUnitId;
|
|
234
|
+
readonly quarantine: Omit<DataUnitQuarantined, "kind" | "unitId">;
|
|
235
|
+
}
|
|
236
|
+
export interface EpochReconciliation {
|
|
237
|
+
/** Units taken out of the profile state and now quarantined. */
|
|
238
|
+
readonly excluded: readonly ExcludedUnit[];
|
|
239
|
+
/** Objects whose state changed. */
|
|
240
|
+
readonly objects: readonly string[];
|
|
241
|
+
/** Merged units that now wait in the profile for an excluded unit's content. */
|
|
242
|
+
readonly pending: readonly DataUnitId[];
|
|
243
|
+
/**
|
|
244
|
+
* The Key Epoch cut off units a loaded Snapshot covered: the Snapshot
|
|
245
|
+
* state was dropped and rebuilt from accepted units (SNAP-EP); the units
|
|
246
|
+
* it covered must be fetched again.
|
|
247
|
+
*/
|
|
248
|
+
readonly snapshotDropped: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Held units retried once the excluded units stopped being their actors'
|
|
251
|
+
* latest accepted ones (§26.2, G-DP1-GAP), with their outcomes.
|
|
252
|
+
*/
|
|
253
|
+
readonly released: readonly ApplyOutcome[];
|
|
254
|
+
}
|
|
255
|
+
export interface DataUnitApplierOptions extends DataUnitCheckOptions {
|
|
256
|
+
/**
|
|
257
|
+
* Where verified units, their exact bytes, statuses and the accepted
|
|
258
|
+
* marks live (the wire SeenUnits runs on it). InMemoryLfcpStorage for
|
|
259
|
+
* tests and development only.
|
|
260
|
+
*/
|
|
261
|
+
readonly storage: Pick<LfcpStorage, "dataUnits" | "snapshots" | "commit" | "localMarks">;
|
|
262
|
+
/** The DEK of a Data Epoch, if this client holds it (e.g. dekResolver). */
|
|
263
|
+
readonly dek: (epoch: DataEpoch) => ResourceDEK | undefined | Promise<ResourceDEK | undefined>;
|
|
264
|
+
/** The profiles this client implements. */
|
|
265
|
+
readonly handlers: readonly DataProfileHandler<unknown>[];
|
|
266
|
+
}
|
|
267
|
+
export declare class DataUnitApplier {
|
|
268
|
+
#private;
|
|
269
|
+
constructor(options: DataUnitApplierOptions);
|
|
270
|
+
/**
|
|
271
|
+
* Receives one Data Unit of the Resource `view` describes. Never creates
|
|
272
|
+
* a Data Unit: received content is applied, not re-sent as local work.
|
|
273
|
+
*/
|
|
274
|
+
receive(view: ControlView, bytes: Uint8Array): Promise<ApplyOutcome>;
|
|
275
|
+
/**
|
|
276
|
+
* Receives the units of one DATA_BATCH (or any run of units) of the
|
|
277
|
+
* Resource `view` describes: each passes the LFCP checks of receive in
|
|
278
|
+
* order, unchanged, and the accepted ones reach the profile together
|
|
279
|
+
* through the handler's applyBatch, when it has one. Outcomes come in the
|
|
280
|
+
* order of `units`. An applied unit's objects and diagnostics are those
|
|
281
|
+
* of the whole batch, reported on the last unit merged; the units
|
|
282
|
+
* buffered before that the batch unblocked count as merged by the first.
|
|
283
|
+
* Before an equivocation is handled, the units accepted so far are
|
|
284
|
+
* applied, so its exclusion sees them.
|
|
285
|
+
*/
|
|
286
|
+
receiveBatch(view: ControlView, units: readonly Uint8Array[]): Promise<ApplyOutcome[]>;
|
|
287
|
+
/**
|
|
288
|
+
* After a restart: the stored, LFCP-accepted units (merged or buffered by
|
|
289
|
+
* the profile) whose content the restored profile state does not hold
|
|
290
|
+
* (merged after its last checkpoint), decrypted again from their exact
|
|
291
|
+
* stored bytes and applied, in (actor, seq) order. Units covered by a
|
|
292
|
+
* Snapshot are not replayed (their content came with it). Needs the
|
|
293
|
+
* handler's has(); returns what was replayed and what could not be (no
|
|
294
|
+
* DEK, refused). LFCP checks are not repeated: the units passed them when
|
|
295
|
+
* they were accepted.
|
|
296
|
+
*/
|
|
297
|
+
replayStored(view: ControlView): Promise<{
|
|
298
|
+
readonly replayed: readonly DataUnitId[];
|
|
299
|
+
readonly skipped: readonly {
|
|
300
|
+
readonly unitId: DataUnitId;
|
|
301
|
+
readonly reason: string;
|
|
302
|
+
}[];
|
|
303
|
+
/** Units quarantined at this start: they crashed the engine twice by themselves. */
|
|
304
|
+
readonly crashed: readonly DataUnitId[];
|
|
305
|
+
}>;
|
|
306
|
+
/**
|
|
307
|
+
* A unit inside the frontier of a Snapshot this client loaded (§29, §66
|
|
308
|
+
* step 3): its content is in the Snapshot, so it is not decrypted or
|
|
309
|
+
* merged again. It gets the DEK-free LFCP checks (structure, signature,
|
|
310
|
+
* equivocation, data/write at its head, epoch cutoff) and is then marked
|
|
311
|
+
* accepted, so the actor's next unit links to it (§26.2). Its own link to
|
|
312
|
+
* the previous unit is not checked: that unit is attested by the signed,
|
|
313
|
+
* authorized Snapshot and was never received. A replay is a duplicate.
|
|
314
|
+
*/
|
|
315
|
+
acceptCovered(view: ControlView, bytes: Uint8Array): Promise<ApplyOutcome>;
|
|
316
|
+
reconcileEpochs(view: ControlView): Promise<EpochReconciliation>;
|
|
317
|
+
}
|
|
318
|
+
export {};
|
|
319
|
+
//# sourceMappingURL=apply.d.ts.map
|