@gmitch215/folio 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +541 -2
- package/dist/bake.d.ts +179 -0
- package/dist/bake.js +704 -0
- package/dist/browser-worker.d.ts +9 -0
- package/dist/browser-worker.js +37 -0
- package/dist/browser.d.ts +68 -0
- package/dist/browser.js +274 -0
- package/dist/compiler.d.ts +79 -0
- package/dist/compiler.js +620 -0
- package/dist/context.d.ts +33 -0
- package/dist/context.js +93 -0
- package/dist/coordinator.d.ts +27 -0
- package/dist/coordinator.js +191 -0
- package/dist/extract.d.ts +165 -0
- package/dist/extract.js +1817 -0
- package/dist/frames.d.ts +33 -0
- package/dist/frames.js +159 -0
- package/dist/guards.d.ts +12 -0
- package/dist/guards.js +202 -0
- package/dist/host.d.ts +60 -0
- package/dist/host.js +374 -0
- package/dist/import-order.d.ts +2 -0
- package/dist/import-order.js +114 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/inline.d.ts +68 -0
- package/dist/inline.js +503 -0
- package/dist/iteration-admission.d.ts +76 -0
- package/dist/iteration-admission.js +72 -0
- package/dist/iteration-layout.d.ts +75 -0
- package/dist/iteration-layout.js +118 -0
- package/dist/iteration-owner.d.ts +32 -0
- package/dist/iteration-owner.js +223 -0
- package/dist/iteration-worker.d.ts +1 -0
- package/dist/iteration-worker.js +150 -0
- package/dist/iteration.d.ts +163 -0
- package/dist/iteration.js +435 -0
- package/dist/managed.d.ts +92 -0
- package/dist/managed.js +421 -0
- package/dist/memory.d.ts +10 -0
- package/dist/memory.js +89 -0
- package/dist/node.d.ts +138 -0
- package/dist/node.js +1153 -0
- package/dist/pages.d.ts +109 -0
- package/dist/pages.js +339 -0
- package/dist/remote.d.ts +86 -0
- package/dist/remote.js +255 -0
- package/dist/tasks.d.ts +107 -0
- package/dist/tasks.js +330 -0
- package/dist/transaction.d.ts +23 -0
- package/dist/transaction.js +93 -0
- package/dist/values.d.ts +3 -0
- package/dist/values.js +25 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +86 -0
- package/package.json +130 -5
package/dist/bake.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/** A memory taken from a live instance or already read into bytes. */
|
|
2
|
+
export type MemorySource = WebAssembly.Memory | ArrayBufferLike | Uint8Array;
|
|
3
|
+
/** A global's value as read from `WebAssembly.Global.value`. */
|
|
4
|
+
export type GlobalValue = number | bigint;
|
|
5
|
+
/**
|
|
6
|
+
* The pages of a booted memory that differ from a fresh instance of the same module, plus the
|
|
7
|
+
* mutable globals and table slots boot changed. Pages that are zero in both are not stored.
|
|
8
|
+
*/
|
|
9
|
+
export interface MemoryImage {
|
|
10
|
+
/** Size of the booted memory, a multiple of 65,536. */
|
|
11
|
+
byteLength: number;
|
|
12
|
+
/** Page indexes that differ, strictly ascending. */
|
|
13
|
+
pages: number[];
|
|
14
|
+
/** The bytes of those pages, in the same order (`pages.length * 65,536` bytes). */
|
|
15
|
+
data: Uint8Array;
|
|
16
|
+
/** Lowercase sha256 hex of the module bytes the image was taken from. */
|
|
17
|
+
module?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Caller-supplied digest of whatever else shapes the heap (settings, shims, assets); this module
|
|
20
|
+
* keeps it as an opaque string of at most 4,096 UTF-8 bytes and compares it at replay.
|
|
21
|
+
*/
|
|
22
|
+
context?: string;
|
|
23
|
+
/** Mutable globals whose value differs from the fresh instance, by wasm global index. */
|
|
24
|
+
globals?: Record<number, GlobalValue>;
|
|
25
|
+
/** Function table slots whose function differs from the fresh instance. */
|
|
26
|
+
tableSlots?: number[];
|
|
27
|
+
}
|
|
28
|
+
/** The same thing read from the booted instance and from a fresh instance of the module. */
|
|
29
|
+
export interface BootedAndFresh<T> {
|
|
30
|
+
/** The value on the instance whose boot sequence has run. */
|
|
31
|
+
booted: T;
|
|
32
|
+
/** The value on a fresh instance of the same module. */
|
|
33
|
+
fresh: T;
|
|
34
|
+
}
|
|
35
|
+
/** Values `captureImage` reads from two instances; the caller supplies them. */
|
|
36
|
+
export interface CaptureOptions {
|
|
37
|
+
/** sha256 hex of the module bytes; `moduleDigest(bytes)` computes it. */
|
|
38
|
+
module?: string;
|
|
39
|
+
/** The context digest to record in the image. */
|
|
40
|
+
context?: string;
|
|
41
|
+
/** Global values read from the booted and the fresh instance, by wasm global index. */
|
|
42
|
+
globals?: BootedAndFresh<Record<number, GlobalValue>>;
|
|
43
|
+
/**
|
|
44
|
+
* Table after boot and a table holding the pre-boot function references. Copy the references
|
|
45
|
+
* before boot; functions from separately instantiated modules have distinct identities and are
|
|
46
|
+
* conservatively reported as changed. Function names cannot establish identity.
|
|
47
|
+
*/
|
|
48
|
+
table?: BootedAndFresh<WebAssembly.Table>;
|
|
49
|
+
}
|
|
50
|
+
/** The result of `imagePages`. */
|
|
51
|
+
export interface ImagePages {
|
|
52
|
+
/** Pages the memory must have to take the image. */
|
|
53
|
+
memoryPages: number;
|
|
54
|
+
/** Pages the image carries, each 64 KiB. */
|
|
55
|
+
deltaPages: number;
|
|
56
|
+
}
|
|
57
|
+
/** What `bakeModule` may do beyond its defaults. */
|
|
58
|
+
export interface BakeOptions {
|
|
59
|
+
/** Largest data segment in bytes, a multiple of 65,536 (default 64 MiB). */
|
|
60
|
+
maxSegmentBytes?: number;
|
|
61
|
+
/** Bake an image that reports changed table slots; the caller then restores them itself. */
|
|
62
|
+
allowTableChanges?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** What `applyImage` requires of an image; a value the image does not carry or differs in is refused. */
|
|
65
|
+
export interface ApplyExpectation {
|
|
66
|
+
/** sha256 hex of the module bytes the memory belongs to. */
|
|
67
|
+
module?: string;
|
|
68
|
+
/** The context digest the replaying site computes. */
|
|
69
|
+
context?: string;
|
|
70
|
+
}
|
|
71
|
+
/** `ApplyExpectation` plus the one switch `applyImage` has. */
|
|
72
|
+
export interface ApplyOptions extends ApplyExpectation {
|
|
73
|
+
/**
|
|
74
|
+
* Copy the memory pages of an image that also records changed globals or table slots. The copy
|
|
75
|
+
* does not set them: the instance keeps its fresh values, so it is not a booted instance, and
|
|
76
|
+
* only the caller can restore them (a module's own globals cannot be written from outside).
|
|
77
|
+
* Without this flag such an image is refused with code `global` or `table`.
|
|
78
|
+
*/
|
|
79
|
+
memoryOnly?: boolean;
|
|
80
|
+
}
|
|
81
|
+
/** The result of `checkBaked`. */
|
|
82
|
+
export interface BakedCheck {
|
|
83
|
+
/** True when every image page reads back from the module's data segments unchanged. */
|
|
84
|
+
equal: boolean;
|
|
85
|
+
/** Byte offset in memory of the first byte where a baked page differs from the image. */
|
|
86
|
+
firstDifference?: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Why an image does not fit: a wrong module `digest` or `context`, a module with `no-memory` or
|
|
90
|
+
* several `memories`, an image over the memory `maximum`, or a `global` or `table` change the
|
|
91
|
+
* operation cannot write.
|
|
92
|
+
*/
|
|
93
|
+
export type ImageMismatchCode = 'digest' | 'context' | 'no-memory' | 'memories' | 'maximum' | 'global' | 'table' | 'start';
|
|
94
|
+
/** The image cannot be baked into this module. */
|
|
95
|
+
export declare class ImageMismatchError extends Error {
|
|
96
|
+
/** The reason, for a caller that handles one mismatch differently from another. */
|
|
97
|
+
readonly code: ImageMismatchCode;
|
|
98
|
+
constructor(code: ImageMismatchCode, detail: string);
|
|
99
|
+
}
|
|
100
|
+
/** Why bytes are not an image: a wrong `magic` or `version`, `truncated` input, or `invalid` contents. */
|
|
101
|
+
export type ImageFormatCode = 'magic' | 'version' | 'truncated' | 'invalid';
|
|
102
|
+
/** Bytes are not an encoded image, or an image object is inconsistent. */
|
|
103
|
+
export declare class ImageFormatError extends Error {
|
|
104
|
+
/** The reason the bytes were rejected. */
|
|
105
|
+
readonly code: ImageFormatCode;
|
|
106
|
+
constructor(code: ImageFormatCode, detail: string);
|
|
107
|
+
}
|
|
108
|
+
/** Default cap on one data segment (64 MiB); it bounds the string and heap copy made per segment. */
|
|
109
|
+
export declare const maxSegmentBytes: number;
|
|
110
|
+
/** Lowercase sha256 hex of module bytes, the form `MemoryImage.module` holds. */
|
|
111
|
+
export declare function moduleDigest(bytes: Uint8Array): Promise<string>;
|
|
112
|
+
/** Memory size to create for an image, and how many of its pages the image carries. */
|
|
113
|
+
export declare function imagePages(image: MemoryImage): ImagePages;
|
|
114
|
+
/**
|
|
115
|
+
* Compares a booted memory with a fresh instance of the same module, page by page. A fresh memory
|
|
116
|
+
* shorter than the booted one counts as zero past its end; a longer one is refused. A page the boot
|
|
117
|
+
* zeroed that the module's own data had set is a delta page and ships as zeros.
|
|
118
|
+
*/
|
|
119
|
+
export declare function captureImage(booted: MemorySource, fresh: MemorySource, options?: CaptureOptions): MemoryImage;
|
|
120
|
+
/**
|
|
121
|
+
* Copies the image pages into a live memory, which must hold a fresh instance's contents; the
|
|
122
|
+
* memory grows to the image size first. Globals and table slots are not restored, so an image that
|
|
123
|
+
* records changed ones is refused with `ImageMismatchError` code `global` or `table` unless
|
|
124
|
+
* `memoryOnly` is set; `bakeModule` is the route that writes changed globals into the module.
|
|
125
|
+
*
|
|
126
|
+
* `expect` names the module and context digests of the site doing the replay. Each one given must
|
|
127
|
+
* equal the image's own, so an image that carries none is refused too; `ImageMismatchError` has
|
|
128
|
+
* code `digest` or `context`, and nothing is written to the memory.
|
|
129
|
+
*/
|
|
130
|
+
export declare function applyImage(memory: WebAssembly.Memory, image: MemoryImage, expect?: ApplyOptions): void;
|
|
131
|
+
/**
|
|
132
|
+
* Serializes an image, little endian: magic `FIMG`, u32 version (1), u32 flags (1 digest, 2
|
|
133
|
+
* globals, 4 table slots, 8 context), u32 memory pages, u32 delta pages, then in this order the 32
|
|
134
|
+
* digest bytes, the context (u32 byte count, then UTF-8), the globals (u32 count, then per entry
|
|
135
|
+
* u32 index, u8 kind 0 for a number as f64 or 1 for a bigint as i64, 8 value bytes), the table
|
|
136
|
+
* slots (u32 count, u32 each), the u32 page indexes and the page bytes.
|
|
137
|
+
*/
|
|
138
|
+
export declare function encodeImage(image: MemoryImage): Uint8Array;
|
|
139
|
+
/** Parses `encodeImage` output; `data` is a view into `bytes`, not a copy. */
|
|
140
|
+
export declare function decodeImage(bytes: Uint8Array): MemoryImage;
|
|
141
|
+
/**
|
|
142
|
+
* Plays a baked module's active data segments over zeroed memory and compares each image page
|
|
143
|
+
* with the result, without instantiating. It reads the module bytes directly, so it works the same
|
|
144
|
+
* whether memory 0 is imported or defined. Passive segments are ignored, an offset other than
|
|
145
|
+
* `i32.const` or `i64.const` throws, and only the image pages are checked, not globals or other
|
|
146
|
+
* pages.
|
|
147
|
+
*/
|
|
148
|
+
export declare function checkBaked(baked: Uint8Array, image: MemoryImage): BakedCheck;
|
|
149
|
+
/** One occurrence of a needle in an image. */
|
|
150
|
+
export interface ImageMatch {
|
|
151
|
+
/** Index into the `needles` array passed to `findInImage`. */
|
|
152
|
+
needle: number;
|
|
153
|
+
/** Byte offset in the image's memory. */
|
|
154
|
+
offset: number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Every offset at which a needle's bytes occur in the image pages, ascending per needle. A match
|
|
158
|
+
* may span adjacent image pages and never spans a gap, so a needle straddling a delta page and an
|
|
159
|
+
* unchanged page is not found. Overlapping matches are all reported. A baked image is public, so
|
|
160
|
+
* this is how to prove a secret is not in it: pass the secret as bytes, and its base64 and hex
|
|
161
|
+
* forms as further needles.
|
|
162
|
+
*/
|
|
163
|
+
export declare function findInImage(image: MemoryImage, needles: Uint8Array[]): ImageMatch[];
|
|
164
|
+
/**
|
|
165
|
+
* Returns the module with the image pages as active data segments after its own segments, and
|
|
166
|
+
* the image's changed mutable globals written as their initial values. Adjacent pages merge into
|
|
167
|
+
* one segment, split at `maxSegmentBytes`. The module must have exactly one memory.
|
|
168
|
+
*
|
|
169
|
+
* An imported memory is left alone: whoever instantiates the baked module creates it with at least
|
|
170
|
+
* `imagePages(image).memoryPages` pages. A defined memory whose initial pages are below the image
|
|
171
|
+
* size has them raised to the image size (only the memory section changes); its maximum, shared
|
|
172
|
+
* flag and memory64 flag stay as they are, and one already large enough is untouched.
|
|
173
|
+
*
|
|
174
|
+
* Throws `ImageMismatchError` for a wrong module digest (taken over `bytes` as passed), a module
|
|
175
|
+
* with no memory or with more than one, an image over the memory maximum, a global that cannot be rewritten and changed
|
|
176
|
+
* table slots (unless `allowTableChanges`). A start function is refused because it would run
|
|
177
|
+
* again over the captured state.
|
|
178
|
+
*/
|
|
179
|
+
export declare function bakeModule(bytes: Uint8Array, image: MemoryImage, options?: BakeOptions): Promise<Uint8Array>;
|