@openlfcp/client 0.1.1 → 0.1.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/README.md CHANGED
@@ -12,9 +12,9 @@ ESM only; Node.js 24 or later (browsers and Electron for every package except `@
12
12
 
13
13
  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
- at `mvp-0.1-baseline.8`, not every deferred WIRE-01 feature. It does not
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.1`, npm dist-tag `latest`). Until 1.0, minor versions may change APIs.
17
+ (`0.1.2`, npm dist-tag `latest`). Until 1.0, minor versions may change APIs.
18
18
 
19
19
  ## Links
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openlfcp/client",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "LFCP client: session, Control Plane and Data Plane synchronization.",
5
5
  "keywords": [
6
6
  "openlfcp",
@@ -42,9 +42,9 @@
42
42
  "tag": "latest"
43
43
  },
44
44
  "dependencies": {
45
- "@openlfcp/core": "^0.1.1",
46
- "@openlfcp/storage": "^0.1.1",
47
- "@openlfcp/crypto": "^0.1.1",
48
- "@openlfcp/wire": "^0.1.1"
45
+ "@openlfcp/core": "^0.1.2",
46
+ "@openlfcp/crypto": "^0.1.2",
47
+ "@openlfcp/storage": "^0.1.2",
48
+ "@openlfcp/wire": "^0.1.2"
49
49
  }
50
50
  }
package/dist/apply.d.ts DELETED
@@ -1,299 +0,0 @@
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
- /** What a handler's applyBatch reports: per unit merged, pending or rejected, and the objects once. */
65
- export interface ProfileBatchResult {
66
- /** Units merged now: the batch's and buffered units it unblocked. */
67
- readonly merged: readonly DataUnitId[];
68
- /** Units buffered by the profile (the batch's, and earlier ones still waiting). */
69
- readonly pending: readonly DataUnitId[];
70
- /** Units the profile refused, with the code and message apply would have thrown. */
71
- readonly rejected: readonly {
72
- readonly unitId: DataUnitId;
73
- readonly code: string;
74
- readonly message: string;
75
- }[];
76
- readonly objects: readonly string[];
77
- readonly diagnostics: readonly ProfileDiagnostic[];
78
- }
79
- export interface ProfileExcludeResult {
80
- /** Objects whose state changed. */
81
- readonly objects: readonly string[];
82
- /** Merged units that now wait for an excluded unit's content (profile-pending). */
83
- readonly pending: readonly DataUnitId[];
84
- }
85
- /** The application side of one Data Profile. Implemented by profile packages. */
86
- export interface DataProfileHandler<T> {
87
- /** The Genesis data_profile it implements (§15, §27). */
88
- readonly dataProfile: string;
89
- /**
90
- * The codec for one unit's plaintext. The unit's Resource and signing
91
- * actor are known before its plaintext is decoded, so the codec can bind
92
- * the content to them; decode throws to reject (local-failure, never
93
- * merged, never marked accepted).
94
- */
95
- codecFor(unit: {
96
- readonly resourceId: ResourceId;
97
- readonly actor: PrincipalId;
98
- }): DataProfileCodec<T>;
99
- /** Merges one accepted unit's decoded value. Throws when the profile refuses it. */
100
- apply(unit: ProfileUnit, value: T): ProfileApplyResult;
101
- /**
102
- * Merges many accepted units at once, as apply would one by one (a
103
- * refusal rejects only its unit). Optional: with it, receiveBatch and
104
- * replayStored hand the profile a whole catch-up at once, which an engine
105
- * such as Automerge applies far faster than unit by unit.
106
- */
107
- applyBatch?(units: readonly {
108
- readonly unit: ProfileUnit;
109
- readonly value: T;
110
- }[]): ProfileBatchResult;
111
- /**
112
- * LFCP-WIRE-01 §19.1 (G-EP7): takes merged or buffered units out again, so that
113
- * the state equals the state built from the remaining accepted units.
114
- */
115
- exclude(unitIds: readonly DataUnitId[]): ProfileExcludeResult;
116
- /**
117
- * Whether the profile state holds this unit's content. With it, units
118
- * merged after the last persisted checkpoint can be replayed from storage
119
- * after a restart (DataUnitApplier.replayStored).
120
- */
121
- has?(unitId: DataUnitId): boolean;
122
- /** Forgets the whole profile state, to rebuild it from accepted units (SNAP-EP). */
123
- reset?(): void;
124
- }
125
- interface Applied {
126
- readonly unitId: DataUnitId;
127
- readonly dataProfile: string;
128
- readonly actor: PrincipalId;
129
- readonly seq: ActorSequence;
130
- readonly epoch: DataEpoch;
131
- /**
132
- * Whether the unit may be advertised in Haves. Always false here: a unit
133
- * is advertised only once the sync layer knows its storage is durable
134
- * (LFCP-036).
135
- */
136
- readonly haveEligible: false;
137
- /** Buffered units this one unblocked, merged now. */
138
- readonly alsoMerged: readonly DataUnitId[];
139
- /** Held units of the same actor that were retried after this one, with their outcomes. */
140
- readonly released: readonly ApplyOutcome[];
141
- }
142
- /**
143
- * Two or more signature-valid units for one (resource, actor, seq).
144
- * LFCP-WIRE-01 §26.2 (G-DP5): no unit of the set stays merged, since keeping the
145
- * first one would choose by arrival order (§26.2 forbids choosing). Every
146
- * unit is marked "equivocation" and un-accepted; merged ones were taken out
147
- * of the profile state.
148
- */
149
- export type EquivocationOutcome = DataUnitEquivocation & {
150
- /** Units of the set that were merged and are now excluded from the profile state. */
151
- readonly excluded: readonly DataUnitId[];
152
- /** Objects whose state changed through the exclusion. */
153
- readonly objects: readonly string[];
154
- /** Merged units that now wait in the profile for an excluded unit's content. */
155
- readonly pending: readonly DataUnitId[];
156
- /** Held units of the actor retried after the exclusion (§26.2, G-DP1-GAP). */
157
- readonly released: readonly ApplyOutcome[];
158
- };
159
- /** The outcome of one received Data Unit. */
160
- export type ApplyOutcome =
161
- /** Accepted by LFCP and merged into the profile state. */
162
- (Applied & {
163
- readonly kind: "applied";
164
- readonly objects: readonly string[];
165
- readonly diagnostics: readonly ProfileDiagnostic[];
166
- })
167
- /** Accepted by LFCP; the profile buffers it until the content it builds on arrives. */
168
- | (Applied & {
169
- readonly kind: "profile-pending";
170
- readonly detail: string;
171
- })
172
- /** Accepted by LFCP, refused by the profile when merging: never merged. */
173
- | {
174
- readonly kind: "profile-rejected";
175
- readonly unitId: DataUnitId;
176
- readonly dataProfile: string;
177
- readonly code: string;
178
- readonly message: string;
179
- }
180
- /** The Resource's Data Profile has no handler (§62 PROFILE_UNSUPPORTED): verified and kept, never decrypted. */
181
- | {
182
- readonly kind: "profile-unsupported";
183
- readonly code: "PROFILE_UNSUPPORTED";
184
- readonly unitId: DataUnitId;
185
- readonly dataProfile: string;
186
- }
187
- /**
188
- * A unit whose content a loaded Snapshot already holds: verified without
189
- * a DEK and accepted, never decrypted or merged again (acceptCovered).
190
- */
191
- | {
192
- readonly kind: "covered";
193
- readonly unitId: DataUnitId;
194
- readonly dataProfile: string;
195
- /** Held units of the same actor that were retried after this one, with their outcomes. */
196
- readonly released: readonly ApplyOutcome[];
197
- }
198
- /**
199
- * The unit crashed the profile engine twice by itself (EngineGuard): it
200
- * is quarantined on this device and never applied again. Local only: no
201
- * wire code; the unit may be valid elsewhere.
202
- */
203
- | {
204
- readonly kind: "engine-crash";
205
- readonly code: "INVALID_AUTOMERGE_BYTES";
206
- readonly unitId: DataUnitId;
207
- readonly message: string;
208
- } | EquivocationOutcome | Exclude<ReceivedDataUnit<unknown>, {
209
- readonly kind: "accepted" | "equivocation";
210
- }>;
211
- /** A merged unit that a newly known Key Epoch puts beyond its cutoff (G-EP7). */
212
- export interface ExcludedUnit {
213
- readonly unitId: DataUnitId;
214
- readonly quarantine: Omit<DataUnitQuarantined, "kind" | "unitId">;
215
- }
216
- export interface EpochReconciliation {
217
- /** Units taken out of the profile state and now quarantined. */
218
- readonly excluded: readonly ExcludedUnit[];
219
- /** Objects whose state changed. */
220
- readonly objects: readonly string[];
221
- /** Merged units that now wait in the profile for an excluded unit's content. */
222
- readonly pending: readonly DataUnitId[];
223
- /**
224
- * The Key Epoch cut off units a loaded Snapshot covered: the Snapshot
225
- * state was dropped and rebuilt from accepted units (SNAP-EP); the units
226
- * it covered must be fetched again.
227
- */
228
- readonly snapshotDropped: boolean;
229
- /**
230
- * Held units retried once the excluded units stopped being their actors'
231
- * latest accepted ones (§26.2, G-DP1-GAP), with their outcomes.
232
- */
233
- readonly released: readonly ApplyOutcome[];
234
- }
235
- export interface DataUnitApplierOptions extends DataUnitCheckOptions {
236
- /**
237
- * Where verified units, their exact bytes, statuses and the accepted
238
- * marks live (the wire SeenUnits runs on it). InMemoryLfcpStorage for
239
- * tests and development only.
240
- */
241
- readonly storage: Pick<LfcpStorage, "dataUnits" | "snapshots" | "commit" | "localMarks">;
242
- /** The DEK of a Data Epoch, if this client holds it (e.g. dekResolver). */
243
- readonly dek: (epoch: DataEpoch) => ResourceDEK | undefined | Promise<ResourceDEK | undefined>;
244
- /** The profiles this client implements. */
245
- readonly handlers: readonly DataProfileHandler<unknown>[];
246
- }
247
- export declare class DataUnitApplier {
248
- #private;
249
- constructor(options: DataUnitApplierOptions);
250
- /**
251
- * Receives one Data Unit of the Resource `view` describes. Never creates
252
- * a Data Unit: received content is applied, not re-sent as local work.
253
- */
254
- receive(view: ControlView, bytes: Uint8Array): Promise<ApplyOutcome>;
255
- /**
256
- * Receives the units of one DATA_BATCH (or any run of units) of the
257
- * Resource `view` describes: each passes the LFCP checks of receive in
258
- * order, unchanged, and the accepted ones reach the profile together
259
- * through the handler's applyBatch, when it has one. Outcomes come in the
260
- * order of `units`. An applied unit's objects and diagnostics are those
261
- * of the whole batch, reported on the last unit merged; the units
262
- * buffered before that the batch unblocked count as merged by the first.
263
- * Before an equivocation is handled, the units accepted so far are
264
- * applied, so its exclusion sees them.
265
- */
266
- receiveBatch(view: ControlView, units: readonly Uint8Array[]): Promise<ApplyOutcome[]>;
267
- /**
268
- * After a restart: the stored, LFCP-accepted units (merged or buffered by
269
- * the profile) whose content the restored profile state does not hold
270
- * (merged after its last checkpoint), decrypted again from their exact
271
- * stored bytes and applied, in (actor, seq) order. Units covered by a
272
- * Snapshot are not replayed (their content came with it). Needs the
273
- * handler's has(); returns what was replayed and what could not be (no
274
- * DEK, refused). LFCP checks are not repeated: the units passed them when
275
- * they were accepted.
276
- */
277
- replayStored(view: ControlView): Promise<{
278
- readonly replayed: readonly DataUnitId[];
279
- readonly skipped: readonly {
280
- readonly unitId: DataUnitId;
281
- readonly reason: string;
282
- }[];
283
- /** Units quarantined at this start: they crashed the engine twice by themselves. */
284
- readonly crashed: readonly DataUnitId[];
285
- }>;
286
- /**
287
- * A unit inside the frontier of a Snapshot this client loaded (§29, §66
288
- * step 3): its content is in the Snapshot, so it is not decrypted or
289
- * merged again. It gets the DEK-free LFCP checks (structure, signature,
290
- * equivocation, data/write at its head, epoch cutoff) and is then marked
291
- * accepted, so the actor's next unit links to it (§26.2). Its own link to
292
- * the previous unit is not checked: that unit is attested by the signed,
293
- * authorized Snapshot and was never received. A replay is a duplicate.
294
- */
295
- acceptCovered(view: ControlView, bytes: Uint8Array): Promise<ApplyOutcome>;
296
- reconcileEpochs(view: ControlView): Promise<EpochReconciliation>;
297
- }
298
- export {};
299
- //# sourceMappingURL=apply.d.ts.map