@tide-ota/protocol 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HashimTheArab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
- # Temporary Holding Version
1
+ # @tide-ota/protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Expo Updates protocol v1 code shared by [`@tide-ota/server`](https://www.npmjs.com/package/@tide-ota/server) and
4
+ [`@tide-ota/cli`](https://www.npmjs.com/package/@tide-ota/cli): manifests, multipart replies, code signing and bsdiff
5
+ patches, on web-standard APIs only (Workers, Node and browsers).
6
+
7
+ You don't need to install it yourself: it comes with the server and the CLI, and its version always matches theirs.
8
+ Part of [Tide](https://github.com/HashimTheArab/tide), a self-hosted Expo Updates server.
@@ -0,0 +1,14 @@
1
+ /** Pulls decoded bytes from one bzip2 stream, holding one block at a time. */
2
+ export interface Bunzip2Reader {
3
+ /** Fills `into` and returns how many bytes it copied; fewer than `into.length` only at the stream's end. */
4
+ read(into: Uint8Array): number;
5
+ /** Refuses unless every decoded byte was read and the stream ends cleanly at the end of its input. */
6
+ end(): void;
7
+ }
8
+ /** Returns the running bzip2 CRC after `byte`; a block's CRC starts at 0xffffffff and ends inverted. */
9
+ export declare function bzip2CrcStep(crc: number, byte: number): number;
10
+ /**
11
+ * Returns a reader over the single bzip2 stream that fills `input` exactly. Every malformed, truncated or
12
+ * CRC-failing stream, and any decoded byte past `limit`, is a ProtocolError on `field`.
13
+ */
14
+ export declare function bunzip2(input: Uint8Array, field: string, limit: number): Bunzip2Reader;
package/dist/bzip2.js ADDED
@@ -0,0 +1,307 @@
1
+ import { ProtocolError } from "./hash.js";
2
+ const MAX_GROUPS = 6;
3
+ const MAX_ALPHA = 258;
4
+ const MAX_CODE_LEN = 20;
5
+ const GROUP_SIZE = 50;
6
+ const MAX_SELECTORS = 18002;
7
+ const CRC_TABLE = Uint32Array.from({ length: 256 }, (_, i) => {
8
+ let c = i << 24;
9
+ for (let k = 0; k < 8; k++)
10
+ c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : c << 1;
11
+ return c >>> 0;
12
+ });
13
+ /** Returns the running bzip2 CRC after `byte`; a block's CRC starts at 0xffffffff and ends inverted. */
14
+ export function bzip2CrcStep(crc, byte) {
15
+ return ((crc << 8) ^ (CRC_TABLE[((crc >>> 24) ^ byte) & 0xff] ?? 0)) >>> 0;
16
+ }
17
+ /**
18
+ * Returns a reader over the single bzip2 stream that fills `input` exactly. Every malformed, truncated or
19
+ * CRC-failing stream, and any decoded byte past `limit`, is a ProtocolError on `field`.
20
+ */
21
+ export function bunzip2(input, field, limit) {
22
+ const fail = (rule) => {
23
+ throw new ProtocolError(field, rule);
24
+ };
25
+ // MSB-first bit reader; at most 7 bits stay buffered between reads.
26
+ let at = 0;
27
+ let buf = 0;
28
+ let count = 0;
29
+ const bits = (n) => {
30
+ while (count < n) {
31
+ if (at >= input.length)
32
+ fail("is truncated");
33
+ buf = (buf << 8) | (input[at++] ?? 0);
34
+ count += 8;
35
+ }
36
+ count -= n;
37
+ const v = (buf >>> count) & ((1 << n) - 1);
38
+ buf &= (1 << count) - 1;
39
+ return v;
40
+ };
41
+ const bits32 = () => ((bits(16) << 16) | bits(16)) >>> 0;
42
+ // Set by the stream header, on first use.
43
+ let max = 0;
44
+ let tt = new Uint32Array(0); // Block bytes in the low 8 bits, inverse BWT links above.
45
+ const selectors = new Uint8Array(MAX_SELECTORS);
46
+ const lengths = new Uint8Array(MAX_GROUPS * MAX_ALPHA);
47
+ const countAt = new Int32Array(MAX_GROUPS * (MAX_CODE_LEN + 1)); // Codes of each length per group.
48
+ const firstAt = new Int32Array(MAX_GROUPS * (MAX_CODE_LEN + 1)); // First canonical code of each length.
49
+ const offsetAt = new Int32Array(MAX_GROUPS * (MAX_CODE_LEN + 1)); // Its index in `perm`.
50
+ const perm = new Uint16Array(MAX_GROUPS * MAX_ALPHA);
51
+ const seqToUnseq = new Uint8Array(256);
52
+ const mtf = new Uint8Array(256);
53
+ const counts = new Int32Array(256);
54
+ let started = false;
55
+ let done = false;
56
+ let combined = 0;
57
+ let produced = 0;
58
+ // The current block's output: inverse BWT walk, then RLE1.
59
+ let inBlock = false;
60
+ let tPos = 0;
61
+ let left = 0;
62
+ let last = -1;
63
+ let run = 0;
64
+ let repeat = 0;
65
+ let crc = 0;
66
+ let expectedCrc = 0;
67
+ function start() {
68
+ started = true;
69
+ if (bits(8) !== 0x42 || bits(8) !== 0x5a || bits(8) !== 0x68)
70
+ fail("is not a bzip2 stream");
71
+ const level = bits(8) - 0x30;
72
+ if (level < 1 || level > 9)
73
+ fail("has a bad block size");
74
+ max = level * 100_000;
75
+ tt = new Uint32Array(max);
76
+ }
77
+ /** Builds group `g`'s decode table from its code lengths, refusing lengths no prefix code can have. */
78
+ function buildTable(g, alphaSize) {
79
+ const base = g * (MAX_CODE_LEN + 1);
80
+ countAt.fill(0, base, base + MAX_CODE_LEN + 1);
81
+ for (let s = 0; s < alphaSize; s++) {
82
+ const len = lengths[g * MAX_ALPHA + s] ?? 0;
83
+ countAt[base + len] = (countAt[base + len] ?? 0) + 1;
84
+ }
85
+ let kraft = 0;
86
+ for (let len = 1; len <= MAX_CODE_LEN; len++) {
87
+ kraft += (countAt[base + len] ?? 0) * 2 ** (MAX_CODE_LEN - len);
88
+ }
89
+ if (kraft > 2 ** MAX_CODE_LEN)
90
+ fail("has an over-subscribed Huffman table");
91
+ let code = 0;
92
+ let index = 0;
93
+ for (let len = 1; len <= MAX_CODE_LEN; len++) {
94
+ const n = countAt[base + len] ?? 0;
95
+ firstAt[base + len] = code;
96
+ offsetAt[base + len] = index;
97
+ for (let s = 0; s < alphaSize; s++) {
98
+ if (lengths[g * MAX_ALPHA + s] === len)
99
+ perm[g * MAX_ALPHA + index++] = s;
100
+ }
101
+ code = (code + n) * 2;
102
+ }
103
+ }
104
+ function symbol(g) {
105
+ const base = g * (MAX_CODE_LEN + 1);
106
+ let code = 0;
107
+ for (let len = 1; len <= MAX_CODE_LEN; len++) {
108
+ code = (code << 1) | bits(1);
109
+ const d = code - (firstAt[base + len] ?? 0);
110
+ if (d >= 0 && d < (countAt[base + len] ?? 0)) {
111
+ return perm[g * MAX_ALPHA + (offsetAt[base + len] ?? 0) + d] ?? 0;
112
+ }
113
+ }
114
+ return fail("has an undecodable Huffman code");
115
+ }
116
+ /** Decodes the next block into `tt`; false at the end-of-stream marker, after its checks pass. */
117
+ function nextBlock() {
118
+ const hi = bits(24);
119
+ const lo = bits(24);
120
+ if (hi === 0x177245 && lo === 0x385090) {
121
+ if (bits32() !== combined)
122
+ fail("has a bad stream CRC");
123
+ if (buf !== 0)
124
+ fail("has non-zero padding");
125
+ if (at !== input.length)
126
+ fail("has data after the stream end");
127
+ return false;
128
+ }
129
+ if (hi !== 0x314159 || lo !== 0x265359)
130
+ fail("has a bad block marker");
131
+ expectedCrc = bits32();
132
+ if (bits(1) === 1)
133
+ fail("has a randomised block");
134
+ const origPtr = bits(24);
135
+ let nInUse = 0;
136
+ const used = bits(16);
137
+ for (let i = 0; i < 16; i++) {
138
+ if ((used & (0x8000 >>> i)) === 0)
139
+ continue;
140
+ const sub = bits(16);
141
+ for (let j = 0; j < 16; j++)
142
+ if (sub & (0x8000 >>> j))
143
+ seqToUnseq[nInUse++] = i * 16 + j;
144
+ }
145
+ if (nInUse === 0)
146
+ fail("has a block with no symbols");
147
+ const alphaSize = nInUse + 2;
148
+ const nGroups = bits(3);
149
+ if (nGroups < 2 || nGroups > MAX_GROUPS)
150
+ fail("has a bad Huffman group count");
151
+ const nSelectors = bits(15);
152
+ if (nSelectors < 1 || nSelectors > MAX_SELECTORS)
153
+ fail("has a bad selector count");
154
+ const groupMtf = [0, 1, 2, 3, 4, 5];
155
+ for (let i = 0; i < nSelectors; i++) {
156
+ let j = 0;
157
+ while (bits(1) === 1)
158
+ if (++j >= nGroups)
159
+ fail("has a selector out of range");
160
+ const g = groupMtf[j] ?? 0;
161
+ groupMtf.copyWithin(1, 0, j);
162
+ groupMtf[0] = g;
163
+ selectors[i] = g;
164
+ }
165
+ for (let g = 0; g < nGroups; g++) {
166
+ let len = bits(5);
167
+ for (let s = 0; s < alphaSize; s++) {
168
+ for (;;) {
169
+ if (len < 1 || len > MAX_CODE_LEN)
170
+ fail("has a bad Huffman code length");
171
+ if (bits(1) === 0)
172
+ break;
173
+ len += bits(1) === 0 ? 1 : -1;
174
+ }
175
+ lengths[g * MAX_ALPHA + s] = len;
176
+ }
177
+ buildTable(g, alphaSize);
178
+ }
179
+ // Symbols: RUNA and RUNB spell zero runs, then move-to-front indexes, then end of block.
180
+ const eob = nInUse + 1;
181
+ for (let i = 0; i < 256; i++)
182
+ mtf[i] = i;
183
+ counts.fill(0);
184
+ let selector = 0;
185
+ let groupLeft = 0;
186
+ let group = 0;
187
+ const next = () => {
188
+ if (groupLeft === 0) {
189
+ if (selector >= nSelectors)
190
+ fail("runs out of selectors");
191
+ group = selectors[selector++] ?? 0;
192
+ groupLeft = GROUP_SIZE;
193
+ }
194
+ groupLeft--;
195
+ return symbol(group);
196
+ };
197
+ let nblock = 0;
198
+ let sym = next();
199
+ while (sym !== eob) {
200
+ if (sym <= 1) {
201
+ let n = 0;
202
+ let weight = 1;
203
+ do {
204
+ n += (sym + 1) * weight;
205
+ weight *= 2;
206
+ if (nblock + n > max)
207
+ fail("has a block longer than its size allows");
208
+ sym = next();
209
+ } while (sym <= 1);
210
+ const uc = seqToUnseq[mtf[0] ?? 0] ?? 0;
211
+ counts[uc] = (counts[uc] ?? 0) + n;
212
+ tt.fill(uc, nblock, nblock + n);
213
+ nblock += n;
214
+ continue;
215
+ }
216
+ if (nblock >= max)
217
+ fail("has a block longer than its size allows");
218
+ const v = mtf[sym - 1] ?? 0;
219
+ mtf.copyWithin(1, 0, sym - 1);
220
+ mtf[0] = v;
221
+ const uc = seqToUnseq[v] ?? 0;
222
+ counts[uc] = (counts[uc] ?? 0) + 1;
223
+ tt[nblock++] = uc;
224
+ sym = next();
225
+ }
226
+ if (origPtr >= nblock)
227
+ fail("has a block origin out of range");
228
+ // Inverse BWT: link each byte to the next position in the original order.
229
+ let sum = 0;
230
+ for (let i = 0; i < 256; i++) {
231
+ const c = counts[i] ?? 0;
232
+ counts[i] = sum;
233
+ sum += c;
234
+ }
235
+ for (let i = 0; i < nblock; i++) {
236
+ const uc = (tt[i] ?? 0) & 0xff;
237
+ const to = counts[uc] ?? 0;
238
+ tt[to] = (tt[to] ?? 0) | (i << 8);
239
+ counts[uc] = to + 1;
240
+ }
241
+ tPos = (tt[origPtr] ?? 0) >>> 8;
242
+ left = nblock;
243
+ last = -1;
244
+ run = 0;
245
+ repeat = 0;
246
+ crc = 0xffffffff;
247
+ return true;
248
+ }
249
+ function finishBlock() {
250
+ const actual = ~crc >>> 0;
251
+ if (actual !== expectedCrc)
252
+ fail("has a bad block CRC");
253
+ combined = (((combined << 1) | (combined >>> 31)) ^ actual) >>> 0;
254
+ }
255
+ function read(into) {
256
+ if (!started)
257
+ start();
258
+ let n = 0;
259
+ while (n < into.length && !done) {
260
+ let byte;
261
+ if (repeat > 0) {
262
+ repeat--;
263
+ byte = last;
264
+ }
265
+ else if (left === 0) {
266
+ if (inBlock)
267
+ finishBlock();
268
+ inBlock = nextBlock();
269
+ done = !inBlock;
270
+ continue;
271
+ }
272
+ else {
273
+ const entry = tt[tPos] ?? 0;
274
+ byte = entry & 0xff;
275
+ tPos = entry >>> 8;
276
+ left--;
277
+ if (run === 4) {
278
+ // The fifth byte of a run counts its further repeats.
279
+ repeat = byte;
280
+ run = 0;
281
+ continue;
282
+ }
283
+ if (byte === last)
284
+ run++;
285
+ else {
286
+ last = byte;
287
+ run = 1;
288
+ }
289
+ if (run === 4 && left === 0)
290
+ fail("has a block that ends inside a run");
291
+ }
292
+ if (produced === limit)
293
+ fail(`decodes to more than ${limit} bytes`);
294
+ produced++;
295
+ crc = bzip2CrcStep(crc, byte);
296
+ into[n++] = byte;
297
+ }
298
+ return n;
299
+ }
300
+ return {
301
+ read,
302
+ end() {
303
+ if (read(new Uint8Array(1)) !== 0)
304
+ fail("has data past its end");
305
+ },
306
+ };
307
+ }
package/dist/hash.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /** The one error this package throws for rejected input; `field` names the offending input. */
2
+ export declare class ProtocolError extends Error {
3
+ readonly field: string;
4
+ constructor(field: string, message: string);
5
+ }
6
+ /** Returns the SHA-256 of `bytes` as unpadded base64url, the Expo manifest `hash` field. */
7
+ export declare function sha256Base64Url(bytes: Uint8Array<ArrayBuffer>): Promise<string>;
8
+ /** Returns the lowercase hex SHA-256 of `bytes`. */
9
+ export declare function sha256Hex(bytes: Uint8Array<ArrayBuffer>): Promise<string>;
10
+ export declare const hex: (bytes: ArrayBuffer | Uint8Array) => string;
11
+ /** Returns `bytes` as standard padded base64. */
12
+ export declare function base64(bytes: Uint8Array): string;
13
+ /** Returns the bytes of non-empty canonical padded base64, or undefined. */
14
+ export declare function decodeBase64(text: string): Uint8Array<ArrayBuffer> | undefined;
15
+ /** Returns `value` if it is the canonical 43-character base64url encoding of a 32-byte digest. */
16
+ export declare function assetHash(value: unknown, field: string): string;
17
+ /**
18
+ * Returns the storage key for the bytes behind `hash`: the digest as 64 lowercase hex characters.
19
+ * Hex, not the hash itself, so keys stay distinct on case-insensitive disks.
20
+ */
21
+ export declare function contentKey(hash: string): string;
package/dist/hash.js ADDED
@@ -0,0 +1,54 @@
1
+ /** The one error this package throws for rejected input; `field` names the offending input. */
2
+ export class ProtocolError extends Error {
3
+ field;
4
+ constructor(field, message) {
5
+ super(`${field} ${message}`);
6
+ this.name = "ProtocolError";
7
+ this.field = field;
8
+ }
9
+ }
10
+ /** Returns the SHA-256 of `bytes` as unpadded base64url, the Expo manifest `hash` field. */
11
+ export async function sha256Base64Url(bytes) {
12
+ const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
13
+ return base64(digest).replaceAll("+", "-").replaceAll("/", "_").replace(/=$/, "");
14
+ }
15
+ /** Returns the lowercase hex SHA-256 of `bytes`. */
16
+ export async function sha256Hex(bytes) {
17
+ return hex(await crypto.subtle.digest("SHA-256", bytes));
18
+ }
19
+ export const hex = (bytes) => Array.from(new Uint8Array(bytes), (b) => b.toString(16).padStart(2, "0")).join("");
20
+ /** Returns `bytes` as standard padded base64. */
21
+ export function base64(bytes) {
22
+ let binary = "";
23
+ for (const b of bytes)
24
+ binary += String.fromCharCode(b);
25
+ return btoa(binary);
26
+ }
27
+ /** Returns the bytes of non-empty canonical padded base64, or undefined. */
28
+ export function decodeBase64(text) {
29
+ if (text === "" ||
30
+ !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(text)) {
31
+ return undefined;
32
+ }
33
+ const bytes = Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
34
+ return base64(bytes) === text ? bytes : undefined;
35
+ }
36
+ /** Returns `value` if it is the canonical 43-character base64url encoding of a 32-byte digest. */
37
+ export function assetHash(value, field) {
38
+ // The last character carries 4 data bits and 2 zero bits.
39
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/.test(value)) {
40
+ throw new ProtocolError(field, "must be 43 characters of base64url");
41
+ }
42
+ return value;
43
+ }
44
+ /**
45
+ * Returns the storage key for the bytes behind `hash`: the digest as 64 lowercase hex characters.
46
+ * Hex, not the hash itself, so keys stay distinct on case-insensitive disks.
47
+ */
48
+ export function contentKey(hash) {
49
+ const binary = atob(`${assetHash(hash, "hash").replaceAll("-", "+").replaceAll("_", "/")}=`);
50
+ let hex = "";
51
+ for (let i = 0; i < binary.length; i++)
52
+ hex += binary.charCodeAt(i).toString(16).padStart(2, "0");
53
+ return hex;
54
+ }
@@ -0,0 +1,15 @@
1
+ export { ProtocolError, assetHash, contentKey, decodeBase64, sha256Base64Url } from "./hash.ts";
2
+ export type { Asset, JsonObject, JsonValue, LaunchAsset, ManifestInput } from "./manifest.ts";
3
+ export { UUID, assetContentType, buildManifest, buildNoUpdateAvailable, buildRollBackToEmbedded, } from "./manifest.ts";
4
+ export type { Part, PartName } from "./multipart.ts";
5
+ export { HEADER_VALUE, encodeMultipart, parseMultipart } from "./multipart.ts";
6
+ export { bzip2CrcStep } from "./bzip2.ts";
7
+ export type { BaseAsset, BaseRecord } from "./patch.ts";
8
+ export { MAX_BASE_BYTES, applyBsdiff, decodeBaseRecord, encodeBaseRecord } from "./patch.ts";
9
+ export type { StoredReply } from "./reply.ts";
10
+ export { CONTENT_KEY, MAX_FILTERS_BYTES, LEGACY_MAP_KEY, MAX_REPLY_BYTES, NO_UPDATE_KEY, baseKey, decodeStoredReply, diskKey, diskPath, unescapeDiskPath, encodeStoredReply, patchKey, replyKey, } from "./reply.ts";
11
+ export type { S3Config, S3Operation, S3Request, SigV4Credentials } from "./s3.ts";
12
+ export { S3Error, awsFetch, childElements, parseS3Xml, readLimited, readS3Text, s3Absent, s3BodyProblem, s3ErrorCode, s3Fetch, s3Target, sigV4Credentials, signV4, storageFromEnv, textOf, } from "./s3.ts";
13
+ export { encodeSfvDictionary, parseSfvDictionary } from "./sfv.ts";
14
+ export type { CodeSigningCertificate, Signer } from "./signature.ts";
15
+ export { certificatePublicKey, codeSigningCertificate, cryptoKeySigner, expoSignature, parseExpoSignature, verifyExpoSignature, } from "./signature.ts";
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { ProtocolError, assetHash, contentKey, decodeBase64, sha256Base64Url } from "./hash.js";
2
+ export { UUID, assetContentType, buildManifest, buildNoUpdateAvailable, buildRollBackToEmbedded, } from "./manifest.js";
3
+ export { HEADER_VALUE, encodeMultipart, parseMultipart } from "./multipart.js";
4
+ export { bzip2CrcStep } from "./bzip2.js";
5
+ export { MAX_BASE_BYTES, applyBsdiff, decodeBaseRecord, encodeBaseRecord } from "./patch.js";
6
+ export { CONTENT_KEY, MAX_FILTERS_BYTES, LEGACY_MAP_KEY, MAX_REPLY_BYTES, NO_UPDATE_KEY, baseKey, decodeStoredReply, diskKey, diskPath, unescapeDiskPath, encodeStoredReply, patchKey, replyKey, } from "./reply.js";
7
+ export { S3Error, awsFetch, childElements, parseS3Xml, readLimited, readS3Text, s3Absent, s3BodyProblem, s3ErrorCode, s3Fetch, s3Target, sigV4Credentials, signV4, storageFromEnv, textOf, } from "./s3.js";
8
+ export { encodeSfvDictionary, parseSfvDictionary } from "./sfv.js";
9
+ export { certificatePublicKey, codeSigningCertificate, cryptoKeySigner, expoSignature, parseExpoSignature, verifyExpoSignature, } from "./signature.js";
@@ -0,0 +1,38 @@
1
+ export type JsonValue = string | number | boolean | null | readonly JsonValue[] | JsonObject;
2
+ export interface JsonObject {
3
+ readonly [key: string]: JsonValue;
4
+ }
5
+ /** A manifest asset. `key` is Metro's key and must never name different bytes in any update; publish enforces it. */
6
+ export interface Asset {
7
+ readonly hash: string;
8
+ readonly key: string;
9
+ readonly contentType: string;
10
+ readonly fileExtension: string;
11
+ readonly url: string;
12
+ }
13
+ /** The launch asset; the builder derives its key from `hash`, so the key cannot name other bytes. */
14
+ export type LaunchAsset = Omit<Asset, "key">;
15
+ /** Returns the media type for a bare file extension (`png`, no dot); `application/octet-stream` when unknown. */
16
+ export declare function assetContentType(ext: string): string;
17
+ export interface ManifestInput {
18
+ readonly id: string;
19
+ readonly createdAt: Date;
20
+ readonly runtimeVersion: string;
21
+ readonly launchAsset: LaunchAsset;
22
+ readonly assets: readonly Asset[];
23
+ readonly metadata: Readonly<Record<string, string>>;
24
+ readonly extra: JsonObject;
25
+ }
26
+ export declare const UUID: RegExp;
27
+ export declare const ASSET_KEY: RegExp;
28
+ /**
29
+ * Returns the manifest as the exact UTF-8 bytes to sign, store and serve. Each input field is read once and the
30
+ * bytes are built from fresh objects holding only validated values, so no input method shapes the output.
31
+ */
32
+ export declare function buildManifest(input: ManifestInput): Uint8Array<ArrayBuffer>;
33
+ /** Returns the noUpdateAvailable directive as the exact UTF-8 bytes to sign and store. */
34
+ export declare function buildNoUpdateAvailable(): Uint8Array<ArrayBuffer>;
35
+ /** Returns the rollBackToEmbedded directive as the exact UTF-8 bytes to sign and store. */
36
+ export declare function buildRollBackToEmbedded(input: {
37
+ readonly commitTime: Date;
38
+ }): Uint8Array<ArrayBuffer>;