@gmitch215/folio 1.0.0 → 1.1.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 +455 -26
- package/dist/affine-state.d.ts +171 -0
- package/dist/affine-state.js +763 -0
- package/dist/affine.d.ts +160 -0
- package/dist/affine.js +571 -0
- package/dist/bake.d.ts +8 -3
- package/dist/bake.js +5 -2
- package/dist/boundaries.d.ts +59 -0
- package/dist/boundaries.js +127 -0
- package/dist/certified.d.ts +66 -0
- package/dist/certified.js +192 -0
- package/dist/certify.d.ts +98 -0
- package/dist/certify.js +2628 -0
- package/dist/compiler.d.ts +37 -1
- package/dist/compiler.js +116 -1
- package/dist/context.d.ts +47 -0
- package/dist/context.js +139 -0
- package/dist/coordinator.d.ts +1 -1
- package/dist/coordinator.js +54 -5
- package/dist/extract.d.ts +114 -1
- package/dist/extract.js +1011 -242
- package/dist/fold.d.ts +32 -0
- package/dist/fold.js +105 -0
- package/dist/frames.d.ts +20 -2
- package/dist/frames.js +205 -10
- package/dist/inline.d.ts +182 -0
- package/dist/inline.js +766 -0
- package/dist/iteration-admission.d.ts +185 -0
- package/dist/iteration-admission.js +201 -0
- package/dist/iteration-layout.d.ts +135 -0
- package/dist/iteration-layout.js +169 -0
- package/dist/iteration-owner.d.ts +45 -0
- package/dist/iteration-owner.js +223 -0
- package/dist/iteration-worker.d.ts +1 -0
- package/dist/iteration-worker.js +216 -0
- package/dist/iteration.d.ts +329 -0
- package/dist/iteration.js +1210 -0
- package/dist/lease.d.ts +45 -0
- package/dist/lease.js +274 -0
- package/dist/managed.d.ts +78 -0
- package/dist/managed.js +448 -27
- package/dist/memo.d.ts +99 -0
- package/dist/memo.js +250 -0
- package/dist/node.d.ts +61 -5
- package/dist/node.js +421 -23
- package/dist/ownership-redirect.d.ts +30 -0
- package/dist/ownership-redirect.js +179 -0
- package/dist/ownership-slices.d.ts +44 -0
- package/dist/ownership-slices.js +72 -0
- package/dist/ownership.d.ts +161 -0
- package/dist/ownership.js +6568 -0
- package/dist/ranges.d.ts +78 -0
- package/dist/ranges.js +263 -0
- package/dist/read-scan.d.ts +18 -0
- package/dist/read-scan.js +94 -0
- package/dist/read-windows.d.ts +103 -0
- package/dist/read-windows.js +244 -0
- package/dist/router-worker.d.ts +1 -0
- package/dist/router-worker.js +4 -0
- package/dist/router.d.ts +203 -0
- package/dist/router.js +667 -0
- package/dist/runs.d.ts +44 -0
- package/dist/runs.js +182 -0
- package/dist/slices-worker.d.ts +1 -0
- package/dist/slices-worker.js +38 -0
- package/dist/slices.d.ts +126 -0
- package/dist/slices.js +441 -0
- package/dist/tasks.d.ts +14 -4
- package/dist/tasks.js +23 -9
- package/dist/transaction.d.ts +10 -0
- package/package.json +44 -4
package/dist/affine.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type FoldChunk } from './fold.ts';
|
|
2
|
+
import { type TaskLink, type TaskPool } from './tasks.ts';
|
|
3
|
+
/** `gf2` is affine over GF(2)^bits (xor), `z2w` is affine over Z/2^bits (add, multiply). */
|
|
4
|
+
export type AffineRing = 'gf2' | 'z2w';
|
|
5
|
+
/** The model of a certificate may also be `zp`: two 16-bit digits of the state, each a residue mod p. */
|
|
6
|
+
export type AffineModelRing = AffineRing | 'zp';
|
|
7
|
+
/** Where the state, the pointer and the length sit in the entry's parameter list. */
|
|
8
|
+
export interface AffineLayout {
|
|
9
|
+
entry: string;
|
|
10
|
+
state: number;
|
|
11
|
+
ptr: number;
|
|
12
|
+
len: number;
|
|
13
|
+
bits: 32 | 64;
|
|
14
|
+
}
|
|
15
|
+
/** One check the probe ran. `trials` counts the trials run, which is fewer than asked on a failure. */
|
|
16
|
+
export interface AffineCheck {
|
|
17
|
+
ring: AffineRing;
|
|
18
|
+
name: string;
|
|
19
|
+
trials: number;
|
|
20
|
+
passed: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The recovered model: T(s, x) = A(|x|) s + T(0, x) over `ring`, with A(|x|) the `align`-byte
|
|
24
|
+
* operator raised to the power |x| / align. `operator` is the columns of that operator over GF(2),
|
|
25
|
+
* or its multiplier over Z/2^bits. Over `zp` the state is `digits` digits of `bits / digits` bits,
|
|
26
|
+
* each reduced mod `modulus` after a call of at least one byte, and `operator` is the digits by
|
|
27
|
+
* digits matrix mod `modulus` in row order.
|
|
28
|
+
*/
|
|
29
|
+
export interface AffineModel {
|
|
30
|
+
kind: 'model';
|
|
31
|
+
ring: AffineModelRing;
|
|
32
|
+
bits: 32 | 64;
|
|
33
|
+
align: number;
|
|
34
|
+
layout: AffineLayout;
|
|
35
|
+
operator: bigint[] | bigint;
|
|
36
|
+
modulus?: bigint;
|
|
37
|
+
digits?: number;
|
|
38
|
+
checks: AffineCheck[];
|
|
39
|
+
calls: number;
|
|
40
|
+
}
|
|
41
|
+
/** The probe found no affine structure, or no streaming shape. `reason` names the check. */
|
|
42
|
+
export interface AffineRefusal {
|
|
43
|
+
kind: 'refusal';
|
|
44
|
+
reason: string;
|
|
45
|
+
checks: AffineCheck[];
|
|
46
|
+
calls: number;
|
|
47
|
+
}
|
|
48
|
+
export interface AffineProbeOptions {
|
|
49
|
+
/** Seed of the PRNG that draws states and data. The default is fixed. */
|
|
50
|
+
seed?: number;
|
|
51
|
+
/** Trials per check. The default is 32. */
|
|
52
|
+
trials?: number;
|
|
53
|
+
/** Every probed length is a multiple of this, for kernels that take whole blocks. */
|
|
54
|
+
align?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface AffineSubject {
|
|
57
|
+
module: WebAssembly.Module | Uint8Array;
|
|
58
|
+
layout: AffineLayout;
|
|
59
|
+
}
|
|
60
|
+
export interface AffineFoldOptions {
|
|
61
|
+
/** `exact` validates every boundary. `audit` reruns a sample of chunks. The default is `exact`. */
|
|
62
|
+
mode?: 'exact' | 'audit';
|
|
63
|
+
/** State before the first byte. The default is 0. */
|
|
64
|
+
initial?: bigint;
|
|
65
|
+
/** Explicit chunk ranges. The default splits the input into `pool.width` aligned chunks. */
|
|
66
|
+
chunks?: FoldChunk[];
|
|
67
|
+
/** Audit mode: chunks to rerun from their predicted start. The default is 2. */
|
|
68
|
+
audit?: number;
|
|
69
|
+
/** Audit mode: seed of the sample. The default is 1. */
|
|
70
|
+
seed?: number;
|
|
71
|
+
}
|
|
72
|
+
export interface AffineFoldResult {
|
|
73
|
+
mode: 'exact' | 'audit';
|
|
74
|
+
state: bigint;
|
|
75
|
+
chunks: number;
|
|
76
|
+
tasks: number;
|
|
77
|
+
/** Chunk boundaries where the real end state equalled the predicted start of the next chunk. */
|
|
78
|
+
validated: number;
|
|
79
|
+
/** The first chunk whose real end state differed from the prediction, or -1. */
|
|
80
|
+
mismatchAt: number;
|
|
81
|
+
/** Audit mode: the chunks that were rerun. */
|
|
82
|
+
audited: number[];
|
|
83
|
+
/** Bytes that ran again serially after a mismatch. */
|
|
84
|
+
fallbackBytes: number;
|
|
85
|
+
}
|
|
86
|
+
/** The task name `serveAffine` answers: `affine:<start state in hex>`. */
|
|
87
|
+
export declare const AFFINE_TASK = "affine";
|
|
88
|
+
export declare const mask: (bits: number) => bigint;
|
|
89
|
+
export declare function mulberry(seed: number): () => number;
|
|
90
|
+
export declare function gfApply(columns: bigint[], vector: bigint): bigint;
|
|
91
|
+
export declare const gfMul: (a: bigint[], b: bigint[]) => bigint[];
|
|
92
|
+
/**
|
|
93
|
+
* The state-dependent part of T(state, x) for a chunk of `length` bytes: A(length) state. The
|
|
94
|
+
* operator comes from repeated squaring and is cached per length. `length` must be a multiple of
|
|
95
|
+
* `model.align`. Over `zp` a zero length leaves the state as it is and any other length reduces
|
|
96
|
+
* every digit.
|
|
97
|
+
*/
|
|
98
|
+
export declare function advance(model: AffineModel, state: bigint, length: number): bigint;
|
|
99
|
+
/** T(start, x) predicted from `offset` = T(0, x): A(length) start combined with the offset. */
|
|
100
|
+
export declare function predictEnd(model: AffineModel, start: bigint, length: number, offset: bigint): bigint;
|
|
101
|
+
/**
|
|
102
|
+
* Probes `entry`, a function (state, pointer, length) -> state, in a private instance of `module`
|
|
103
|
+
* and decides by trial whether its state transition is affine over GF(2)^bits or over Z/2^bits.
|
|
104
|
+
* It recovers the parameter roles, checks affinity, data independence, homogeneity (the operator
|
|
105
|
+
* for L bytes is the L-th power of the one-unit operator), additivity and streaming composition,
|
|
106
|
+
* and returns the model or the check that failed. Every call into the kernel is counted.
|
|
107
|
+
* A pass is evidence on the sampled inputs only; `foldAffine` in `exact` mode is what makes the
|
|
108
|
+
* result independent of the probe.
|
|
109
|
+
*/
|
|
110
|
+
export declare function probeAffine(module: WebAssembly.Module | Uint8Array, entry: string, options?: AffineProbeOptions): (AffineModel & {
|
|
111
|
+
ring: AffineRing;
|
|
112
|
+
}) | AffineRefusal;
|
|
113
|
+
/**
|
|
114
|
+
* Runs on the worker side. Instantiates the kernel privately and answers `affine:<hex state>`
|
|
115
|
+
* tasks: the input is the chunk, the output is the 8-byte little-endian end state.
|
|
116
|
+
*/
|
|
117
|
+
export declare function serveAffine(link: TaskLink, subject: AffineSubject): void;
|
|
118
|
+
/** The serial reference: one call over all the bytes in a private instance. */
|
|
119
|
+
export declare function affineSerial(subject: AffineSubject): (input: Uint8Array, state?: bigint) => bigint;
|
|
120
|
+
/** What `foldExact` needs from a state representation. */
|
|
121
|
+
export interface ExactHooks<State> {
|
|
122
|
+
/** The state every chunk but the first starts from in pass 1. */
|
|
123
|
+
zero: State;
|
|
124
|
+
/** Starts the task that runs bytes [from, to) from `start`, returns its handle. */
|
|
125
|
+
submit(start: State, from: number, to: number): string;
|
|
126
|
+
/** Joins a task and decodes its end state. */
|
|
127
|
+
end(handle: string): State;
|
|
128
|
+
/** The end state of a chunk of `length` bytes from `start`, given its end state from zero. */
|
|
129
|
+
predict(start: State, length: number, offset: State): State;
|
|
130
|
+
equal(a: State, b: State): boolean;
|
|
131
|
+
}
|
|
132
|
+
export interface ExactOutcome<State> {
|
|
133
|
+
state: State;
|
|
134
|
+
validated: number;
|
|
135
|
+
mismatchAt: number;
|
|
136
|
+
fallbackBytes: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The two pass exact fold over at least two chunks. The result is the serial state by induction:
|
|
140
|
+
* every pass 2 chunk ran from the start state its predecessor's end state is compared with. The
|
|
141
|
+
* first disagreement hands the rest of the input to one serial task.
|
|
142
|
+
*/
|
|
143
|
+
export declare function foldExact<State>(chunks: FoldChunk[], length: number, initial: State, hooks: ExactHooks<State>): ExactOutcome<State>;
|
|
144
|
+
/**
|
|
145
|
+
* Folds `input` through the kernel on `pool` workers started with `serveAffine`, and returns the
|
|
146
|
+
* state the serial call over the same bytes returns.
|
|
147
|
+
*
|
|
148
|
+
* `exact`: pass 1 runs every chunk but the last from state zero (the first from `initial`); the
|
|
149
|
+
* model turns the offsets into each chunk's predicted start; pass 2 runs chunks 1 to n-1 from
|
|
150
|
+
* their predicted starts; an ordered check compares each chunk's real end state with the next
|
|
151
|
+
* chunk's predicted start. If all agree, the final state is the serial one by induction, whatever
|
|
152
|
+
* the model got wrong. At the first disagreement the rest of the input runs serially from the
|
|
153
|
+
* last real state. This equals the serial call when the kernel composes over a split
|
|
154
|
+
* (T(s, x||y) = T(T(s, x), y)), which the probe checks on samples and nothing here proves.
|
|
155
|
+
*
|
|
156
|
+
* `audit`: one pass from state zero, the model combines the offsets, and `audit` chunks run again
|
|
157
|
+
* from their predicted starts. A disagreement reruns the whole input serially. A chunk that is not
|
|
158
|
+
* sampled is trusted: the model's error in it goes undetected.
|
|
159
|
+
*/
|
|
160
|
+
export declare function foldAffine(pool: TaskPool, input: Uint8Array, model: AffineModel, options?: AffineFoldOptions): AffineFoldResult;
|