efiencrypt 0.0.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.
@@ -0,0 +1,2438 @@
1
+ import { spawn } from "node:child_process";
2
+ import { readFile, mkdtemp, mkdir, cp, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join, dirname } from "node:path";
5
+ import { randomBytes, createHash, createCipheriv } from "node:crypto";
6
+ import { createReadStream, createWriteStream } from "node:fs";
7
+ import { pipeline } from "node:stream/promises";
8
+ import { Readable, Transform } from "node:stream";
9
+ import { resolveSmbiosField, getSmbiosField, smbiosDataTypeSize, parseSmbios } from "./smbios.js";
10
+ class StringBuilder {
11
+ #content = [];
12
+ write(content) {
13
+ this.#content.push(content);
14
+ return this;
15
+ }
16
+ async *#read() {
17
+ const content = this.#content;
18
+ this.#content = [];
19
+ while (content.length > 0) {
20
+ const item = content.shift();
21
+ if (item instanceof StringBuilder) {
22
+ content.unshift(...item.#content);
23
+ item.#content = [];
24
+ } else if (typeof item === "string") {
25
+ yield item;
26
+ } else if (Readable.isReadable(item)) {
27
+ for await (const part of item) {
28
+ yield part;
29
+ }
30
+ }
31
+ }
32
+ }
33
+ toReadable() {
34
+ return Readable.from(this.#read(), {
35
+ objectMode: false,
36
+ encoding: "ascii"
37
+ });
38
+ }
39
+ }
40
+ const hex = (buffer) => {
41
+ const res = Buffer.alloc(buffer.length * 6, " 0x00,");
42
+ for (let i = 0; i < buffer.length; i++) {
43
+ if (i % 16 === 0) {
44
+ res.write("\n", i * 6, "ascii");
45
+ }
46
+ const byte = buffer.at(i);
47
+ res.write(byte.toString(16), i * 6 + (byte >= 16 ? 3 : 4), "ascii");
48
+ }
49
+ return res;
50
+ };
51
+ class CountTransform extends Transform {
52
+ length = 0;
53
+ constructor() {
54
+ super({
55
+ objectMode: false
56
+ });
57
+ }
58
+ _transform(chunk, encoding, callback) {
59
+ chunk = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding);
60
+ this.length += chunk.length;
61
+ callback(null, chunk);
62
+ }
63
+ }
64
+ class HexTransform extends CountTransform {
65
+ _transform(chunk, encoding, callback) {
66
+ super._transform(chunk, encoding, (err, data) => callback(err, hex(data)));
67
+ }
68
+ }
69
+ class HexCVarTransform extends HexTransform {
70
+ #varName;
71
+ #static;
72
+ constructor(varName, isStatic) {
73
+ super();
74
+ this.#varName = varName;
75
+ this.#static = isStatic;
76
+ this.push(`${this.#static ? "static " : ""}uint8_t ${this.#varName}[] = {`);
77
+ }
78
+ _flush(callback) {
79
+ this.push(`};
80
+ ${this.#static ? "static " : ""}size_t ${this.#varName}_len = 0x${this.length.toString(16)};
81
+ `);
82
+ callback();
83
+ }
84
+ }
85
+ class CodeBuilder {
86
+ #varCounter = 0;
87
+ #blocks = /* @__PURE__ */ new Map();
88
+ #alreadyIncluded = /* @__PURE__ */ new Map();
89
+ curBlock = "main";
90
+ constructor(header = "") {
91
+ this.#blocks.set(this.curBlock, new StringBuilder());
92
+ this.write(header);
93
+ this.writeNewBlock("headers");
94
+ this.writeNewBlock("global");
95
+ }
96
+ changeCurBlock(curBlock, fn) {
97
+ const savedCurBlock = this.curBlock;
98
+ try {
99
+ this.curBlock = curBlock;
100
+ fn();
101
+ } finally {
102
+ this.curBlock = savedCurBlock;
103
+ }
104
+ }
105
+ newVar() {
106
+ return `var${this.#varCounter++}`;
107
+ }
108
+ write(code, blockName = this.curBlock) {
109
+ this.#blocks.get(blockName).write(code);
110
+ }
111
+ writeNewBlock(newBlockName, blockName = this.curBlock) {
112
+ const newBlock = new StringBuilder();
113
+ if (this.#blocks.has(newBlockName)) {
114
+ throw new Error(`Block ${newBlockName} already exists!`);
115
+ }
116
+ this.#blocks.set(newBlockName, newBlock);
117
+ this.write(newBlock, blockName);
118
+ }
119
+ createBinaryVar(content, varName, blockName = "global") {
120
+ const isStatic = !varName;
121
+ if (!varName) {
122
+ varName = this.newVar();
123
+ }
124
+ const readable = Buffer.isBuffer(content) ? Readable.from(content) : content;
125
+ this.write(readable.pipe(new HexCVarTransform(varName, isStatic)), blockName);
126
+ return varName;
127
+ }
128
+ insertOnce(name, fn) {
129
+ let data = this.#alreadyIncluded.get(name);
130
+ if (!data) {
131
+ data = {};
132
+ this.#alreadyIncluded.set(name, data);
133
+ fn(data);
134
+ }
135
+ return data;
136
+ }
137
+ addHeader(header) {
138
+ const headerCode = `#include ${header}
139
+ `;
140
+ this.insertOnce(header, () => {
141
+ this.write(headerCode, "headers");
142
+ });
143
+ }
144
+ toReadable() {
145
+ return this.#blocks.get("main").toReadable();
146
+ }
147
+ }
148
+ const reorderHash = (hash) => {
149
+ for (let i = 0; i < 8; i++) {
150
+ hash.writeUint32LE(hash.readUInt32BE(i * 4), i * 4);
151
+ }
152
+ return hash;
153
+ };
154
+ const reorderUUID = (buffer) => {
155
+ buffer.writeUint32LE(buffer.readUInt32BE(0), 0);
156
+ buffer.writeUint16LE(buffer.readUInt16BE(4), 4);
157
+ buffer.writeUint16LE(buffer.readUInt16BE(6), 6);
158
+ return buffer;
159
+ };
160
+ const uuidRegExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
161
+ const parseUUID = (uuid) => {
162
+ if (!uuidRegExp.test(uuid)) {
163
+ throw new Error("Invalid UUID");
164
+ }
165
+ return reorderUUID(Buffer.from(uuid.replaceAll("-", ""), "hex"));
166
+ };
167
+ const fail = (msg) => {
168
+ throw new Error(msg);
169
+ };
170
+ const hashData = async (hash, binaryData) => {
171
+ if (binaryData.type === "missing") {
172
+ return binaryData.size ?? 1;
173
+ }
174
+ if (binaryData.type === "file") {
175
+ const count = new CountTransform();
176
+ const start = binaryData.offset ?? 0;
177
+ await pipeline(
178
+ createReadStream(binaryData.file, {
179
+ start,
180
+ end: binaryData.size != null ? start + binaryData.size - 1 : Infinity
181
+ }),
182
+ count,
183
+ hash,
184
+ { end: false }
185
+ );
186
+ return count.length;
187
+ }
188
+ const buffer = binaryData.type === "buffer" ? binaryData.buffer : Buffer.from(binaryData.buffer, binaryData.type);
189
+ hash.update(buffer);
190
+ return buffer.length;
191
+ };
192
+ const codeBlockDiskSectorVar = (codeBuilder) => {
193
+ codeBuilder.insertOnce(`diskSector`, () => {
194
+ codeBuilder.write(`UINT8 *diskSector = NULL;
195
+ `, "gen_compute_hash_vars");
196
+ });
197
+ };
198
+ const codeBlockProtocolGuid = (codeBuilder, protocolName) => {
199
+ codeBuilder.insertOnce(`GUID_${protocolName}`, () => {
200
+ codeBuilder.insertOnce("guidVars", () => codeBuilder.writeNewBlock("guidVars", "gen_compute_hash_vars"));
201
+ codeBuilder.write(`EFI_GUID GUID_${protocolName} = EFI_${protocolName}_PROTOCOL_GUID;
202
+ `, "guidVars");
203
+ });
204
+ };
205
+ const codeBlockLoadedImage = (codeBuilder) => {
206
+ codeBuilder.insertOnce("loadedImage", () => {
207
+ codeBlockProtocolGuid(codeBuilder, "LOADED_IMAGE");
208
+ codeBuilder.write("EFI_LOADED_IMAGE_PROTOCOL *loadedImage = NULL;\n", "gen_compute_hash_vars");
209
+ codeBuilder.write(
210
+ `HANDLE_PROTOCOL(image_handle, GUID_LOADED_IMAGE, &loadedImage);
211
+ CHECK_ERROR(!loadedImage);
212
+ `,
213
+ "gen_compute_hash_prep"
214
+ );
215
+ });
216
+ };
217
+ const codeBlockDevicePathToText = (codeBuilder) => {
218
+ codeBuilder.insertOnce("devicePathToText", () => {
219
+ codeBlockProtocolGuid(codeBuilder, "DEVICE_PATH_TO_TEXT");
220
+ codeBuilder.write("EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *devicePathToText = NULL;\n", "gen_compute_hash_vars");
221
+ codeBuilder.write(
222
+ `status = uefi_call_wrapper(gBS->LocateProtocol, 3, &GUID_DEVICE_PATH_TO_TEXT, NULL, &devicePathToText);
223
+ CHECK_ERROR(!devicePathToText);
224
+ `,
225
+ "gen_compute_hash_prep"
226
+ );
227
+ });
228
+ };
229
+ const codeBlockBootPartitionDevice = (codeBuilder) => {
230
+ codeBuilder.insertOnce("bootPartitionDevice", () => {
231
+ codeBlockLoadedImage(codeBuilder);
232
+ codeBlockDevicePathToText(codeBuilder);
233
+ codeBlockProtocolGuid(codeBuilder, "DEVICE_PATH");
234
+ codeBuilder.write("EFI_DEVICE_PATH_PROTOCOL *bootDevice = NULL;\n", "gen_compute_hash_vars");
235
+ codeBuilder.write(
236
+ `HANDLE_PROTOCOL(loadedImage->DeviceHandle, GUID_DEVICE_PATH, &bootDevice);
237
+ CHECK_ERROR(!bootDevice);
238
+ CHAR16 *bootPartitionDeviceString = (void *)uefi_call_wrapper(devicePathToText->ConvertDevicePathToText, 3, bootDevice, FALSE, FALSE);
239
+ CHECK_ERROR(!bootPartitionDeviceString);
240
+ UINTN bootPartitionDeviceStringLen = 2 * RtStrLen(bootPartitionDeviceString);
241
+ `,
242
+ "gen_compute_hash_prep"
243
+ );
244
+ });
245
+ };
246
+ const codeBlockBootFile = (codeBuilder) => {
247
+ codeBuilder.insertOnce("bootFile", () => {
248
+ codeBlockLoadedImage(codeBuilder);
249
+ codeBlockDevicePathToText(codeBuilder);
250
+ codeBuilder.write(
251
+ `CHAR16 *bootFileString = (void *)uefi_call_wrapper(devicePathToText->ConvertDevicePathToText, 3, loadedImage->FilePath, FALSE, FALSE);
252
+ CHECK_ERROR(!bootFileString);
253
+ UINTN bootFileStringLen = 2 * RtStrLen(bootFileString);
254
+ `,
255
+ "gen_compute_hash_prep"
256
+ );
257
+ });
258
+ };
259
+ const codeBlockFindBlock = (codeBuilder) => codeBuilder.insertOnce("findBlock", (data) => {
260
+ data.salt = randomBytes(32);
261
+ const saltVarName = codeBuilder.createBinaryVar(data.salt);
262
+ codeBlockProtocolGuid(codeBuilder, "DEVICE_PATH");
263
+ codeBlockProtocolGuid(codeBuilder, "BLOCK_IO");
264
+ codeBuilder.write(
265
+ `UINTN blockIONbHandles = 0;
266
+ EFI_HANDLE *blockIOHandles = NULL;
267
+ status = uefi_call_wrapper(gBS->LocateHandleBuffer, 5, ByProtocol, &GUID_BLOCK_IO, NULL, &blockIONbHandles, &blockIOHandles);
268
+ CHECK_ERROR(0);
269
+ for (UINTN i = 0; i < blockIONbHandles; i++)
270
+ {
271
+ EFI_BLOCK_IO_PROTOCOL *bio = NULL;
272
+ HANDLE_PROTOCOL(blockIOHandles[i], GUID_BLOCK_IO, &bio);
273
+ if (EFI_ERROR(status) || !bio || !bio->Media->BlockSize)
274
+ continue;
275
+ EFI_DEVICE_PATH_PROTOCOL *devPath = NULL;
276
+ HANDLE_PROTOCOL(blockIOHandles[i], GUID_DEVICE_PATH, &devPath);
277
+ if (EFI_ERROR(status) || !devPath)
278
+ continue;
279
+ CHAR16 *devPathString = (void *)uefi_call_wrapper(devicePathToText->ConvertDevicePathToText, 3, devPath, FALSE, FALSE);
280
+ if (!devPathString)
281
+ continue;
282
+ UINTN devPathStringLen = 2 * RtStrLen(devPathString);
283
+ if (devPathStringLen)
284
+ {
285
+ sha256_context_t devPathStringHash;
286
+ sha256_init(&devPathStringHash);
287
+ sha256_update(&devPathStringHash, ${saltVarName}, ${saltVarName}_len);
288
+ sha256_update(&devPathStringHash, (void*)devPathString, devPathStringLen);
289
+ sha256_finalize(&devPathStringHash);
290
+ `
291
+ );
292
+ codeBuilder.writeNewBlock("blockIOHandlesTestDevice");
293
+ codeBuilder.write(`
294
+ }
295
+ }
296
+ FREE_POOL(blockIOHandles);
297
+ `);
298
+ });
299
+ const codeBlockGetDeviceHandle = (codeBuilder, device) => codeBuilder.insertOnce(`deviceHandle:${device ?? ""}`, (data) => {
300
+ data.varName = codeBuilder.newVar();
301
+ codeBuilder.write(
302
+ `EFI_HANDLE ${data.varName}_handle = NULL;
303
+ EFI_BLOCK_IO_PROTOCOL *${data.varName}_bio = NULL;
304
+ UINT64 ${data.varName}_size = 0;
305
+ CHAR16 *${data.varName}_devPathString = NULL;
306
+ UINTN ${data.varName}_devPathStringLen = 0;
307
+ `,
308
+ "gen_compute_hash_vars"
309
+ );
310
+ const { salt } = codeBlockFindBlock(codeBuilder);
311
+ let condition;
312
+ if (device) {
313
+ const hashVar = codeBuilder.createBinaryVar(reorderHash(createHash("sha256").update(salt).update(device, "utf16le").digest()));
314
+ condition = `RtCompareMem(devPathStringHash.hash, ${hashVar}, 32) == 0`;
315
+ } else {
316
+ codeBlockBootPartitionDevice(codeBuilder);
317
+ condition = `!bio->Media->LogicalPartition && devPathStringLen && devPathStringLen <= bootPartitionDeviceStringLen && RtCompareMem(devPathString, bootPartitionDeviceString, devPathStringLen) == 0`;
318
+ }
319
+ codeBuilder.write(
320
+ `if (${condition}) {
321
+ ${data.varName}_handle = blockIOHandles[i];
322
+ ${data.varName}_bio = bio;
323
+ ${data.varName}_devPathString = devPathString;
324
+ ${data.varName}_devPathStringLen = devPathStringLen;
325
+ ${data.varName}_size = ((bio->Media->LastBlock + 1) * bio->Media->BlockSize);
326
+ }
327
+ `,
328
+ "blockIOHandlesTestDevice"
329
+ );
330
+ });
331
+ const codeBlockGetDeviceDiskIO = (codeBuilder, device) => codeBuilder.insertOnce(`deviceDiskIO:${device ?? ""}`, (data) => {
332
+ data.varName = codeBlockGetDeviceHandle(codeBuilder, device).varName;
333
+ codeBlockProtocolGuid(codeBuilder, "DISK_IO");
334
+ codeBuilder.write(`EFI_DISK_IO_PROTOCOL *${data.varName}_dio = NULL;
335
+ `, "gen_compute_hash_vars");
336
+ codeBuilder.write(`if (${data.varName}_handle) { HANDLE_PROTOCOL(${data.varName}_handle, GUID_DISK_IO, &${data.varName}_dio); }
337
+ `);
338
+ });
339
+ const codeBlockGetDeviceVolume = (codeBuilder, device) => codeBuilder.insertOnce(`deviceVolume:${device ?? ""}`, (data) => {
340
+ let handleVariable;
341
+ if (device) {
342
+ data.varName = codeBlockGetDeviceHandle(codeBuilder, device).varName;
343
+ handleVariable = `${data.varName}_handle`;
344
+ } else {
345
+ codeBlockLoadedImage(codeBuilder);
346
+ data.varName = "efiDevice";
347
+ handleVariable = "loadedImage->DeviceHandle";
348
+ }
349
+ codeBlockProtocolGuid(codeBuilder, "SIMPLE_FILE_SYSTEM");
350
+ codeBuilder.write(`EFI_FILE_IO_INTERFACE *${data.varName}_fio = NULL;
351
+ `, "gen_compute_hash_vars");
352
+ codeBuilder.write(`EFI_FILE_HANDLE ${data.varName}_volume = NULL;
353
+ `, "gen_compute_hash_vars");
354
+ codeBuilder.write(`if (${handleVariable}) {
355
+ HANDLE_PROTOCOL(${handleVariable}, GUID_SIMPLE_FILE_SYSTEM, &${data.varName}_fio);
356
+ if (${data.varName}_fio) {
357
+ uefi_call_wrapper(${data.varName}_fio->OpenVolume, 2, ${data.varName}_fio, &${data.varName}_volume);
358
+ }
359
+ }
360
+ `);
361
+ });
362
+ const codeBlockGetFile = (codeBuilder, file, device) => codeBuilder.insertOnce(`file:${device ?? ""}:${file}`, (data) => {
363
+ data.varName = codeBuilder.newVar();
364
+ const { varName: deviceVar } = codeBlockGetDeviceVolume(codeBuilder, device);
365
+ codeBuilder.write(`EFI_FILE_HANDLE ${data.varName}_handle = NULL;
366
+ `, "gen_compute_hash_vars");
367
+ codeBuilder.write(`EFI_FILE_INFO *${data.varName}_fileInfo = NULL;
368
+ `, "gen_compute_hash_vars");
369
+ codeBuilder.write(`if (${deviceVar}_volume) {
370
+ uefi_call_wrapper(${deviceVar}_volume->Open, 5, ${deviceVar}_volume, &${data.varName}_handle, L${JSON.stringify(file)}, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
371
+ if (${data.varName}_handle) {
372
+ ${data.varName}_fileInfo = LibFileInfo(${data.varName}_handle);
373
+ }
374
+ }
375
+ `);
376
+ });
377
+ const handlers = {
378
+ random({ hash, codeBuilder, hashComponent }) {
379
+ const secret = randomBytes(hashComponent.length);
380
+ hash.update(secret);
381
+ const secretVar = codeBuilder.createBinaryVar(secret);
382
+ codeBuilder.write(`sha256_update(hash, ${secretVar}, ${secretVar}_len);
383
+ `);
384
+ },
385
+ smbios({ hash, codeBuilder, hashComponent, smbios }) {
386
+ const fieldRef = resolveSmbiosField(hashComponent.ref);
387
+ const value = hashComponent.value ?? getSmbiosField(smbios ?? fail("Missing SMBIOS information"), fieldRef);
388
+ if (value) {
389
+ if (typeof value === "string" && fieldRef.type != "string") {
390
+ if (fieldRef.type === "uuid") {
391
+ hash.update(parseUUID(value));
392
+ } else {
393
+ hash.update(Buffer.from(value, "hex"));
394
+ }
395
+ } else {
396
+ hash.update(value);
397
+ }
398
+ if (fieldRef.type === "string") {
399
+ hash.update("\0");
400
+ }
401
+ }
402
+ codeBuilder.addHeader('"smbios.h"');
403
+ if ("type" in fieldRef.table) {
404
+ codeBuilder.write(
405
+ `status = smbios_hashValue(hash, 0, ${fieldRef.table.type}, ${fieldRef.table.index ?? 0}, ${fieldRef.offset}, ${fieldRef.type === "string" ? 0 : smbiosDataTypeSize[fieldRef.type]});
406
+ `
407
+ );
408
+ } else {
409
+ codeBuilder.write(
410
+ `status = smbios_hashValue(hash, 1, ${fieldRef.table.handle & 255}, ${fieldRef.table.handle >> 8 & 255}, ${fieldRef.offset}, ${fieldRef.type === "string" ? 0 : smbiosDataTypeSize[fieldRef.type]});
411
+ `
412
+ );
413
+ }
414
+ codeBuilder.write("CHECK_ERROR(0);\n");
415
+ },
416
+ "boot-partition-device"({ hash, codeBuilder, hashComponent }) {
417
+ hash.update(Buffer.from(hashComponent.value, "utf16le"));
418
+ hash.update("\0\0");
419
+ codeBlockBootPartitionDevice(codeBuilder);
420
+ codeBuilder.write(`sha256_update(hash, (void*)bootPartitionDeviceString, bootPartitionDeviceStringLen + 2);
421
+ `);
422
+ },
423
+ "boot-hd-device"({ hash, codeBuilder, hashComponent }) {
424
+ hash.update(Buffer.from(hashComponent.value, "utf16le"));
425
+ hash.update("\0\0");
426
+ const { varName } = codeBlockGetDeviceHandle(codeBuilder);
427
+ codeBuilder.write(`if (${varName}_devPathString) sha256_update(hash, (void*)${varName}_devPathString, ${varName}_devPathStringLen + 2);
428
+ `);
429
+ },
430
+ "boot-file"({ hash, codeBuilder, hashComponent }) {
431
+ hash.update(Buffer.from(hashComponent.value, "utf16le"));
432
+ hash.update("\0\0");
433
+ codeBlockBootFile(codeBuilder);
434
+ codeBuilder.write(`sha256_update(hash, (void*)bootFileString, bootFileStringLen + 2);
435
+ `);
436
+ },
437
+ "hd-size"({ hash, codeBuilder, hashComponent }) {
438
+ if (hashComponent.value !== "missing") {
439
+ const size = Buffer.alloc(8);
440
+ size.writeBigUInt64LE(BigInt(hashComponent.value));
441
+ hash.update(size);
442
+ }
443
+ const { varName } = codeBlockGetDeviceHandle(codeBuilder, hashComponent.device);
444
+ codeBuilder.write(`if (${varName}_bio) sha256_update(hash, (void*)&${varName}_size, sizeof ${varName}_size);
445
+ `);
446
+ },
447
+ async "hd-data"({ hash, codeBuilder, hashComponent }) {
448
+ const size = await hashData(hash, hashComponent.value);
449
+ codeBlockDiskSectorVar(codeBuilder);
450
+ const { varName } = codeBlockGetDeviceDiskIO(codeBuilder, hashComponent.device);
451
+ const offset = BigInt(hashComponent.offset);
452
+ const startPos = hashComponent.offsetRef === "start" ? offset : `${varName}_size - ${offset} - ${size}`;
453
+ codeBuilder.write(`if (${varName}_dio && ${offset} + ${size} <= ${varName}_size) {
454
+ diskSector = AllocatePool(${size});
455
+ if (diskSector) {
456
+ status = uefi_call_wrapper(${varName}_dio->ReadDisk, 5, ${varName}_dio, ${varName}_bio->Media->MediaId, ${startPos}, ${size}, diskSector);
457
+ if (!EFI_ERROR(status)) {
458
+ sha256_update(hash, diskSector, ${size});
459
+ }
460
+ FREE_POOL(diskSector);
461
+ }
462
+ }
463
+ `);
464
+ },
465
+ "file-size"({ hash, codeBuilder, hashComponent }) {
466
+ if (hashComponent.value !== "missing") {
467
+ const size = Buffer.alloc(8);
468
+ size.writeBigUInt64LE(BigInt(hashComponent.value));
469
+ hash.update(size);
470
+ }
471
+ const { varName } = codeBlockGetFile(codeBuilder, hashComponent.file, hashComponent.device);
472
+ codeBuilder.write(`if (${varName}_fileInfo) sha256_update(hash, (void*)&${varName}_fileInfo->FileSize, 8);
473
+ `);
474
+ },
475
+ async "file-data"({ hash, codeBuilder, hashComponent }) {
476
+ const size = await hashData(hash, hashComponent.value);
477
+ codeBlockDiskSectorVar(codeBuilder);
478
+ const { varName } = codeBlockGetFile(codeBuilder, hashComponent.file, hashComponent.device);
479
+ const ref = hashComponent.offsetRef ?? "full";
480
+ const offset = BigInt(ref === "full" ? 0 : hashComponent.offset ?? "0");
481
+ const startPos = ref === "end" ? `${varName}_fileInfo->FileSize - ${offset} - ${size}` : offset;
482
+ codeBuilder.write(`if (${varName}_fileInfo) {
483
+ UINT64 size = ${ref === "full" ? `${varName}_fileInfo->FileSize` : size};
484
+ if (size + ${hashComponent.offset ?? 0} <= ${varName}_fileInfo->FileSize) {
485
+ diskSector = AllocatePool(size);
486
+ if (diskSector) {
487
+ status = uefi_call_wrapper(${varName}_handle->SetPosition, 2, ${varName}_handle, ${startPos});
488
+ if (!EFI_ERROR(status)) {
489
+ status = uefi_call_wrapper(${varName}_handle->Read, 3, ${varName}_handle, &size, diskSector);
490
+ if (!EFI_ERROR(status)) {
491
+ sha256_update(hash, diskSector, size);
492
+ }
493
+ }
494
+ FREE_POOL(diskSector);
495
+ }
496
+ }
497
+ }
498
+ `);
499
+ }
500
+ };
501
+ const genCode = async (config) => {
502
+ const codeBuilder = new CodeBuilder("/*\n * DO NOT EDIT! This file was generated automatically!\n */\n");
503
+ codeBuilder.addHeader('"gen-code.h"');
504
+ codeBuilder.write(
505
+ `EFI_STATUS gen_compute_hash(sha256_context_t *hash, EFI_HANDLE image_handle) {
506
+ EFI_STATUS status = 0;
507
+ `
508
+ );
509
+ codeBuilder.writeNewBlock("gen_compute_hash_vars");
510
+ codeBuilder.writeNewBlock("gen_compute_hash_prep");
511
+ codeBuilder.writeNewBlock("gen_compute_hash");
512
+ codeBuilder.write("return status;\n}\n");
513
+ codeBuilder.curBlock = "gen_compute_hash";
514
+ const hash = createHash("sha256");
515
+ const smbios = config.smbios ? parseSmbios(await readFile(config.smbios)) : void 0;
516
+ for (const hashComponent of config.hashComponents) {
517
+ const handler = handlers[hashComponent.type];
518
+ await handler({ hashComponent, codeBuilder, config, hash, smbios });
519
+ }
520
+ const iv = randomBytes(16);
521
+ codeBuilder.createBinaryVar(iv, "iv");
522
+ const cipher = createCipheriv("aes-256-cbc", reorderHash(hash.digest()), iv);
523
+ codeBuilder.createBinaryVar(createReadStream(config.inputFile).pipe(cipher), "enc_payload");
524
+ await pipeline(codeBuilder.toReadable(), createWriteStream(join(config.buildFolder, "gen-code.c")));
525
+ };
526
+ const validate = validate10;
527
+ const schema11 = { "properties": { "$schema": { "type": "string" }, "inputFile": { "description": "Path to the input efi file to embed.", "type": "string" }, "outputFile": { "description": "Path to the output efi file to write.", "type": "string" }, "skipGenCode": { "description": "Whether to skip generating code", "type": "boolean" }, "skipExtract": { "description": "Whether to skip extracting source code\n(can be useful if the extraction was already done)", "type": "boolean" }, "skipMake": { "description": "Whether to skip calling make\n(can be useful to change the code before calling make)", "type": "boolean" }, "buildFolder": { "description": "Folder where to build the code.\nDefaults to a temporary folder that is removed when the build is finished.", "type": "string" }, "hashComponents": { "description": "Data to include in the hash for encryption.", "type": "array", "items": { "$ref": "#/definitions/HashComponent" } }, "smbios": { "description": "Path to the input smbios dump file.\nCan be produced by: dmidecode --dump-bin <filePath>", "type": "string" } } };
528
+ const func2 = Object.prototype.hasOwnProperty;
529
+ const schema32 = { "properties": { "type": { "enum": ["boot-file", "boot-hd-device", "boot-partition-device"] } } };
530
+ const schema15 = { "anyOf": [{ "type": "object", "properties": { "table": { "$ref": "#/definitions/SmbiosTableRef" }, "offset": { "type": "number" }, "type": { "enum": ["byte", "dword", "qword", "string", "uuid", "word"], "type": "string" } }, "additionalProperties": false, "required": ["offset", "table", "type"] }, { "enum": ["baseboard-asset-tag", "baseboard-manufacturer", "baseboard-product-name", "baseboard-serial-number", "baseboard-version", "bios-release-date", "bios-revision", "bios-vendor", "bios-version", "chassis-asset-tag", "chassis-manufacturer", "chassis-serial-number", "chassis-version", "processor-manufacturer", "processor-version", "system-family", "system-manufacturer", "system-product-name", "system-serial-number", "system-sku-number", "system-uuid", "system-version"], "type": "string" }] };
531
+ const schema16 = { "anyOf": [{ "type": "object", "properties": { "handle": { "type": "number" } }, "additionalProperties": false, "required": ["handle"] }, { "type": "object", "properties": { "type": { "type": "number" }, "index": { "type": "number" } }, "additionalProperties": false, "required": ["type"] }, { "enum": ["32-bit Memory Error", "64-bit Memory Error", "Additional Information", "Baseboard", "Boot Integrity Services", "Built-in Pointing Device", "Cache", "Chassis", "Cooling Device", "Electrical Current Probe", "Firmware Inventory", "Firmware Language", "Group Associations", "Hardware Security", "IPMI Device", "Management Controller Host Interface", "Management Device", "Management Device Component", "Management Device Threshold Data", "Memory Array Mapped Address", "Memory Channel", "Memory Controller", "Memory Device", "Memory Device Mapped Address", "Memory Module", "OEM Strings", "Onboard Devices", "Onboard Devices Extended Information", "Out-of-band Remote Access", "Physical Memory Array", "Platform Firmware", "Port Connector", "Portable Battery", "Power Supply", "Processor", "Processor Additional Information", "String Property", "System", "System Boot", "System Configuration Options", "System Event Log", "System Power Controls", "System Reset", "System Slots", "TPM Device", "Temperature Probe", "Voltage Probe"], "type": "string" }, { "type": "number" }] };
532
+ function validate13(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
533
+ let vErrors = null;
534
+ let errors = 0;
535
+ const _errs0 = errors;
536
+ let valid0 = false;
537
+ const _errs1 = errors;
538
+ if (errors === _errs1) {
539
+ if (data && typeof data == "object" && !Array.isArray(data)) {
540
+ let missing0;
541
+ if (data.offset === void 0 && (missing0 = "offset") || data.table === void 0 && (missing0 = "table") || data.type === void 0 && (missing0 = "type")) {
542
+ const err0 = { instancePath, schemaPath: "#/anyOf/0/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" };
543
+ if (vErrors === null) {
544
+ vErrors = [err0];
545
+ } else {
546
+ vErrors.push(err0);
547
+ }
548
+ errors++;
549
+ } else {
550
+ const _errs3 = errors;
551
+ for (const key0 in data) {
552
+ if (!(key0 === "table" || key0 === "offset" || key0 === "type")) {
553
+ const err1 = { instancePath, schemaPath: "#/anyOf/0/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
554
+ if (vErrors === null) {
555
+ vErrors = [err1];
556
+ } else {
557
+ vErrors.push(err1);
558
+ }
559
+ errors++;
560
+ break;
561
+ }
562
+ }
563
+ if (_errs3 === errors) {
564
+ if (data.table !== void 0) {
565
+ let data0 = data.table;
566
+ const _errs4 = errors;
567
+ const _errs6 = errors;
568
+ let valid3 = false;
569
+ const _errs7 = errors;
570
+ if (errors === _errs7) {
571
+ if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
572
+ let missing1;
573
+ if (data0.handle === void 0 && (missing1 = "handle")) {
574
+ const err2 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/0/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" };
575
+ if (vErrors === null) {
576
+ vErrors = [err2];
577
+ } else {
578
+ vErrors.push(err2);
579
+ }
580
+ errors++;
581
+ } else {
582
+ const _errs9 = errors;
583
+ for (const key1 in data0) {
584
+ if (!(key1 === "handle")) {
585
+ const err3 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/0/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key1 }, message: "must NOT have additional properties" };
586
+ if (vErrors === null) {
587
+ vErrors = [err3];
588
+ } else {
589
+ vErrors.push(err3);
590
+ }
591
+ errors++;
592
+ break;
593
+ }
594
+ }
595
+ if (_errs9 === errors) {
596
+ if (data0.handle !== void 0) {
597
+ let data1 = data0.handle;
598
+ if (!(typeof data1 == "number" && isFinite(data1))) {
599
+ const err4 = { instancePath: instancePath + "/table/handle", schemaPath: "#/definitions/SmbiosTableRef/anyOf/0/properties/handle/type", keyword: "type", params: { type: "number" }, message: "must be number" };
600
+ if (vErrors === null) {
601
+ vErrors = [err4];
602
+ } else {
603
+ vErrors.push(err4);
604
+ }
605
+ errors++;
606
+ }
607
+ }
608
+ }
609
+ }
610
+ } else {
611
+ const err5 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/0/type", keyword: "type", params: { type: "object" }, message: "must be object" };
612
+ if (vErrors === null) {
613
+ vErrors = [err5];
614
+ } else {
615
+ vErrors.push(err5);
616
+ }
617
+ errors++;
618
+ }
619
+ }
620
+ var _valid1 = _errs7 === errors;
621
+ valid3 = valid3 || _valid1;
622
+ if (!valid3) {
623
+ const _errs12 = errors;
624
+ if (errors === _errs12) {
625
+ if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
626
+ let missing2;
627
+ if (data0.type === void 0 && (missing2 = "type")) {
628
+ const err6 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/1/required", keyword: "required", params: { missingProperty: missing2 }, message: "must have required property '" + missing2 + "'" };
629
+ if (vErrors === null) {
630
+ vErrors = [err6];
631
+ } else {
632
+ vErrors.push(err6);
633
+ }
634
+ errors++;
635
+ } else {
636
+ const _errs14 = errors;
637
+ for (const key2 in data0) {
638
+ if (!(key2 === "type" || key2 === "index")) {
639
+ const err7 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/1/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key2 }, message: "must NOT have additional properties" };
640
+ if (vErrors === null) {
641
+ vErrors = [err7];
642
+ } else {
643
+ vErrors.push(err7);
644
+ }
645
+ errors++;
646
+ break;
647
+ }
648
+ }
649
+ if (_errs14 === errors) {
650
+ if (data0.type !== void 0) {
651
+ let data2 = data0.type;
652
+ const _errs15 = errors;
653
+ if (!(typeof data2 == "number" && isFinite(data2))) {
654
+ const err8 = { instancePath: instancePath + "/table/type", schemaPath: "#/definitions/SmbiosTableRef/anyOf/1/properties/type/type", keyword: "type", params: { type: "number" }, message: "must be number" };
655
+ if (vErrors === null) {
656
+ vErrors = [err8];
657
+ } else {
658
+ vErrors.push(err8);
659
+ }
660
+ errors++;
661
+ }
662
+ var valid5 = _errs15 === errors;
663
+ } else {
664
+ var valid5 = true;
665
+ }
666
+ if (valid5) {
667
+ if (data0.index !== void 0) {
668
+ let data3 = data0.index;
669
+ const _errs17 = errors;
670
+ if (!(typeof data3 == "number" && isFinite(data3))) {
671
+ const err9 = { instancePath: instancePath + "/table/index", schemaPath: "#/definitions/SmbiosTableRef/anyOf/1/properties/index/type", keyword: "type", params: { type: "number" }, message: "must be number" };
672
+ if (vErrors === null) {
673
+ vErrors = [err9];
674
+ } else {
675
+ vErrors.push(err9);
676
+ }
677
+ errors++;
678
+ }
679
+ var valid5 = _errs17 === errors;
680
+ } else {
681
+ var valid5 = true;
682
+ }
683
+ }
684
+ }
685
+ }
686
+ } else {
687
+ const err10 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/1/type", keyword: "type", params: { type: "object" }, message: "must be object" };
688
+ if (vErrors === null) {
689
+ vErrors = [err10];
690
+ } else {
691
+ vErrors.push(err10);
692
+ }
693
+ errors++;
694
+ }
695
+ }
696
+ var _valid1 = _errs12 === errors;
697
+ valid3 = valid3 || _valid1;
698
+ if (!valid3) {
699
+ const _errs19 = errors;
700
+ if (typeof data0 !== "string") {
701
+ const err11 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/2/type", keyword: "type", params: { type: "string" }, message: "must be string" };
702
+ if (vErrors === null) {
703
+ vErrors = [err11];
704
+ } else {
705
+ vErrors.push(err11);
706
+ }
707
+ errors++;
708
+ }
709
+ if (!(data0 === "32-bit Memory Error" || data0 === "64-bit Memory Error" || data0 === "Additional Information" || data0 === "Baseboard" || data0 === "Boot Integrity Services" || data0 === "Built-in Pointing Device" || data0 === "Cache" || data0 === "Chassis" || data0 === "Cooling Device" || data0 === "Electrical Current Probe" || data0 === "Firmware Inventory" || data0 === "Firmware Language" || data0 === "Group Associations" || data0 === "Hardware Security" || data0 === "IPMI Device" || data0 === "Management Controller Host Interface" || data0 === "Management Device" || data0 === "Management Device Component" || data0 === "Management Device Threshold Data" || data0 === "Memory Array Mapped Address" || data0 === "Memory Channel" || data0 === "Memory Controller" || data0 === "Memory Device" || data0 === "Memory Device Mapped Address" || data0 === "Memory Module" || data0 === "OEM Strings" || data0 === "Onboard Devices" || data0 === "Onboard Devices Extended Information" || data0 === "Out-of-band Remote Access" || data0 === "Physical Memory Array" || data0 === "Platform Firmware" || data0 === "Port Connector" || data0 === "Portable Battery" || data0 === "Power Supply" || data0 === "Processor" || data0 === "Processor Additional Information" || data0 === "String Property" || data0 === "System" || data0 === "System Boot" || data0 === "System Configuration Options" || data0 === "System Event Log" || data0 === "System Power Controls" || data0 === "System Reset" || data0 === "System Slots" || data0 === "TPM Device" || data0 === "Temperature Probe" || data0 === "Voltage Probe")) {
710
+ const err12 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/2/enum", keyword: "enum", params: { allowedValues: schema16.anyOf[2].enum }, message: "must be equal to one of the allowed values" };
711
+ if (vErrors === null) {
712
+ vErrors = [err12];
713
+ } else {
714
+ vErrors.push(err12);
715
+ }
716
+ errors++;
717
+ }
718
+ var _valid1 = _errs19 === errors;
719
+ valid3 = valid3 || _valid1;
720
+ if (!valid3) {
721
+ const _errs21 = errors;
722
+ if (!(typeof data0 == "number" && isFinite(data0))) {
723
+ const err13 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf/3/type", keyword: "type", params: { type: "number" }, message: "must be number" };
724
+ if (vErrors === null) {
725
+ vErrors = [err13];
726
+ } else {
727
+ vErrors.push(err13);
728
+ }
729
+ errors++;
730
+ }
731
+ var _valid1 = _errs21 === errors;
732
+ valid3 = valid3 || _valid1;
733
+ }
734
+ }
735
+ }
736
+ if (!valid3) {
737
+ const err14 = { instancePath: instancePath + "/table", schemaPath: "#/definitions/SmbiosTableRef/anyOf", keyword: "anyOf", params: {}, message: "must match a schema in anyOf" };
738
+ if (vErrors === null) {
739
+ vErrors = [err14];
740
+ } else {
741
+ vErrors.push(err14);
742
+ }
743
+ errors++;
744
+ } else {
745
+ errors = _errs6;
746
+ if (vErrors !== null) {
747
+ if (_errs6) {
748
+ vErrors.length = _errs6;
749
+ } else {
750
+ vErrors = null;
751
+ }
752
+ }
753
+ }
754
+ var valid1 = _errs4 === errors;
755
+ } else {
756
+ var valid1 = true;
757
+ }
758
+ if (valid1) {
759
+ if (data.offset !== void 0) {
760
+ let data4 = data.offset;
761
+ const _errs23 = errors;
762
+ if (!(typeof data4 == "number" && isFinite(data4))) {
763
+ const err15 = { instancePath: instancePath + "/offset", schemaPath: "#/anyOf/0/properties/offset/type", keyword: "type", params: { type: "number" }, message: "must be number" };
764
+ if (vErrors === null) {
765
+ vErrors = [err15];
766
+ } else {
767
+ vErrors.push(err15);
768
+ }
769
+ errors++;
770
+ }
771
+ var valid1 = _errs23 === errors;
772
+ } else {
773
+ var valid1 = true;
774
+ }
775
+ if (valid1) {
776
+ if (data.type !== void 0) {
777
+ let data5 = data.type;
778
+ const _errs25 = errors;
779
+ if (typeof data5 !== "string") {
780
+ const err16 = { instancePath: instancePath + "/type", schemaPath: "#/anyOf/0/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
781
+ if (vErrors === null) {
782
+ vErrors = [err16];
783
+ } else {
784
+ vErrors.push(err16);
785
+ }
786
+ errors++;
787
+ }
788
+ if (!(data5 === "byte" || data5 === "dword" || data5 === "qword" || data5 === "string" || data5 === "uuid" || data5 === "word")) {
789
+ const err17 = { instancePath: instancePath + "/type", schemaPath: "#/anyOf/0/properties/type/enum", keyword: "enum", params: { allowedValues: schema15.anyOf[0].properties.type.enum }, message: "must be equal to one of the allowed values" };
790
+ if (vErrors === null) {
791
+ vErrors = [err17];
792
+ } else {
793
+ vErrors.push(err17);
794
+ }
795
+ errors++;
796
+ }
797
+ var valid1 = _errs25 === errors;
798
+ } else {
799
+ var valid1 = true;
800
+ }
801
+ }
802
+ }
803
+ }
804
+ }
805
+ } else {
806
+ const err18 = { instancePath, schemaPath: "#/anyOf/0/type", keyword: "type", params: { type: "object" }, message: "must be object" };
807
+ if (vErrors === null) {
808
+ vErrors = [err18];
809
+ } else {
810
+ vErrors.push(err18);
811
+ }
812
+ errors++;
813
+ }
814
+ }
815
+ var _valid0 = _errs1 === errors;
816
+ valid0 = valid0 || _valid0;
817
+ if (!valid0) {
818
+ const _errs27 = errors;
819
+ if (typeof data !== "string") {
820
+ const err19 = { instancePath, schemaPath: "#/anyOf/1/type", keyword: "type", params: { type: "string" }, message: "must be string" };
821
+ if (vErrors === null) {
822
+ vErrors = [err19];
823
+ } else {
824
+ vErrors.push(err19);
825
+ }
826
+ errors++;
827
+ }
828
+ if (!(data === "baseboard-asset-tag" || data === "baseboard-manufacturer" || data === "baseboard-product-name" || data === "baseboard-serial-number" || data === "baseboard-version" || data === "bios-release-date" || data === "bios-revision" || data === "bios-vendor" || data === "bios-version" || data === "chassis-asset-tag" || data === "chassis-manufacturer" || data === "chassis-serial-number" || data === "chassis-version" || data === "processor-manufacturer" || data === "processor-version" || data === "system-family" || data === "system-manufacturer" || data === "system-product-name" || data === "system-serial-number" || data === "system-sku-number" || data === "system-uuid" || data === "system-version")) {
829
+ const err20 = { instancePath, schemaPath: "#/anyOf/1/enum", keyword: "enum", params: { allowedValues: schema15.anyOf[1].enum }, message: "must be equal to one of the allowed values" };
830
+ if (vErrors === null) {
831
+ vErrors = [err20];
832
+ } else {
833
+ vErrors.push(err20);
834
+ }
835
+ errors++;
836
+ }
837
+ var _valid0 = _errs27 === errors;
838
+ valid0 = valid0 || _valid0;
839
+ }
840
+ if (!valid0) {
841
+ const err21 = { instancePath, schemaPath: "#/anyOf", keyword: "anyOf", params: {}, message: "must match a schema in anyOf" };
842
+ if (vErrors === null) {
843
+ vErrors = [err21];
844
+ } else {
845
+ vErrors.push(err21);
846
+ }
847
+ errors++;
848
+ validate13.errors = vErrors;
849
+ return false;
850
+ } else {
851
+ errors = _errs0;
852
+ if (vErrors !== null) {
853
+ if (_errs0) {
854
+ vErrors.length = _errs0;
855
+ } else {
856
+ vErrors = null;
857
+ }
858
+ }
859
+ }
860
+ validate13.errors = vErrors;
861
+ return errors === 0;
862
+ }
863
+ function validate12(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
864
+ let vErrors = null;
865
+ let errors = 0;
866
+ if (errors === 0) {
867
+ if (data && typeof data == "object" && !Array.isArray(data)) {
868
+ let missing0;
869
+ if (data.ref === void 0 && (missing0 = "ref") || data.type === void 0 && (missing0 = "type")) {
870
+ validate12.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
871
+ return false;
872
+ } else {
873
+ const _errs1 = errors;
874
+ for (const key0 in data) {
875
+ if (!(key0 === "type" || key0 === "ref" || key0 === "value")) {
876
+ validate12.errors = [{ instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" }];
877
+ return false;
878
+ }
879
+ }
880
+ if (_errs1 === errors) {
881
+ if (data.type !== void 0) {
882
+ let data0 = data.type;
883
+ const _errs2 = errors;
884
+ if (typeof data0 !== "string") {
885
+ validate12.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
886
+ return false;
887
+ }
888
+ if ("smbios" !== data0) {
889
+ validate12.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/const", keyword: "const", params: { allowedValue: "smbios" }, message: "must be equal to constant" }];
890
+ return false;
891
+ }
892
+ var valid0 = _errs2 === errors;
893
+ } else {
894
+ var valid0 = true;
895
+ }
896
+ if (valid0) {
897
+ if (data.ref !== void 0) {
898
+ const _errs4 = errors;
899
+ if (!validate13(data.ref, { instancePath: instancePath + "/ref", parentData: data, parentDataProperty: "ref", rootData })) {
900
+ vErrors = vErrors === null ? validate13.errors : vErrors.concat(validate13.errors);
901
+ errors = vErrors.length;
902
+ }
903
+ var valid0 = _errs4 === errors;
904
+ } else {
905
+ var valid0 = true;
906
+ }
907
+ if (valid0) {
908
+ if (data.value !== void 0) {
909
+ const _errs5 = errors;
910
+ if (typeof data.value !== "string") {
911
+ validate12.errors = [{ instancePath: instancePath + "/value", schemaPath: "#/properties/value/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
912
+ return false;
913
+ }
914
+ var valid0 = _errs5 === errors;
915
+ } else {
916
+ var valid0 = true;
917
+ }
918
+ }
919
+ }
920
+ }
921
+ }
922
+ } else {
923
+ validate12.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
924
+ return false;
925
+ }
926
+ }
927
+ validate12.errors = vErrors;
928
+ return errors === 0;
929
+ }
930
+ const schema17 = { "properties": { "offsetRef": { "enum": ["end", "start"] } } };
931
+ const schema18 = { "type": ["string", "number"] };
932
+ const schema21 = { "enum": ["ascii", "base64", "base64url", "binary", "hex", "latin1", "ucs-2", "ucs2", "utf-16le", "utf-8", "utf16le", "utf8"] };
933
+ function validate17(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
934
+ let vErrors = null;
935
+ let errors = 0;
936
+ {
937
+ if (data && typeof data == "object" && !Array.isArray(data)) {
938
+ let missing0;
939
+ if (data.buffer === void 0 && (missing0 = "buffer") || data.type === void 0 && (missing0 = "type")) {
940
+ validate17.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
941
+ return false;
942
+ } else {
943
+ for (const key0 in data) {
944
+ if (!(key0 === "type" || key0 === "buffer")) {
945
+ validate17.errors = [{ instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" }];
946
+ return false;
947
+ }
948
+ }
949
+ {
950
+ if (data.type !== void 0) {
951
+ let data0 = data.type;
952
+ const _errs2 = errors;
953
+ if (typeof data0 !== "string") {
954
+ validate17.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/definitions/global.BufferEncoding/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
955
+ return false;
956
+ }
957
+ if (!(data0 === "ascii" || data0 === "base64" || data0 === "base64url" || data0 === "binary" || data0 === "hex" || data0 === "latin1" || data0 === "ucs-2" || data0 === "ucs2" || data0 === "utf-16le" || data0 === "utf-8" || data0 === "utf16le" || data0 === "utf8")) {
958
+ validate17.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/definitions/global.BufferEncoding/enum", keyword: "enum", params: { allowedValues: schema21.enum }, message: "must be equal to one of the allowed values" }];
959
+ return false;
960
+ }
961
+ var valid0 = _errs2 === errors;
962
+ } else {
963
+ var valid0 = true;
964
+ }
965
+ if (valid0) {
966
+ if (data.buffer !== void 0) {
967
+ const _errs5 = errors;
968
+ if (typeof data.buffer !== "string") {
969
+ validate17.errors = [{ instancePath: instancePath + "/buffer", schemaPath: "#/properties/buffer/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
970
+ return false;
971
+ }
972
+ var valid0 = _errs5 === errors;
973
+ } else {
974
+ var valid0 = true;
975
+ }
976
+ }
977
+ }
978
+ }
979
+ } else {
980
+ validate17.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
981
+ return false;
982
+ }
983
+ }
984
+ validate17.errors = vErrors;
985
+ return errors === 0;
986
+ }
987
+ function validate16(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
988
+ let vErrors = null;
989
+ let errors = 0;
990
+ if (errors === 0) {
991
+ if (data && typeof data == "object" && !Array.isArray(data)) {
992
+ let missing0;
993
+ if (data.offset === void 0 && (missing0 = "offset") || data.offsetRef === void 0 && (missing0 = "offsetRef") || data.type === void 0 && (missing0 = "type") || data.value === void 0 && (missing0 = "value")) {
994
+ validate16.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
995
+ return false;
996
+ } else {
997
+ const _errs1 = errors;
998
+ for (const key0 in data) {
999
+ if (!(key0 === "type" || key0 === "device" || key0 === "offsetRef" || key0 === "offset" || key0 === "value")) {
1000
+ validate16.errors = [{ instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" }];
1001
+ return false;
1002
+ }
1003
+ }
1004
+ if (_errs1 === errors) {
1005
+ if (data.type !== void 0) {
1006
+ let data0 = data.type;
1007
+ const _errs2 = errors;
1008
+ if (typeof data0 !== "string") {
1009
+ validate16.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1010
+ return false;
1011
+ }
1012
+ if ("hd-data" !== data0) {
1013
+ validate16.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/const", keyword: "const", params: { allowedValue: "hd-data" }, message: "must be equal to constant" }];
1014
+ return false;
1015
+ }
1016
+ var valid0 = _errs2 === errors;
1017
+ } else {
1018
+ var valid0 = true;
1019
+ }
1020
+ if (valid0) {
1021
+ if (data.device !== void 0) {
1022
+ const _errs4 = errors;
1023
+ if (typeof data.device !== "string") {
1024
+ validate16.errors = [{ instancePath: instancePath + "/device", schemaPath: "#/properties/device/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1025
+ return false;
1026
+ }
1027
+ var valid0 = _errs4 === errors;
1028
+ } else {
1029
+ var valid0 = true;
1030
+ }
1031
+ if (valid0) {
1032
+ if (data.offsetRef !== void 0) {
1033
+ let data2 = data.offsetRef;
1034
+ const _errs6 = errors;
1035
+ if (typeof data2 !== "string") {
1036
+ validate16.errors = [{ instancePath: instancePath + "/offsetRef", schemaPath: "#/properties/offsetRef/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1037
+ return false;
1038
+ }
1039
+ if (!(data2 === "end" || data2 === "start")) {
1040
+ validate16.errors = [{ instancePath: instancePath + "/offsetRef", schemaPath: "#/properties/offsetRef/enum", keyword: "enum", params: { allowedValues: schema17.properties.offsetRef.enum }, message: "must be equal to one of the allowed values" }];
1041
+ return false;
1042
+ }
1043
+ var valid0 = _errs6 === errors;
1044
+ } else {
1045
+ var valid0 = true;
1046
+ }
1047
+ if (valid0) {
1048
+ if (data.offset !== void 0) {
1049
+ let data3 = data.offset;
1050
+ const _errs8 = errors;
1051
+ if (typeof data3 !== "string" && !(typeof data3 == "number" && isFinite(data3))) {
1052
+ validate16.errors = [{ instancePath: instancePath + "/offset", schemaPath: "#/definitions/BigNumber/type", keyword: "type", params: { type: schema18.type }, message: "must be string,number" }];
1053
+ return false;
1054
+ }
1055
+ var valid0 = _errs8 === errors;
1056
+ } else {
1057
+ var valid0 = true;
1058
+ }
1059
+ if (valid0) {
1060
+ if (data.value !== void 0) {
1061
+ let data4 = data.value;
1062
+ const _errs11 = errors;
1063
+ const _errs12 = errors;
1064
+ let valid2 = false;
1065
+ const _errs13 = errors;
1066
+ const _errs14 = errors;
1067
+ if (errors === _errs14) {
1068
+ if (data4 && typeof data4 == "object" && !Array.isArray(data4)) {
1069
+ let missing1;
1070
+ if (data4.file === void 0 && (missing1 = "file") || data4.type === void 0 && (missing1 = "type")) {
1071
+ const err0 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromFile/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" };
1072
+ if (vErrors === null) {
1073
+ vErrors = [err0];
1074
+ } else {
1075
+ vErrors.push(err0);
1076
+ }
1077
+ errors++;
1078
+ } else {
1079
+ const _errs16 = errors;
1080
+ for (const key1 in data4) {
1081
+ if (!(key1 === "type" || key1 === "file" || key1 === "offset" || key1 === "size")) {
1082
+ const err1 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromFile/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key1 }, message: "must NOT have additional properties" };
1083
+ if (vErrors === null) {
1084
+ vErrors = [err1];
1085
+ } else {
1086
+ vErrors.push(err1);
1087
+ }
1088
+ errors++;
1089
+ break;
1090
+ }
1091
+ }
1092
+ if (_errs16 === errors) {
1093
+ if (data4.type !== void 0) {
1094
+ let data5 = data4.type;
1095
+ const _errs17 = errors;
1096
+ if (typeof data5 !== "string") {
1097
+ const err2 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromFile/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1098
+ if (vErrors === null) {
1099
+ vErrors = [err2];
1100
+ } else {
1101
+ vErrors.push(err2);
1102
+ }
1103
+ errors++;
1104
+ }
1105
+ if ("file" !== data5) {
1106
+ const err3 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromFile/properties/type/const", keyword: "const", params: { allowedValue: "file" }, message: "must be equal to constant" };
1107
+ if (vErrors === null) {
1108
+ vErrors = [err3];
1109
+ } else {
1110
+ vErrors.push(err3);
1111
+ }
1112
+ errors++;
1113
+ }
1114
+ var valid4 = _errs17 === errors;
1115
+ } else {
1116
+ var valid4 = true;
1117
+ }
1118
+ if (valid4) {
1119
+ if (data4.file !== void 0) {
1120
+ const _errs19 = errors;
1121
+ if (typeof data4.file !== "string") {
1122
+ const err4 = { instancePath: instancePath + "/value/file", schemaPath: "#/definitions/BinaryDataFromFile/properties/file/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1123
+ if (vErrors === null) {
1124
+ vErrors = [err4];
1125
+ } else {
1126
+ vErrors.push(err4);
1127
+ }
1128
+ errors++;
1129
+ }
1130
+ var valid4 = _errs19 === errors;
1131
+ } else {
1132
+ var valid4 = true;
1133
+ }
1134
+ if (valid4) {
1135
+ if (data4.offset !== void 0) {
1136
+ let data7 = data4.offset;
1137
+ const _errs21 = errors;
1138
+ if (!(typeof data7 == "number" && isFinite(data7))) {
1139
+ const err5 = { instancePath: instancePath + "/value/offset", schemaPath: "#/definitions/BinaryDataFromFile/properties/offset/type", keyword: "type", params: { type: "number" }, message: "must be number" };
1140
+ if (vErrors === null) {
1141
+ vErrors = [err5];
1142
+ } else {
1143
+ vErrors.push(err5);
1144
+ }
1145
+ errors++;
1146
+ }
1147
+ var valid4 = _errs21 === errors;
1148
+ } else {
1149
+ var valid4 = true;
1150
+ }
1151
+ if (valid4) {
1152
+ if (data4.size !== void 0) {
1153
+ let data8 = data4.size;
1154
+ const _errs23 = errors;
1155
+ if (!(typeof data8 == "number" && isFinite(data8))) {
1156
+ const err6 = { instancePath: instancePath + "/value/size", schemaPath: "#/definitions/BinaryDataFromFile/properties/size/type", keyword: "type", params: { type: "number" }, message: "must be number" };
1157
+ if (vErrors === null) {
1158
+ vErrors = [err6];
1159
+ } else {
1160
+ vErrors.push(err6);
1161
+ }
1162
+ errors++;
1163
+ }
1164
+ var valid4 = _errs23 === errors;
1165
+ } else {
1166
+ var valid4 = true;
1167
+ }
1168
+ }
1169
+ }
1170
+ }
1171
+ }
1172
+ }
1173
+ } else {
1174
+ const err7 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromFile/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1175
+ if (vErrors === null) {
1176
+ vErrors = [err7];
1177
+ } else {
1178
+ vErrors.push(err7);
1179
+ }
1180
+ errors++;
1181
+ }
1182
+ }
1183
+ var _valid0 = _errs13 === errors;
1184
+ valid2 = valid2 || _valid0;
1185
+ if (!valid2) {
1186
+ const _errs25 = errors;
1187
+ if (!validate17(data4, { instancePath: instancePath + "/value", parentData: data, parentDataProperty: "value", rootData })) {
1188
+ vErrors = vErrors === null ? validate17.errors : vErrors.concat(validate17.errors);
1189
+ errors = vErrors.length;
1190
+ }
1191
+ var _valid0 = _errs25 === errors;
1192
+ valid2 = valid2 || _valid0;
1193
+ if (!valid2) {
1194
+ const _errs26 = errors;
1195
+ const _errs27 = errors;
1196
+ if (errors === _errs27) {
1197
+ if (data4 && typeof data4 == "object" && !Array.isArray(data4)) {
1198
+ let missing2;
1199
+ if (data4.buffer === void 0 && (missing2 = "buffer") || data4.type === void 0 && (missing2 = "type")) {
1200
+ const err8 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromBuffer/required", keyword: "required", params: { missingProperty: missing2 }, message: "must have required property '" + missing2 + "'" };
1201
+ if (vErrors === null) {
1202
+ vErrors = [err8];
1203
+ } else {
1204
+ vErrors.push(err8);
1205
+ }
1206
+ errors++;
1207
+ } else {
1208
+ const _errs29 = errors;
1209
+ for (const key2 in data4) {
1210
+ if (!(key2 === "type" || key2 === "buffer")) {
1211
+ const err9 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromBuffer/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key2 }, message: "must NOT have additional properties" };
1212
+ if (vErrors === null) {
1213
+ vErrors = [err9];
1214
+ } else {
1215
+ vErrors.push(err9);
1216
+ }
1217
+ errors++;
1218
+ break;
1219
+ }
1220
+ }
1221
+ if (_errs29 === errors) {
1222
+ if (data4.type !== void 0) {
1223
+ let data9 = data4.type;
1224
+ const _errs30 = errors;
1225
+ if (typeof data9 !== "string") {
1226
+ const err10 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromBuffer/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1227
+ if (vErrors === null) {
1228
+ vErrors = [err10];
1229
+ } else {
1230
+ vErrors.push(err10);
1231
+ }
1232
+ errors++;
1233
+ }
1234
+ if ("buffer" !== data9) {
1235
+ const err11 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromBuffer/properties/type/const", keyword: "const", params: { allowedValue: "buffer" }, message: "must be equal to constant" };
1236
+ if (vErrors === null) {
1237
+ vErrors = [err11];
1238
+ } else {
1239
+ vErrors.push(err11);
1240
+ }
1241
+ errors++;
1242
+ }
1243
+ var valid6 = _errs30 === errors;
1244
+ } else {
1245
+ var valid6 = true;
1246
+ }
1247
+ if (valid6) {
1248
+ if (data4.buffer !== void 0) {
1249
+ let data10 = data4.buffer;
1250
+ const _errs32 = errors;
1251
+ if (!(data10 && typeof data10 == "object" && !Array.isArray(data10))) {
1252
+ const err12 = { instancePath: instancePath + "/value/buffer", schemaPath: "#/definitions/BinaryDataFromBuffer/properties/buffer/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1253
+ if (vErrors === null) {
1254
+ vErrors = [err12];
1255
+ } else {
1256
+ vErrors.push(err12);
1257
+ }
1258
+ errors++;
1259
+ }
1260
+ var valid6 = _errs32 === errors;
1261
+ } else {
1262
+ var valid6 = true;
1263
+ }
1264
+ }
1265
+ }
1266
+ }
1267
+ } else {
1268
+ const err13 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromBuffer/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1269
+ if (vErrors === null) {
1270
+ vErrors = [err13];
1271
+ } else {
1272
+ vErrors.push(err13);
1273
+ }
1274
+ errors++;
1275
+ }
1276
+ }
1277
+ var _valid0 = _errs26 === errors;
1278
+ valid2 = valid2 || _valid0;
1279
+ if (!valid2) {
1280
+ const _errs34 = errors;
1281
+ const _errs35 = errors;
1282
+ if (errors === _errs35) {
1283
+ if (data4 && typeof data4 == "object" && !Array.isArray(data4)) {
1284
+ let missing3;
1285
+ if (data4.type === void 0 && (missing3 = "type")) {
1286
+ const err14 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryMissingData/required", keyword: "required", params: { missingProperty: missing3 }, message: "must have required property '" + missing3 + "'" };
1287
+ if (vErrors === null) {
1288
+ vErrors = [err14];
1289
+ } else {
1290
+ vErrors.push(err14);
1291
+ }
1292
+ errors++;
1293
+ } else {
1294
+ const _errs37 = errors;
1295
+ for (const key3 in data4) {
1296
+ if (!(key3 === "type" || key3 === "size")) {
1297
+ const err15 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryMissingData/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key3 }, message: "must NOT have additional properties" };
1298
+ if (vErrors === null) {
1299
+ vErrors = [err15];
1300
+ } else {
1301
+ vErrors.push(err15);
1302
+ }
1303
+ errors++;
1304
+ break;
1305
+ }
1306
+ }
1307
+ if (_errs37 === errors) {
1308
+ if (data4.type !== void 0) {
1309
+ let data11 = data4.type;
1310
+ const _errs38 = errors;
1311
+ if (typeof data11 !== "string") {
1312
+ const err16 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryMissingData/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1313
+ if (vErrors === null) {
1314
+ vErrors = [err16];
1315
+ } else {
1316
+ vErrors.push(err16);
1317
+ }
1318
+ errors++;
1319
+ }
1320
+ if ("missing" !== data11) {
1321
+ const err17 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryMissingData/properties/type/const", keyword: "const", params: { allowedValue: "missing" }, message: "must be equal to constant" };
1322
+ if (vErrors === null) {
1323
+ vErrors = [err17];
1324
+ } else {
1325
+ vErrors.push(err17);
1326
+ }
1327
+ errors++;
1328
+ }
1329
+ var valid8 = _errs38 === errors;
1330
+ } else {
1331
+ var valid8 = true;
1332
+ }
1333
+ if (valid8) {
1334
+ if (data4.size !== void 0) {
1335
+ let data12 = data4.size;
1336
+ const _errs40 = errors;
1337
+ if (!(typeof data12 == "number" && isFinite(data12))) {
1338
+ const err18 = { instancePath: instancePath + "/value/size", schemaPath: "#/definitions/BinaryMissingData/properties/size/type", keyword: "type", params: { type: "number" }, message: "must be number" };
1339
+ if (vErrors === null) {
1340
+ vErrors = [err18];
1341
+ } else {
1342
+ vErrors.push(err18);
1343
+ }
1344
+ errors++;
1345
+ }
1346
+ var valid8 = _errs40 === errors;
1347
+ } else {
1348
+ var valid8 = true;
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+ } else {
1354
+ const err19 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryMissingData/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1355
+ if (vErrors === null) {
1356
+ vErrors = [err19];
1357
+ } else {
1358
+ vErrors.push(err19);
1359
+ }
1360
+ errors++;
1361
+ }
1362
+ }
1363
+ var _valid0 = _errs34 === errors;
1364
+ valid2 = valid2 || _valid0;
1365
+ }
1366
+ }
1367
+ }
1368
+ if (!valid2) {
1369
+ const err20 = { instancePath: instancePath + "/value", schemaPath: "#/properties/value/anyOf", keyword: "anyOf", params: {}, message: "must match a schema in anyOf" };
1370
+ if (vErrors === null) {
1371
+ vErrors = [err20];
1372
+ } else {
1373
+ vErrors.push(err20);
1374
+ }
1375
+ errors++;
1376
+ validate16.errors = vErrors;
1377
+ return false;
1378
+ } else {
1379
+ errors = _errs12;
1380
+ if (vErrors !== null) {
1381
+ if (_errs12) {
1382
+ vErrors.length = _errs12;
1383
+ } else {
1384
+ vErrors = null;
1385
+ }
1386
+ }
1387
+ }
1388
+ var valid0 = _errs11 === errors;
1389
+ } else {
1390
+ var valid0 = true;
1391
+ }
1392
+ }
1393
+ }
1394
+ }
1395
+ }
1396
+ }
1397
+ }
1398
+ } else {
1399
+ validate16.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
1400
+ return false;
1401
+ }
1402
+ }
1403
+ validate16.errors = vErrors;
1404
+ return errors === 0;
1405
+ }
1406
+ function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
1407
+ let vErrors = null;
1408
+ let errors = 0;
1409
+ {
1410
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1411
+ let missing0;
1412
+ if (data.type === void 0 && (missing0 = "type") || data.value === void 0 && (missing0 = "value")) {
1413
+ validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
1414
+ return false;
1415
+ } else {
1416
+ for (const key0 in data) {
1417
+ if (!(key0 === "type" || key0 === "device" || key0 === "value")) {
1418
+ validate20.errors = [{ instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" }];
1419
+ return false;
1420
+ }
1421
+ }
1422
+ {
1423
+ if (data.type !== void 0) {
1424
+ let data0 = data.type;
1425
+ const _errs2 = errors;
1426
+ if (typeof data0 !== "string") {
1427
+ validate20.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1428
+ return false;
1429
+ }
1430
+ if ("hd-size" !== data0) {
1431
+ validate20.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/const", keyword: "const", params: { allowedValue: "hd-size" }, message: "must be equal to constant" }];
1432
+ return false;
1433
+ }
1434
+ var valid0 = _errs2 === errors;
1435
+ } else {
1436
+ var valid0 = true;
1437
+ }
1438
+ if (valid0) {
1439
+ if (data.device !== void 0) {
1440
+ const _errs4 = errors;
1441
+ if (typeof data.device !== "string") {
1442
+ validate20.errors = [{ instancePath: instancePath + "/device", schemaPath: "#/properties/device/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1443
+ return false;
1444
+ }
1445
+ var valid0 = _errs4 === errors;
1446
+ } else {
1447
+ var valid0 = true;
1448
+ }
1449
+ if (valid0) {
1450
+ if (data.value !== void 0) {
1451
+ let data2 = data.value;
1452
+ const _errs6 = errors;
1453
+ if (typeof data2 !== "string" && !(typeof data2 == "number" && isFinite(data2))) {
1454
+ validate20.errors = [{ instancePath: instancePath + "/value", schemaPath: "#/definitions/BigNumber/type", keyword: "type", params: { type: schema18.type }, message: "must be string,number" }];
1455
+ return false;
1456
+ }
1457
+ var valid0 = _errs6 === errors;
1458
+ } else {
1459
+ var valid0 = true;
1460
+ }
1461
+ }
1462
+ }
1463
+ }
1464
+ }
1465
+ } else {
1466
+ validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
1467
+ return false;
1468
+ }
1469
+ }
1470
+ validate20.errors = vErrors;
1471
+ return errors === 0;
1472
+ }
1473
+ const schema26 = { "properties": { "offsetRef": { "enum": ["end", "full", "start"] }, "offset": { "type": ["string", "number"] } } };
1474
+ function validate22(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
1475
+ let vErrors = null;
1476
+ let errors = 0;
1477
+ if (errors === 0) {
1478
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1479
+ let missing0;
1480
+ if (data.file === void 0 && (missing0 = "file") || data.type === void 0 && (missing0 = "type") || data.value === void 0 && (missing0 = "value")) {
1481
+ validate22.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
1482
+ return false;
1483
+ } else {
1484
+ const _errs1 = errors;
1485
+ for (const key0 in data) {
1486
+ if (!(key0 === "type" || key0 === "device" || key0 === "file" || key0 === "offsetRef" || key0 === "offset" || key0 === "value")) {
1487
+ validate22.errors = [{ instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" }];
1488
+ return false;
1489
+ }
1490
+ }
1491
+ if (_errs1 === errors) {
1492
+ if (data.type !== void 0) {
1493
+ let data0 = data.type;
1494
+ const _errs2 = errors;
1495
+ if (typeof data0 !== "string") {
1496
+ validate22.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1497
+ return false;
1498
+ }
1499
+ if ("file-data" !== data0) {
1500
+ validate22.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/const", keyword: "const", params: { allowedValue: "file-data" }, message: "must be equal to constant" }];
1501
+ return false;
1502
+ }
1503
+ var valid0 = _errs2 === errors;
1504
+ } else {
1505
+ var valid0 = true;
1506
+ }
1507
+ if (valid0) {
1508
+ if (data.device !== void 0) {
1509
+ const _errs4 = errors;
1510
+ if (typeof data.device !== "string") {
1511
+ validate22.errors = [{ instancePath: instancePath + "/device", schemaPath: "#/properties/device/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1512
+ return false;
1513
+ }
1514
+ var valid0 = _errs4 === errors;
1515
+ } else {
1516
+ var valid0 = true;
1517
+ }
1518
+ if (valid0) {
1519
+ if (data.file !== void 0) {
1520
+ const _errs6 = errors;
1521
+ if (typeof data.file !== "string") {
1522
+ validate22.errors = [{ instancePath: instancePath + "/file", schemaPath: "#/properties/file/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1523
+ return false;
1524
+ }
1525
+ var valid0 = _errs6 === errors;
1526
+ } else {
1527
+ var valid0 = true;
1528
+ }
1529
+ if (valid0) {
1530
+ if (data.offsetRef !== void 0) {
1531
+ let data3 = data.offsetRef;
1532
+ const _errs8 = errors;
1533
+ if (typeof data3 !== "string") {
1534
+ validate22.errors = [{ instancePath: instancePath + "/offsetRef", schemaPath: "#/properties/offsetRef/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1535
+ return false;
1536
+ }
1537
+ if (!(data3 === "end" || data3 === "full" || data3 === "start")) {
1538
+ validate22.errors = [{ instancePath: instancePath + "/offsetRef", schemaPath: "#/properties/offsetRef/enum", keyword: "enum", params: { allowedValues: schema26.properties.offsetRef.enum }, message: "must be equal to one of the allowed values" }];
1539
+ return false;
1540
+ }
1541
+ var valid0 = _errs8 === errors;
1542
+ } else {
1543
+ var valid0 = true;
1544
+ }
1545
+ if (valid0) {
1546
+ if (data.offset !== void 0) {
1547
+ let data4 = data.offset;
1548
+ const _errs10 = errors;
1549
+ if (typeof data4 !== "string" && !(typeof data4 == "number" && isFinite(data4))) {
1550
+ validate22.errors = [{ instancePath: instancePath + "/offset", schemaPath: "#/properties/offset/type", keyword: "type", params: { type: schema26.properties.offset.type }, message: "must be string,number" }];
1551
+ return false;
1552
+ }
1553
+ var valid0 = _errs10 === errors;
1554
+ } else {
1555
+ var valid0 = true;
1556
+ }
1557
+ if (valid0) {
1558
+ if (data.value !== void 0) {
1559
+ let data5 = data.value;
1560
+ const _errs12 = errors;
1561
+ const _errs13 = errors;
1562
+ let valid1 = false;
1563
+ const _errs14 = errors;
1564
+ const _errs15 = errors;
1565
+ if (errors === _errs15) {
1566
+ if (data5 && typeof data5 == "object" && !Array.isArray(data5)) {
1567
+ let missing1;
1568
+ if (data5.file === void 0 && (missing1 = "file") || data5.type === void 0 && (missing1 = "type")) {
1569
+ const err0 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromFile/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" };
1570
+ if (vErrors === null) {
1571
+ vErrors = [err0];
1572
+ } else {
1573
+ vErrors.push(err0);
1574
+ }
1575
+ errors++;
1576
+ } else {
1577
+ const _errs17 = errors;
1578
+ for (const key1 in data5) {
1579
+ if (!(key1 === "type" || key1 === "file" || key1 === "offset" || key1 === "size")) {
1580
+ const err1 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromFile/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key1 }, message: "must NOT have additional properties" };
1581
+ if (vErrors === null) {
1582
+ vErrors = [err1];
1583
+ } else {
1584
+ vErrors.push(err1);
1585
+ }
1586
+ errors++;
1587
+ break;
1588
+ }
1589
+ }
1590
+ if (_errs17 === errors) {
1591
+ if (data5.type !== void 0) {
1592
+ let data6 = data5.type;
1593
+ const _errs18 = errors;
1594
+ if (typeof data6 !== "string") {
1595
+ const err2 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromFile/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1596
+ if (vErrors === null) {
1597
+ vErrors = [err2];
1598
+ } else {
1599
+ vErrors.push(err2);
1600
+ }
1601
+ errors++;
1602
+ }
1603
+ if ("file" !== data6) {
1604
+ const err3 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromFile/properties/type/const", keyword: "const", params: { allowedValue: "file" }, message: "must be equal to constant" };
1605
+ if (vErrors === null) {
1606
+ vErrors = [err3];
1607
+ } else {
1608
+ vErrors.push(err3);
1609
+ }
1610
+ errors++;
1611
+ }
1612
+ var valid3 = _errs18 === errors;
1613
+ } else {
1614
+ var valid3 = true;
1615
+ }
1616
+ if (valid3) {
1617
+ if (data5.file !== void 0) {
1618
+ const _errs20 = errors;
1619
+ if (typeof data5.file !== "string") {
1620
+ const err4 = { instancePath: instancePath + "/value/file", schemaPath: "#/definitions/BinaryDataFromFile/properties/file/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1621
+ if (vErrors === null) {
1622
+ vErrors = [err4];
1623
+ } else {
1624
+ vErrors.push(err4);
1625
+ }
1626
+ errors++;
1627
+ }
1628
+ var valid3 = _errs20 === errors;
1629
+ } else {
1630
+ var valid3 = true;
1631
+ }
1632
+ if (valid3) {
1633
+ if (data5.offset !== void 0) {
1634
+ let data8 = data5.offset;
1635
+ const _errs22 = errors;
1636
+ if (!(typeof data8 == "number" && isFinite(data8))) {
1637
+ const err5 = { instancePath: instancePath + "/value/offset", schemaPath: "#/definitions/BinaryDataFromFile/properties/offset/type", keyword: "type", params: { type: "number" }, message: "must be number" };
1638
+ if (vErrors === null) {
1639
+ vErrors = [err5];
1640
+ } else {
1641
+ vErrors.push(err5);
1642
+ }
1643
+ errors++;
1644
+ }
1645
+ var valid3 = _errs22 === errors;
1646
+ } else {
1647
+ var valid3 = true;
1648
+ }
1649
+ if (valid3) {
1650
+ if (data5.size !== void 0) {
1651
+ let data9 = data5.size;
1652
+ const _errs24 = errors;
1653
+ if (!(typeof data9 == "number" && isFinite(data9))) {
1654
+ const err6 = { instancePath: instancePath + "/value/size", schemaPath: "#/definitions/BinaryDataFromFile/properties/size/type", keyword: "type", params: { type: "number" }, message: "must be number" };
1655
+ if (vErrors === null) {
1656
+ vErrors = [err6];
1657
+ } else {
1658
+ vErrors.push(err6);
1659
+ }
1660
+ errors++;
1661
+ }
1662
+ var valid3 = _errs24 === errors;
1663
+ } else {
1664
+ var valid3 = true;
1665
+ }
1666
+ }
1667
+ }
1668
+ }
1669
+ }
1670
+ }
1671
+ } else {
1672
+ const err7 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromFile/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1673
+ if (vErrors === null) {
1674
+ vErrors = [err7];
1675
+ } else {
1676
+ vErrors.push(err7);
1677
+ }
1678
+ errors++;
1679
+ }
1680
+ }
1681
+ var _valid0 = _errs14 === errors;
1682
+ valid1 = valid1 || _valid0;
1683
+ if (!valid1) {
1684
+ const _errs26 = errors;
1685
+ if (!validate17(data5, { instancePath: instancePath + "/value", parentData: data, parentDataProperty: "value", rootData })) {
1686
+ vErrors = vErrors === null ? validate17.errors : vErrors.concat(validate17.errors);
1687
+ errors = vErrors.length;
1688
+ }
1689
+ var _valid0 = _errs26 === errors;
1690
+ valid1 = valid1 || _valid0;
1691
+ if (!valid1) {
1692
+ const _errs27 = errors;
1693
+ const _errs28 = errors;
1694
+ if (errors === _errs28) {
1695
+ if (data5 && typeof data5 == "object" && !Array.isArray(data5)) {
1696
+ let missing2;
1697
+ if (data5.buffer === void 0 && (missing2 = "buffer") || data5.type === void 0 && (missing2 = "type")) {
1698
+ const err8 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromBuffer/required", keyword: "required", params: { missingProperty: missing2 }, message: "must have required property '" + missing2 + "'" };
1699
+ if (vErrors === null) {
1700
+ vErrors = [err8];
1701
+ } else {
1702
+ vErrors.push(err8);
1703
+ }
1704
+ errors++;
1705
+ } else {
1706
+ const _errs30 = errors;
1707
+ for (const key2 in data5) {
1708
+ if (!(key2 === "type" || key2 === "buffer")) {
1709
+ const err9 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromBuffer/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key2 }, message: "must NOT have additional properties" };
1710
+ if (vErrors === null) {
1711
+ vErrors = [err9];
1712
+ } else {
1713
+ vErrors.push(err9);
1714
+ }
1715
+ errors++;
1716
+ break;
1717
+ }
1718
+ }
1719
+ if (_errs30 === errors) {
1720
+ if (data5.type !== void 0) {
1721
+ let data10 = data5.type;
1722
+ const _errs31 = errors;
1723
+ if (typeof data10 !== "string") {
1724
+ const err10 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromBuffer/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1725
+ if (vErrors === null) {
1726
+ vErrors = [err10];
1727
+ } else {
1728
+ vErrors.push(err10);
1729
+ }
1730
+ errors++;
1731
+ }
1732
+ if ("buffer" !== data10) {
1733
+ const err11 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryDataFromBuffer/properties/type/const", keyword: "const", params: { allowedValue: "buffer" }, message: "must be equal to constant" };
1734
+ if (vErrors === null) {
1735
+ vErrors = [err11];
1736
+ } else {
1737
+ vErrors.push(err11);
1738
+ }
1739
+ errors++;
1740
+ }
1741
+ var valid5 = _errs31 === errors;
1742
+ } else {
1743
+ var valid5 = true;
1744
+ }
1745
+ if (valid5) {
1746
+ if (data5.buffer !== void 0) {
1747
+ let data11 = data5.buffer;
1748
+ const _errs33 = errors;
1749
+ if (!(data11 && typeof data11 == "object" && !Array.isArray(data11))) {
1750
+ const err12 = { instancePath: instancePath + "/value/buffer", schemaPath: "#/definitions/BinaryDataFromBuffer/properties/buffer/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1751
+ if (vErrors === null) {
1752
+ vErrors = [err12];
1753
+ } else {
1754
+ vErrors.push(err12);
1755
+ }
1756
+ errors++;
1757
+ }
1758
+ var valid5 = _errs33 === errors;
1759
+ } else {
1760
+ var valid5 = true;
1761
+ }
1762
+ }
1763
+ }
1764
+ }
1765
+ } else {
1766
+ const err13 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryDataFromBuffer/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1767
+ if (vErrors === null) {
1768
+ vErrors = [err13];
1769
+ } else {
1770
+ vErrors.push(err13);
1771
+ }
1772
+ errors++;
1773
+ }
1774
+ }
1775
+ var _valid0 = _errs27 === errors;
1776
+ valid1 = valid1 || _valid0;
1777
+ if (!valid1) {
1778
+ const _errs35 = errors;
1779
+ const _errs36 = errors;
1780
+ if (errors === _errs36) {
1781
+ if (data5 && typeof data5 == "object" && !Array.isArray(data5)) {
1782
+ let missing3;
1783
+ if (data5.type === void 0 && (missing3 = "type")) {
1784
+ const err14 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryMissingData/required", keyword: "required", params: { missingProperty: missing3 }, message: "must have required property '" + missing3 + "'" };
1785
+ if (vErrors === null) {
1786
+ vErrors = [err14];
1787
+ } else {
1788
+ vErrors.push(err14);
1789
+ }
1790
+ errors++;
1791
+ } else {
1792
+ const _errs38 = errors;
1793
+ for (const key3 in data5) {
1794
+ if (!(key3 === "type" || key3 === "size")) {
1795
+ const err15 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryMissingData/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key3 }, message: "must NOT have additional properties" };
1796
+ if (vErrors === null) {
1797
+ vErrors = [err15];
1798
+ } else {
1799
+ vErrors.push(err15);
1800
+ }
1801
+ errors++;
1802
+ break;
1803
+ }
1804
+ }
1805
+ if (_errs38 === errors) {
1806
+ if (data5.type !== void 0) {
1807
+ let data12 = data5.type;
1808
+ const _errs39 = errors;
1809
+ if (typeof data12 !== "string") {
1810
+ const err16 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryMissingData/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1811
+ if (vErrors === null) {
1812
+ vErrors = [err16];
1813
+ } else {
1814
+ vErrors.push(err16);
1815
+ }
1816
+ errors++;
1817
+ }
1818
+ if ("missing" !== data12) {
1819
+ const err17 = { instancePath: instancePath + "/value/type", schemaPath: "#/definitions/BinaryMissingData/properties/type/const", keyword: "const", params: { allowedValue: "missing" }, message: "must be equal to constant" };
1820
+ if (vErrors === null) {
1821
+ vErrors = [err17];
1822
+ } else {
1823
+ vErrors.push(err17);
1824
+ }
1825
+ errors++;
1826
+ }
1827
+ var valid7 = _errs39 === errors;
1828
+ } else {
1829
+ var valid7 = true;
1830
+ }
1831
+ if (valid7) {
1832
+ if (data5.size !== void 0) {
1833
+ let data13 = data5.size;
1834
+ const _errs41 = errors;
1835
+ if (!(typeof data13 == "number" && isFinite(data13))) {
1836
+ const err18 = { instancePath: instancePath + "/value/size", schemaPath: "#/definitions/BinaryMissingData/properties/size/type", keyword: "type", params: { type: "number" }, message: "must be number" };
1837
+ if (vErrors === null) {
1838
+ vErrors = [err18];
1839
+ } else {
1840
+ vErrors.push(err18);
1841
+ }
1842
+ errors++;
1843
+ }
1844
+ var valid7 = _errs41 === errors;
1845
+ } else {
1846
+ var valid7 = true;
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1851
+ } else {
1852
+ const err19 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/BinaryMissingData/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1853
+ if (vErrors === null) {
1854
+ vErrors = [err19];
1855
+ } else {
1856
+ vErrors.push(err19);
1857
+ }
1858
+ errors++;
1859
+ }
1860
+ }
1861
+ var _valid0 = _errs35 === errors;
1862
+ valid1 = valid1 || _valid0;
1863
+ }
1864
+ }
1865
+ }
1866
+ if (!valid1) {
1867
+ const err20 = { instancePath: instancePath + "/value", schemaPath: "#/properties/value/anyOf", keyword: "anyOf", params: {}, message: "must match a schema in anyOf" };
1868
+ if (vErrors === null) {
1869
+ vErrors = [err20];
1870
+ } else {
1871
+ vErrors.push(err20);
1872
+ }
1873
+ errors++;
1874
+ validate22.errors = vErrors;
1875
+ return false;
1876
+ } else {
1877
+ errors = _errs13;
1878
+ if (vErrors !== null) {
1879
+ if (_errs13) {
1880
+ vErrors.length = _errs13;
1881
+ } else {
1882
+ vErrors = null;
1883
+ }
1884
+ }
1885
+ }
1886
+ var valid0 = _errs12 === errors;
1887
+ } else {
1888
+ var valid0 = true;
1889
+ }
1890
+ }
1891
+ }
1892
+ }
1893
+ }
1894
+ }
1895
+ }
1896
+ }
1897
+ } else {
1898
+ validate22.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
1899
+ return false;
1900
+ }
1901
+ }
1902
+ validate22.errors = vErrors;
1903
+ return errors === 0;
1904
+ }
1905
+ function validate25(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
1906
+ let vErrors = null;
1907
+ let errors = 0;
1908
+ {
1909
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1910
+ let missing0;
1911
+ if (data.file === void 0 && (missing0 = "file") || data.type === void 0 && (missing0 = "type") || data.value === void 0 && (missing0 = "value")) {
1912
+ validate25.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
1913
+ return false;
1914
+ } else {
1915
+ for (const key0 in data) {
1916
+ if (!(key0 === "type" || key0 === "device" || key0 === "file" || key0 === "value")) {
1917
+ validate25.errors = [{ instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" }];
1918
+ return false;
1919
+ }
1920
+ }
1921
+ {
1922
+ if (data.type !== void 0) {
1923
+ let data0 = data.type;
1924
+ const _errs2 = errors;
1925
+ if (typeof data0 !== "string") {
1926
+ validate25.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1927
+ return false;
1928
+ }
1929
+ if ("file-size" !== data0) {
1930
+ validate25.errors = [{ instancePath: instancePath + "/type", schemaPath: "#/properties/type/const", keyword: "const", params: { allowedValue: "file-size" }, message: "must be equal to constant" }];
1931
+ return false;
1932
+ }
1933
+ var valid0 = _errs2 === errors;
1934
+ } else {
1935
+ var valid0 = true;
1936
+ }
1937
+ if (valid0) {
1938
+ if (data.device !== void 0) {
1939
+ const _errs4 = errors;
1940
+ if (typeof data.device !== "string") {
1941
+ validate25.errors = [{ instancePath: instancePath + "/device", schemaPath: "#/properties/device/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1942
+ return false;
1943
+ }
1944
+ var valid0 = _errs4 === errors;
1945
+ } else {
1946
+ var valid0 = true;
1947
+ }
1948
+ if (valid0) {
1949
+ if (data.file !== void 0) {
1950
+ const _errs6 = errors;
1951
+ if (typeof data.file !== "string") {
1952
+ validate25.errors = [{ instancePath: instancePath + "/file", schemaPath: "#/properties/file/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
1953
+ return false;
1954
+ }
1955
+ var valid0 = _errs6 === errors;
1956
+ } else {
1957
+ var valid0 = true;
1958
+ }
1959
+ if (valid0) {
1960
+ if (data.value !== void 0) {
1961
+ let data3 = data.value;
1962
+ const _errs8 = errors;
1963
+ if (typeof data3 !== "string" && !(typeof data3 == "number" && isFinite(data3))) {
1964
+ validate25.errors = [{ instancePath: instancePath + "/value", schemaPath: "#/definitions/BigNumber/type", keyword: "type", params: { type: schema18.type }, message: "must be string,number" }];
1965
+ return false;
1966
+ }
1967
+ var valid0 = _errs8 === errors;
1968
+ } else {
1969
+ var valid0 = true;
1970
+ }
1971
+ }
1972
+ }
1973
+ }
1974
+ }
1975
+ }
1976
+ } else {
1977
+ validate25.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
1978
+ return false;
1979
+ }
1980
+ }
1981
+ validate25.errors = vErrors;
1982
+ return errors === 0;
1983
+ }
1984
+ function validate11(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
1985
+ let vErrors = null;
1986
+ let errors = 0;
1987
+ const _errs0 = errors;
1988
+ let valid0 = false;
1989
+ const _errs1 = errors;
1990
+ const _errs2 = errors;
1991
+ if (errors === _errs2) {
1992
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1993
+ let missing0;
1994
+ if (data.length === void 0 && (missing0 = "length") || data.type === void 0 && (missing0 = "type")) {
1995
+ const err0 = { instancePath, schemaPath: "#/definitions/HashComponentRandom/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" };
1996
+ if (vErrors === null) {
1997
+ vErrors = [err0];
1998
+ } else {
1999
+ vErrors.push(err0);
2000
+ }
2001
+ errors++;
2002
+ } else {
2003
+ const _errs4 = errors;
2004
+ for (const key0 in data) {
2005
+ if (!(key0 === "type" || key0 === "length")) {
2006
+ const err1 = { instancePath, schemaPath: "#/definitions/HashComponentRandom/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
2007
+ if (vErrors === null) {
2008
+ vErrors = [err1];
2009
+ } else {
2010
+ vErrors.push(err1);
2011
+ }
2012
+ errors++;
2013
+ break;
2014
+ }
2015
+ }
2016
+ if (_errs4 === errors) {
2017
+ if (data.type !== void 0) {
2018
+ let data0 = data.type;
2019
+ const _errs5 = errors;
2020
+ if (typeof data0 !== "string") {
2021
+ const err2 = { instancePath: instancePath + "/type", schemaPath: "#/definitions/HashComponentRandom/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
2022
+ if (vErrors === null) {
2023
+ vErrors = [err2];
2024
+ } else {
2025
+ vErrors.push(err2);
2026
+ }
2027
+ errors++;
2028
+ }
2029
+ if ("random" !== data0) {
2030
+ const err3 = { instancePath: instancePath + "/type", schemaPath: "#/definitions/HashComponentRandom/properties/type/const", keyword: "const", params: { allowedValue: "random" }, message: "must be equal to constant" };
2031
+ if (vErrors === null) {
2032
+ vErrors = [err3];
2033
+ } else {
2034
+ vErrors.push(err3);
2035
+ }
2036
+ errors++;
2037
+ }
2038
+ var valid2 = _errs5 === errors;
2039
+ } else {
2040
+ var valid2 = true;
2041
+ }
2042
+ if (valid2) {
2043
+ if (data.length !== void 0) {
2044
+ let data1 = data.length;
2045
+ const _errs7 = errors;
2046
+ if (!(typeof data1 == "number" && isFinite(data1))) {
2047
+ const err4 = { instancePath: instancePath + "/length", schemaPath: "#/definitions/HashComponentRandom/properties/length/type", keyword: "type", params: { type: "number" }, message: "must be number" };
2048
+ if (vErrors === null) {
2049
+ vErrors = [err4];
2050
+ } else {
2051
+ vErrors.push(err4);
2052
+ }
2053
+ errors++;
2054
+ }
2055
+ var valid2 = _errs7 === errors;
2056
+ } else {
2057
+ var valid2 = true;
2058
+ }
2059
+ }
2060
+ }
2061
+ }
2062
+ } else {
2063
+ const err5 = { instancePath, schemaPath: "#/definitions/HashComponentRandom/type", keyword: "type", params: { type: "object" }, message: "must be object" };
2064
+ if (vErrors === null) {
2065
+ vErrors = [err5];
2066
+ } else {
2067
+ vErrors.push(err5);
2068
+ }
2069
+ errors++;
2070
+ }
2071
+ }
2072
+ var _valid0 = _errs1 === errors;
2073
+ valid0 = valid0 || _valid0;
2074
+ if (!valid0) {
2075
+ const _errs9 = errors;
2076
+ if (!validate12(data, { instancePath, parentData, parentDataProperty, rootData })) {
2077
+ vErrors = vErrors === null ? validate12.errors : vErrors.concat(validate12.errors);
2078
+ errors = vErrors.length;
2079
+ }
2080
+ var _valid0 = _errs9 === errors;
2081
+ valid0 = valid0 || _valid0;
2082
+ if (!valid0) {
2083
+ const _errs10 = errors;
2084
+ if (!validate16(data, { instancePath, parentData, parentDataProperty, rootData })) {
2085
+ vErrors = vErrors === null ? validate16.errors : vErrors.concat(validate16.errors);
2086
+ errors = vErrors.length;
2087
+ }
2088
+ var _valid0 = _errs10 === errors;
2089
+ valid0 = valid0 || _valid0;
2090
+ if (!valid0) {
2091
+ const _errs11 = errors;
2092
+ if (!validate20(data, { instancePath, parentData, parentDataProperty, rootData })) {
2093
+ vErrors = vErrors === null ? validate20.errors : vErrors.concat(validate20.errors);
2094
+ errors = vErrors.length;
2095
+ }
2096
+ var _valid0 = _errs11 === errors;
2097
+ valid0 = valid0 || _valid0;
2098
+ if (!valid0) {
2099
+ const _errs12 = errors;
2100
+ if (!validate22(data, { instancePath, parentData, parentDataProperty, rootData })) {
2101
+ vErrors = vErrors === null ? validate22.errors : vErrors.concat(validate22.errors);
2102
+ errors = vErrors.length;
2103
+ }
2104
+ var _valid0 = _errs12 === errors;
2105
+ valid0 = valid0 || _valid0;
2106
+ if (!valid0) {
2107
+ const _errs13 = errors;
2108
+ if (!validate25(data, { instancePath, parentData, parentDataProperty, rootData })) {
2109
+ vErrors = vErrors === null ? validate25.errors : vErrors.concat(validate25.errors);
2110
+ errors = vErrors.length;
2111
+ }
2112
+ var _valid0 = _errs13 === errors;
2113
+ valid0 = valid0 || _valid0;
2114
+ if (!valid0) {
2115
+ const _errs14 = errors;
2116
+ const _errs15 = errors;
2117
+ if (errors === _errs15) {
2118
+ if (data && typeof data == "object" && !Array.isArray(data)) {
2119
+ let missing1;
2120
+ if (data.type === void 0 && (missing1 = "type") || data.value === void 0 && (missing1 = "value")) {
2121
+ const err6 = { instancePath, schemaPath: "#/definitions/HashComponentMiscStringData/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" };
2122
+ if (vErrors === null) {
2123
+ vErrors = [err6];
2124
+ } else {
2125
+ vErrors.push(err6);
2126
+ }
2127
+ errors++;
2128
+ } else {
2129
+ const _errs17 = errors;
2130
+ for (const key1 in data) {
2131
+ if (!(key1 === "type" || key1 === "value")) {
2132
+ const err7 = { instancePath, schemaPath: "#/definitions/HashComponentMiscStringData/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key1 }, message: "must NOT have additional properties" };
2133
+ if (vErrors === null) {
2134
+ vErrors = [err7];
2135
+ } else {
2136
+ vErrors.push(err7);
2137
+ }
2138
+ errors++;
2139
+ break;
2140
+ }
2141
+ }
2142
+ if (_errs17 === errors) {
2143
+ if (data.type !== void 0) {
2144
+ let data2 = data.type;
2145
+ const _errs18 = errors;
2146
+ if (typeof data2 !== "string") {
2147
+ const err8 = { instancePath: instancePath + "/type", schemaPath: "#/definitions/HashComponentMiscStringData/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
2148
+ if (vErrors === null) {
2149
+ vErrors = [err8];
2150
+ } else {
2151
+ vErrors.push(err8);
2152
+ }
2153
+ errors++;
2154
+ }
2155
+ if (!(data2 === "boot-file" || data2 === "boot-hd-device" || data2 === "boot-partition-device")) {
2156
+ const err9 = { instancePath: instancePath + "/type", schemaPath: "#/definitions/HashComponentMiscStringData/properties/type/enum", keyword: "enum", params: { allowedValues: schema32.properties.type.enum }, message: "must be equal to one of the allowed values" };
2157
+ if (vErrors === null) {
2158
+ vErrors = [err9];
2159
+ } else {
2160
+ vErrors.push(err9);
2161
+ }
2162
+ errors++;
2163
+ }
2164
+ var valid4 = _errs18 === errors;
2165
+ } else {
2166
+ var valid4 = true;
2167
+ }
2168
+ if (valid4) {
2169
+ if (data.value !== void 0) {
2170
+ const _errs20 = errors;
2171
+ if (typeof data.value !== "string") {
2172
+ const err10 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/HashComponentMiscStringData/properties/value/type", keyword: "type", params: { type: "string" }, message: "must be string" };
2173
+ if (vErrors === null) {
2174
+ vErrors = [err10];
2175
+ } else {
2176
+ vErrors.push(err10);
2177
+ }
2178
+ errors++;
2179
+ }
2180
+ var valid4 = _errs20 === errors;
2181
+ } else {
2182
+ var valid4 = true;
2183
+ }
2184
+ }
2185
+ }
2186
+ }
2187
+ } else {
2188
+ const err11 = { instancePath, schemaPath: "#/definitions/HashComponentMiscStringData/type", keyword: "type", params: { type: "object" }, message: "must be object" };
2189
+ if (vErrors === null) {
2190
+ vErrors = [err11];
2191
+ } else {
2192
+ vErrors.push(err11);
2193
+ }
2194
+ errors++;
2195
+ }
2196
+ }
2197
+ var _valid0 = _errs14 === errors;
2198
+ valid0 = valid0 || _valid0;
2199
+ }
2200
+ }
2201
+ }
2202
+ }
2203
+ }
2204
+ }
2205
+ if (!valid0) {
2206
+ const err12 = { instancePath, schemaPath: "#/anyOf", keyword: "anyOf", params: {}, message: "must match a schema in anyOf" };
2207
+ if (vErrors === null) {
2208
+ vErrors = [err12];
2209
+ } else {
2210
+ vErrors.push(err12);
2211
+ }
2212
+ errors++;
2213
+ validate11.errors = vErrors;
2214
+ return false;
2215
+ } else {
2216
+ errors = _errs0;
2217
+ if (vErrors !== null) {
2218
+ if (_errs0) {
2219
+ vErrors.length = _errs0;
2220
+ } else {
2221
+ vErrors = null;
2222
+ }
2223
+ }
2224
+ }
2225
+ validate11.errors = vErrors;
2226
+ return errors === 0;
2227
+ }
2228
+ function validate10(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
2229
+ let vErrors = null;
2230
+ let errors = 0;
2231
+ if (errors === 0) {
2232
+ if (data && typeof data == "object" && !Array.isArray(data)) {
2233
+ let missing0;
2234
+ if (data.inputFile === void 0 && (missing0 = "inputFile")) {
2235
+ validate10.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
2236
+ return false;
2237
+ } else {
2238
+ const _errs1 = errors;
2239
+ for (const key0 in data) {
2240
+ if (!func2.call(schema11.properties, key0)) {
2241
+ validate10.errors = [{ instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" }];
2242
+ return false;
2243
+ }
2244
+ }
2245
+ if (_errs1 === errors) {
2246
+ if (data.$schema !== void 0) {
2247
+ const _errs2 = errors;
2248
+ if (typeof data.$schema !== "string") {
2249
+ validate10.errors = [{ instancePath: instancePath + "/$schema", schemaPath: "#/properties/%24schema/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
2250
+ return false;
2251
+ }
2252
+ var valid0 = _errs2 === errors;
2253
+ } else {
2254
+ var valid0 = true;
2255
+ }
2256
+ if (valid0) {
2257
+ if (data.inputFile !== void 0) {
2258
+ const _errs4 = errors;
2259
+ if (typeof data.inputFile !== "string") {
2260
+ validate10.errors = [{ instancePath: instancePath + "/inputFile", schemaPath: "#/properties/inputFile/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
2261
+ return false;
2262
+ }
2263
+ var valid0 = _errs4 === errors;
2264
+ } else {
2265
+ var valid0 = true;
2266
+ }
2267
+ if (valid0) {
2268
+ if (data.outputFile !== void 0) {
2269
+ const _errs6 = errors;
2270
+ if (typeof data.outputFile !== "string") {
2271
+ validate10.errors = [{ instancePath: instancePath + "/outputFile", schemaPath: "#/properties/outputFile/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
2272
+ return false;
2273
+ }
2274
+ var valid0 = _errs6 === errors;
2275
+ } else {
2276
+ var valid0 = true;
2277
+ }
2278
+ if (valid0) {
2279
+ if (data.skipGenCode !== void 0) {
2280
+ const _errs8 = errors;
2281
+ if (typeof data.skipGenCode !== "boolean") {
2282
+ validate10.errors = [{ instancePath: instancePath + "/skipGenCode", schemaPath: "#/properties/skipGenCode/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
2283
+ return false;
2284
+ }
2285
+ var valid0 = _errs8 === errors;
2286
+ } else {
2287
+ var valid0 = true;
2288
+ }
2289
+ if (valid0) {
2290
+ if (data.skipExtract !== void 0) {
2291
+ const _errs10 = errors;
2292
+ if (typeof data.skipExtract !== "boolean") {
2293
+ validate10.errors = [{ instancePath: instancePath + "/skipExtract", schemaPath: "#/properties/skipExtract/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
2294
+ return false;
2295
+ }
2296
+ var valid0 = _errs10 === errors;
2297
+ } else {
2298
+ var valid0 = true;
2299
+ }
2300
+ if (valid0) {
2301
+ if (data.skipMake !== void 0) {
2302
+ const _errs12 = errors;
2303
+ if (typeof data.skipMake !== "boolean") {
2304
+ validate10.errors = [{ instancePath: instancePath + "/skipMake", schemaPath: "#/properties/skipMake/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
2305
+ return false;
2306
+ }
2307
+ var valid0 = _errs12 === errors;
2308
+ } else {
2309
+ var valid0 = true;
2310
+ }
2311
+ if (valid0) {
2312
+ if (data.buildFolder !== void 0) {
2313
+ const _errs14 = errors;
2314
+ if (typeof data.buildFolder !== "string") {
2315
+ validate10.errors = [{ instancePath: instancePath + "/buildFolder", schemaPath: "#/properties/buildFolder/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
2316
+ return false;
2317
+ }
2318
+ var valid0 = _errs14 === errors;
2319
+ } else {
2320
+ var valid0 = true;
2321
+ }
2322
+ if (valid0) {
2323
+ if (data.hashComponents !== void 0) {
2324
+ let data7 = data.hashComponents;
2325
+ const _errs16 = errors;
2326
+ if (errors === _errs16) {
2327
+ if (Array.isArray(data7)) {
2328
+ var valid1 = true;
2329
+ const len0 = data7.length;
2330
+ for (let i0 = 0; i0 < len0; i0++) {
2331
+ const _errs18 = errors;
2332
+ if (!validate11(data7[i0], { instancePath: instancePath + "/hashComponents/" + i0, parentData: data7, parentDataProperty: i0, rootData })) {
2333
+ vErrors = vErrors === null ? validate11.errors : vErrors.concat(validate11.errors);
2334
+ errors = vErrors.length;
2335
+ }
2336
+ var valid1 = _errs18 === errors;
2337
+ if (!valid1) {
2338
+ break;
2339
+ }
2340
+ }
2341
+ } else {
2342
+ validate10.errors = [{ instancePath: instancePath + "/hashComponents", schemaPath: "#/properties/hashComponents/type", keyword: "type", params: { type: "array" }, message: "must be array" }];
2343
+ return false;
2344
+ }
2345
+ }
2346
+ var valid0 = _errs16 === errors;
2347
+ } else {
2348
+ var valid0 = true;
2349
+ }
2350
+ if (valid0) {
2351
+ if (data.smbios !== void 0) {
2352
+ const _errs19 = errors;
2353
+ if (typeof data.smbios !== "string") {
2354
+ validate10.errors = [{ instancePath: instancePath + "/smbios", schemaPath: "#/properties/smbios/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
2355
+ return false;
2356
+ }
2357
+ var valid0 = _errs19 === errors;
2358
+ } else {
2359
+ var valid0 = true;
2360
+ }
2361
+ }
2362
+ }
2363
+ }
2364
+ }
2365
+ }
2366
+ }
2367
+ }
2368
+ }
2369
+ }
2370
+ }
2371
+ } else {
2372
+ validate10.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
2373
+ return false;
2374
+ }
2375
+ }
2376
+ validate10.errors = vErrors;
2377
+ return errors === 0;
2378
+ }
2379
+ const spawnProcess = (command, args, options) => new Promise((resolve, reject) => {
2380
+ const child = spawn(command, args, options);
2381
+ child.on("close", (code, signal) => {
2382
+ if (!code && !signal) {
2383
+ resolve();
2384
+ } else {
2385
+ throw new Error("Command failed");
2386
+ }
2387
+ });
2388
+ });
2389
+ const build = async (config) => {
2390
+ if (!validate(config)) {
2391
+ console.error(validate.errors);
2392
+ throw new Error("Invalid configuration");
2393
+ }
2394
+ if (!config.hashComponents) {
2395
+ config = {
2396
+ ...config,
2397
+ hashComponents: [
2398
+ { type: "random", length: 32 },
2399
+ ...config.smbios ? [
2400
+ { type: "smbios", ref: "system-serial-number" },
2401
+ { type: "smbios", ref: "system-uuid" }
2402
+ ] : []
2403
+ ]
2404
+ };
2405
+ }
2406
+ let useTempFolder = false;
2407
+ if (!config.buildFolder) {
2408
+ useTempFolder = true;
2409
+ config.buildFolder = await mkdtemp(join(tmpdir(), "efiencrypt-"));
2410
+ }
2411
+ try {
2412
+ await mkdir(join(config.buildFolder), { recursive: true });
2413
+ if (!config.skipGenCode) {
2414
+ await genCode(config);
2415
+ }
2416
+ if (!config.skipExtract) {
2417
+ const extract = (await import("./extract-BW1V8DVW.js")).extract;
2418
+ await extract(config.buildFolder);
2419
+ }
2420
+ if (!config.skipMake) {
2421
+ await spawnProcess("make", [], {
2422
+ stdio: "inherit",
2423
+ cwd: config.buildFolder
2424
+ });
2425
+ if (config.outputFile) {
2426
+ await mkdir(dirname(config.outputFile), { recursive: true });
2427
+ await cp(join(config.buildFolder, "bootx64.efi"), config.outputFile);
2428
+ }
2429
+ }
2430
+ } finally {
2431
+ if (useTempFolder) {
2432
+ await rm(config.buildFolder, { recursive: true, force: true });
2433
+ }
2434
+ }
2435
+ };
2436
+ export {
2437
+ build as b
2438
+ };