@hot-updater/bsdiff 0.31.4 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/assets/hdiff.wasm CHANGED
Binary file
package/dist/bun.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bun.js","names":[],"sources":["../src/bun.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\n\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadBunWasmModule());\n\nfunction loadBunWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Bun runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAMA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,GAAG;AAEtE,uBAAuB,kBAAkB,CAAC;AAE1C,SAAS,oBAAwC;CAC/C,IAAI;EACF,OAAO,IAAI,YAAY,OAAO,aAAa,cAAc,CAAC;CAC5D,QAAQ;EACN,MAAM,IAAI,WACR,gBACA,8CAA8C,eAAe,SAAS,GACxE;CACF;AACF"}
1
+ {"version":3,"file":"bun.js","names":[],"sources":["../src/bun.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\n\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadBunWasmModule());\n\nfunction loadBunWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Bun runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAMA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,mBAAmB,CAAC;AAE3C,SAAS,oBAAwC;AAC/C,KAAI;AACF,SAAO,IAAI,YAAY,OAAO,aAAa,eAAe,CAAC;SACrD;AACN,QAAM,IAAI,WACR,gBACA,8CAA8C,eAAe,UAAU,GACxE"}
package/dist/deno.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"deno.js","names":[],"sources":["../src/deno.ts"],"sourcesContent":["import { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { toUint8Array } from \"./internal/bytes.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadDenoWasmModule());\n\nfunction loadDenoWasmModule(): WebAssembly.Module {\n const deno = (\n globalThis as {\n Deno?: {\n readFileSync?: (path: string | URL) => Uint8Array<ArrayBufferLike>;\n };\n }\n ).Deno;\n if (!deno || typeof deno.readFileSync !== \"function\") {\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"Deno runtime does not expose Deno.readFileSync\",\n );\n }\n\n try {\n return new WebAssembly.Module(\n toUint8Array(deno.readFileSync(HDIFF_WASM_URL)),\n );\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Deno runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,GAAG;AAEtE,uBAAuB,mBAAmB,CAAC;AAE3C,SAAS,qBAAyC;CAChD,MAAM,OACJ,WAKA;CACF,IAAI,CAAC,QAAQ,OAAO,KAAK,iBAAiB,YACxC,MAAM,IAAI,WACR,gBACA,gDACF;CAGF,IAAI;EACF,OAAO,IAAI,YAAY,OACrB,aAAa,KAAK,aAAa,cAAc,CAAC,CAChD;CACF,QAAQ;EACN,MAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,SAAS,GACzE;CACF;AACF"}
1
+ {"version":3,"file":"deno.js","names":[],"sources":["../src/deno.ts"],"sourcesContent":["import { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { toUint8Array } from \"./internal/bytes.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadDenoWasmModule());\n\nfunction loadDenoWasmModule(): WebAssembly.Module {\n const deno = (\n globalThis as {\n Deno?: {\n readFileSync?: (path: string | URL) => Uint8Array<ArrayBufferLike>;\n };\n }\n ).Deno;\n if (!deno || typeof deno.readFileSync !== \"function\") {\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"Deno runtime does not expose Deno.readFileSync\",\n );\n }\n\n try {\n return new WebAssembly.Module(\n toUint8Array(deno.readFileSync(HDIFF_WASM_URL)),\n );\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Deno runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,oBAAoB,CAAC;AAE5C,SAAS,qBAAyC;CAChD,MAAM,OACJ,WAKA;AACF,KAAI,CAAC,QAAQ,OAAO,KAAK,iBAAiB,WACxC,OAAM,IAAI,WACR,gBACA,iDACD;AAGH,KAAI;AACF,SAAO,IAAI,YAAY,OACrB,aAAa,KAAK,aAAa,eAAe,CAAC,CAChD;SACK;AACN,QAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,UAAU,GACzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export type HdiffErrorCode =\n | \"INVALID_HBC\"\n | \"NON_EXECUTION_FORM\"\n | \"BYTECODE_VERSION_MISMATCH\"\n | \"PATCH_FAILED\";\n\nexport class HdiffError extends Error {\n public readonly code: HdiffErrorCode;\n\n public constructor(\n code: HdiffErrorCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = \"HdiffError\";\n this.code = code;\n }\n}\n"],"mappings":";AAMA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YACE,MACA,SACA,SACA;EACA,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export type HdiffErrorCode =\n | \"INVALID_HBC\"\n | \"NON_EXECUTION_FORM\"\n | \"BYTECODE_VERSION_MISMATCH\"\n | \"PATCH_FAILED\";\n\nexport class HdiffError extends Error {\n public readonly code: HdiffErrorCode;\n\n public constructor(\n code: HdiffErrorCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = \"HdiffError\";\n this.code = code;\n }\n}\n"],"mappings":";AAMA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YACE,MACA,SACA,SACA;AACA,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO;AACZ,OAAK,OAAO"}
package/dist/hdiff.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hdiff.js","names":[],"sources":["../src/hdiff.ts"],"sourcesContent":["import { HdiffError } from \"./errors.js\";\nimport { createBsdiffPatch } from \"./internal/bsdiff.js\";\nimport { type Bytes, type BytesLike, toUint8Array } from \"./internal/bytes.js\";\nimport { validateExecutionHbc } from \"./internal/hermes-validate.js\";\n\nexport async function hdiff(base: BytesLike, next: BytesLike): Promise<Bytes> {\n const baseBytes = toUint8Array(base);\n const nextBytes = toUint8Array(next);\n\n const baseMeta = await validateExecutionHbc(baseBytes);\n const nextMeta = await validateExecutionHbc(nextBytes);\n\n if (baseMeta.version !== nextMeta.version) {\n throw new HdiffError(\n \"BYTECODE_VERSION_MISMATCH\",\n `HBC version mismatch: base=${baseMeta.version}, next=${nextMeta.version}`,\n );\n }\n\n return await createBsdiffPatch(baseBytes, nextBytes);\n}\n"],"mappings":";;;;;AAKA,eAAsB,MAAM,MAAiB,MAAiC;CAC5E,MAAM,YAAY,aAAa,IAAI;CACnC,MAAM,YAAY,aAAa,IAAI;CAEnC,MAAM,WAAW,MAAM,qBAAqB,SAAS;CACrD,MAAM,WAAW,MAAM,qBAAqB,SAAS;CAErD,IAAI,SAAS,YAAY,SAAS,SAChC,MAAM,IAAI,WACR,6BACA,8BAA8B,SAAS,QAAQ,SAAS,SAAS,SACnE;CAGF,OAAO,MAAM,kBAAkB,WAAW,SAAS;AACrD"}
1
+ {"version":3,"file":"hdiff.js","names":[],"sources":["../src/hdiff.ts"],"sourcesContent":["import { HdiffError } from \"./errors.js\";\nimport { createBsdiffPatch } from \"./internal/bsdiff.js\";\nimport { type Bytes, type BytesLike, toUint8Array } from \"./internal/bytes.js\";\nimport { validateExecutionHbc } from \"./internal/hermes-validate.js\";\n\nexport async function hdiff(base: BytesLike, next: BytesLike): Promise<Bytes> {\n const baseBytes = toUint8Array(base);\n const nextBytes = toUint8Array(next);\n\n const baseMeta = await validateExecutionHbc(baseBytes);\n const nextMeta = await validateExecutionHbc(nextBytes);\n\n if (baseMeta.version !== nextMeta.version) {\n throw new HdiffError(\n \"BYTECODE_VERSION_MISMATCH\",\n `HBC version mismatch: base=${baseMeta.version}, next=${nextMeta.version}`,\n );\n }\n\n return await createBsdiffPatch(baseBytes, nextBytes);\n}\n"],"mappings":";;;;;AAKA,eAAsB,MAAM,MAAiB,MAAiC;CAC5E,MAAM,YAAY,aAAa,KAAK;CACpC,MAAM,YAAY,aAAa,KAAK;CAEpC,MAAM,WAAW,MAAM,qBAAqB,UAAU;CACtD,MAAM,WAAW,MAAM,qBAAqB,UAAU;AAEtD,KAAI,SAAS,YAAY,SAAS,QAChC,OAAM,IAAI,WACR,6BACA,8BAA8B,SAAS,QAAQ,SAAS,SAAS,UAClE;AAGH,QAAO,MAAM,kBAAkB,WAAW,UAAU"}
@@ -1,16 +1,23 @@
1
1
  import { HdiffError } from "../errors.js";
2
2
  //#region src/internal/bsdiff.ts
3
+ var BsdiffStatus = /* @__PURE__ */ function(BsdiffStatus) {
4
+ BsdiffStatus[BsdiffStatus["OK"] = 0] = "OK";
5
+ BsdiffStatus[BsdiffStatus["INVALID_INPUT"] = 1] = "INVALID_INPUT";
6
+ BsdiffStatus[BsdiffStatus["PATCH_FAILED"] = 2] = "PATCH_FAILED";
7
+ BsdiffStatus[BsdiffStatus["INVALID_PATCH"] = 3] = "INVALID_PATCH";
8
+ return BsdiffStatus;
9
+ }(BsdiffStatus || {});
3
10
  let wasmPromise;
4
11
  async function createBsdiffPatch(base, next) {
5
12
  const wasm = await getBsdiffWasm();
6
13
  const status = runBinaryOperation(wasm, base, next, (basePtr, baseLen, nextPtr, nextLen) => wasm.create_patch(basePtr, baseLen, nextPtr, nextLen));
7
- if (status !== 0) throw mapPatchError(status);
14
+ if (status !== BsdiffStatus.OK) throw mapPatchError(status);
8
15
  return readAndFreeOutput(wasm);
9
16
  }
10
17
  async function applyBsdiffPatch(base, patch) {
11
18
  const wasm = await getBsdiffWasm();
12
19
  const status = runBinaryOperation(wasm, base, patch, (basePtr, baseLen, patchPtr, patchLen) => wasm.apply_patch(basePtr, baseLen, patchPtr, patchLen));
13
- if (status !== 0) throw mapApplyError(status);
20
+ if (status !== BsdiffStatus.OK) throw mapApplyError(status);
14
21
  return readAndFreeOutput(wasm);
15
22
  }
16
23
  function runBinaryOperation(wasm, left, right, run) {
@@ -42,15 +49,15 @@ function readAndFreeOutput(wasm) {
42
49
  return copied;
43
50
  }
44
51
  function mapPatchError(status) {
45
- if (status === 1) return new HdiffError("PATCH_FAILED", "Invalid input bytes provided to bsdiff wasm");
46
- if (status === 2) return new HdiffError("PATCH_FAILED", "Failed to generate ENDSLEY/BSDIFF43 patch");
47
- if (status === 3) return new HdiffError("PATCH_FAILED", "Unexpected patch-validation status while creating patch");
52
+ if (status === BsdiffStatus.INVALID_INPUT) return new HdiffError("PATCH_FAILED", "Invalid input bytes provided to bsdiff wasm");
53
+ if (status === BsdiffStatus.PATCH_FAILED) return new HdiffError("PATCH_FAILED", "Failed to generate ENDSLEY/BSDIFF43 patch");
54
+ if (status === BsdiffStatus.INVALID_PATCH) return new HdiffError("PATCH_FAILED", "Unexpected patch-validation status while creating patch");
48
55
  return new HdiffError("PATCH_FAILED", `Unknown bsdiff wasm status: ${status}`);
49
56
  }
50
57
  function mapApplyError(status) {
51
- if (status === 1) return new HdiffError("PATCH_FAILED", "Invalid input bytes provided to bspatch wasm");
52
- if (status === 3) return new HdiffError("PATCH_FAILED", "Invalid ENDSLEY/BSDIFF43 patch bytes");
53
- if (status === 2) return new HdiffError("PATCH_FAILED", "Unexpected patch-generation status while applying patch");
58
+ if (status === BsdiffStatus.INVALID_INPUT) return new HdiffError("PATCH_FAILED", "Invalid input bytes provided to bspatch wasm");
59
+ if (status === BsdiffStatus.INVALID_PATCH) return new HdiffError("PATCH_FAILED", "Invalid ENDSLEY/BSDIFF43 patch bytes");
60
+ if (status === BsdiffStatus.PATCH_FAILED) return new HdiffError("PATCH_FAILED", "Unexpected patch-generation status while applying patch");
54
61
  return new HdiffError("PATCH_FAILED", `Unknown bspatch wasm status: ${status}`);
55
62
  }
56
63
  async function getBsdiffWasm() {
@@ -1 +1 @@
1
- {"version":3,"file":"bsdiff.js","names":[],"sources":["../../src/internal/bsdiff.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\nimport type { Bytes } from \"./bytes.js\";\n\ntype BsdiffExports = {\n memory: WebAssembly.Memory;\n alloc: (len: number) => number;\n dealloc: (ptr: number, len: number) => void;\n create_patch: (\n basePtr: number,\n baseLen: number,\n nextPtr: number,\n nextLen: number,\n ) => number;\n apply_patch: (\n basePtr: number,\n baseLen: number,\n patchPtr: number,\n patchLen: number,\n ) => number;\n output_ptr: () => number;\n output_len: () => number;\n free_output: () => void;\n};\n\nenum BsdiffStatus {\n OK = 0,\n INVALID_INPUT = 1,\n PATCH_FAILED = 2,\n INVALID_PATCH = 3,\n}\n\nlet wasmPromise: Promise<BsdiffExports> | undefined;\n\nexport async function createBsdiffPatch(\n base: Bytes,\n next: Bytes,\n): Promise<Bytes> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n next,\n (basePtr, baseLen, nextPtr, nextLen) =>\n wasm.create_patch(basePtr, baseLen, nextPtr, nextLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapPatchError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nexport async function applyBsdiffPatch(\n base: Bytes,\n patch: Bytes,\n): Promise<Bytes> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n patch,\n (basePtr, baseLen, patchPtr, patchLen) =>\n wasm.apply_patch(basePtr, baseLen, patchPtr, patchLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapApplyError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nfunction runBinaryOperation(\n wasm: BsdiffExports,\n left: Bytes,\n right: Bytes,\n run: (\n leftPtr: number,\n leftLen: number,\n rightPtr: number,\n rightLen: number,\n ) => number,\n): number {\n const leftPtr = wasm.alloc(left.byteLength);\n const rightPtr = wasm.alloc(right.byteLength);\n\n try {\n writeBytesToMemory(wasm.memory, leftPtr, left);\n writeBytesToMemory(wasm.memory, rightPtr, right);\n return run(leftPtr, left.byteLength, rightPtr, right.byteLength);\n } finally {\n if (left.byteLength > 0) {\n wasm.dealloc(leftPtr, left.byteLength);\n }\n if (right.byteLength > 0) {\n wasm.dealloc(rightPtr, right.byteLength);\n }\n }\n}\n\nfunction writeBytesToMemory(\n memory: WebAssembly.Memory,\n ptr: number,\n bytes: Bytes,\n): void {\n if (bytes.byteLength === 0) {\n return;\n }\n new Uint8Array(memory.buffer, ptr, bytes.byteLength).set(bytes);\n}\n\nfunction readAndFreeOutput(wasm: BsdiffExports): Bytes {\n const outPtr = wasm.output_ptr();\n const outLen = wasm.output_len();\n\n if (outLen === 0) {\n wasm.free_output();\n return new Uint8Array();\n }\n\n const output = new Uint8Array(wasm.memory.buffer, outPtr, outLen);\n const copied = new Uint8Array(output);\n wasm.free_output();\n return copied;\n}\n\nfunction mapPatchError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bsdiff wasm\",\n );\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Failed to generate ENDSLEY/BSDIFF43 patch\",\n );\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-validation status while creating patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bsdiff wasm status: ${status}`,\n );\n}\n\nfunction mapApplyError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bspatch wasm\",\n );\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid ENDSLEY/BSDIFF43 patch bytes\",\n );\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-generation status while applying patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bspatch wasm status: ${status}`,\n );\n}\n\nasync function getBsdiffWasm(): Promise<BsdiffExports> {\n wasmPromise ??= loadBsdiffWasm();\n return wasmPromise;\n}\n\nasync function loadBsdiffWasm(): Promise<BsdiffExports> {\n const precompiled = getPrecompiledBsdiffModule();\n const directExports = asBsdiffExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toBsdiffExports(instance.exports);\n }\n\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"No precompiled bsdiff WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledBsdiffModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toBsdiffExports(source: unknown): BsdiffExports {\n const direct = asBsdiffExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\"PATCH_FAILED\", \"bsdiff wasm exports are incomplete\");\n}\n\nfunction asBsdiffExports(source: unknown): BsdiffExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<BsdiffExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.alloc === \"function\" &&\n typeof maybe.dealloc === \"function\" &&\n typeof maybe.create_patch === \"function\" &&\n typeof maybe.apply_patch === \"function\" &&\n typeof maybe.output_ptr === \"function\" &&\n typeof maybe.output_len === \"function\" &&\n typeof maybe.free_output === \"function\"\n ) {\n return maybe as BsdiffExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;AA+BA,IAAI;AAEJ,eAAsB,kBACpB,MACA,MACgB;CAChB,MAAM,OAAO,MAAM,cAAc;CAEjC,MAAM,SAAS,mBACb,MACA,MACA,OACC,SAAS,SAAS,SAAS,YAC1B,KAAK,aAAa,SAAS,SAAS,SAAS,OAAO,CACxD;CAEA,IAAI,WAAA,GACF,MAAM,cAAc,MAAM;CAG5B,OAAO,kBAAkB,IAAI;AAC/B;AAEA,eAAsB,iBACpB,MACA,OACgB;CAChB,MAAM,OAAO,MAAM,cAAc;CAEjC,MAAM,SAAS,mBACb,MACA,MACA,QACC,SAAS,SAAS,UAAU,aAC3B,KAAK,YAAY,SAAS,SAAS,UAAU,QAAQ,CACzD;CAEA,IAAI,WAAA,GACF,MAAM,cAAc,MAAM;CAG5B,OAAO,kBAAkB,IAAI;AAC/B;AAEA,SAAS,mBACP,MACA,MACA,OACA,KAMQ;CACR,MAAM,UAAU,KAAK,MAAM,KAAK,UAAU;CAC1C,MAAM,WAAW,KAAK,MAAM,MAAM,UAAU;CAE5C,IAAI;EACF,mBAAmB,KAAK,QAAQ,SAAS,IAAI;EAC7C,mBAAmB,KAAK,QAAQ,UAAU,KAAK;EAC/C,OAAO,IAAI,SAAS,KAAK,YAAY,UAAU,MAAM,UAAU;CACjE,UAAU;EACR,IAAI,KAAK,aAAa,GACpB,KAAK,QAAQ,SAAS,KAAK,UAAU;EAEvC,IAAI,MAAM,aAAa,GACrB,KAAK,QAAQ,UAAU,MAAM,UAAU;CAE3C;AACF;AAEA,SAAS,mBACP,QACA,KACA,OACM;CACN,IAAI,MAAM,eAAe,GACvB;CAEF,IAAI,WAAW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,IAA8B;CAExC,OAAO;AACT;AAEA,SAAS,iBAAiB,KAAyC;CACjE,IAAI,eAAe,YAAY,QAC7B,OAAO;CAET,OAAO,OAAO,UAAU,SAAS,KAAK,GAAG,MAAM;AACjD;AAEA,SAAS,iBAAiB,QAA+C;CACvE,IAAI,kBAAkB,YAAY,QAChC,OAAO;CAET,OACE,OAAO,UAAU,SAAS,KAAK,MAAM,MAAM;AAE/C;AAEA,SAAS,gBAAgB,QAAgC;CACvD,MAAM,SAAS,gBAAgB,MAAM;CACrC,IAAI,QACF,OAAO;CAGT,MAAM,IAAI,WAAW,gBAAgB,oCAAoC;AAC3E;AAEA,SAAS,gBAAgB,QAA4C;CACnE,IAAI,UAAU,OAAO,WAAW,UAAU;EACxC,MAAM,QAAQ;EACd,IACE,iBAAiB,MAAM,MAAM,KAC7B,OAAO,MAAM,UAAU,cACvB,OAAO,MAAM,YAAY,cACzB,OAAO,MAAM,iBAAiB,cAC9B,OAAO,MAAM,gBAAgB,cAC7B,OAAO,MAAM,eAAe,cAC5B,OAAO,MAAM,eAAe,cAC5B,OAAO,MAAM,gBAAgB,YAE7B,OAAO;CAEX;AAEF"}
1
+ {"version":3,"file":"bsdiff.js","names":[],"sources":["../../src/internal/bsdiff.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\nimport type { Bytes } from \"./bytes.js\";\n\ntype BsdiffExports = {\n memory: WebAssembly.Memory;\n alloc: (len: number) => number;\n dealloc: (ptr: number, len: number) => void;\n create_patch: (\n basePtr: number,\n baseLen: number,\n nextPtr: number,\n nextLen: number,\n ) => number;\n apply_patch: (\n basePtr: number,\n baseLen: number,\n patchPtr: number,\n patchLen: number,\n ) => number;\n output_ptr: () => number;\n output_len: () => number;\n free_output: () => void;\n};\n\nenum BsdiffStatus {\n OK = 0,\n INVALID_INPUT = 1,\n PATCH_FAILED = 2,\n INVALID_PATCH = 3,\n}\n\nlet wasmPromise: Promise<BsdiffExports> | undefined;\n\nexport async function createBsdiffPatch(\n base: Bytes,\n next: Bytes,\n): Promise<Bytes> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n next,\n (basePtr, baseLen, nextPtr, nextLen) =>\n wasm.create_patch(basePtr, baseLen, nextPtr, nextLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapPatchError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nexport async function applyBsdiffPatch(\n base: Bytes,\n patch: Bytes,\n): Promise<Bytes> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n patch,\n (basePtr, baseLen, patchPtr, patchLen) =>\n wasm.apply_patch(basePtr, baseLen, patchPtr, patchLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapApplyError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nfunction runBinaryOperation(\n wasm: BsdiffExports,\n left: Bytes,\n right: Bytes,\n run: (\n leftPtr: number,\n leftLen: number,\n rightPtr: number,\n rightLen: number,\n ) => number,\n): number {\n const leftPtr = wasm.alloc(left.byteLength);\n const rightPtr = wasm.alloc(right.byteLength);\n\n try {\n writeBytesToMemory(wasm.memory, leftPtr, left);\n writeBytesToMemory(wasm.memory, rightPtr, right);\n return run(leftPtr, left.byteLength, rightPtr, right.byteLength);\n } finally {\n if (left.byteLength > 0) {\n wasm.dealloc(leftPtr, left.byteLength);\n }\n if (right.byteLength > 0) {\n wasm.dealloc(rightPtr, right.byteLength);\n }\n }\n}\n\nfunction writeBytesToMemory(\n memory: WebAssembly.Memory,\n ptr: number,\n bytes: Bytes,\n): void {\n if (bytes.byteLength === 0) {\n return;\n }\n new Uint8Array(memory.buffer, ptr, bytes.byteLength).set(bytes);\n}\n\nfunction readAndFreeOutput(wasm: BsdiffExports): Bytes {\n const outPtr = wasm.output_ptr();\n const outLen = wasm.output_len();\n\n if (outLen === 0) {\n wasm.free_output();\n return new Uint8Array();\n }\n\n const output = new Uint8Array(wasm.memory.buffer, outPtr, outLen);\n const copied = new Uint8Array(output);\n wasm.free_output();\n return copied;\n}\n\nfunction mapPatchError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bsdiff wasm\",\n );\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Failed to generate ENDSLEY/BSDIFF43 patch\",\n );\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-validation status while creating patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bsdiff wasm status: ${status}`,\n );\n}\n\nfunction mapApplyError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bspatch wasm\",\n );\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid ENDSLEY/BSDIFF43 patch bytes\",\n );\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-generation status while applying patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bspatch wasm status: ${status}`,\n );\n}\n\nasync function getBsdiffWasm(): Promise<BsdiffExports> {\n wasmPromise ??= loadBsdiffWasm();\n return wasmPromise;\n}\n\nasync function loadBsdiffWasm(): Promise<BsdiffExports> {\n const precompiled = getPrecompiledBsdiffModule();\n const directExports = asBsdiffExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toBsdiffExports(instance.exports);\n }\n\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"No precompiled bsdiff WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledBsdiffModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toBsdiffExports(source: unknown): BsdiffExports {\n const direct = asBsdiffExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\"PATCH_FAILED\", \"bsdiff wasm exports are incomplete\");\n}\n\nfunction asBsdiffExports(source: unknown): BsdiffExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<BsdiffExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.alloc === \"function\" &&\n typeof maybe.dealloc === \"function\" &&\n typeof maybe.create_patch === \"function\" &&\n typeof maybe.apply_patch === \"function\" &&\n typeof maybe.output_ptr === \"function\" &&\n typeof maybe.output_len === \"function\" &&\n typeof maybe.free_output === \"function\"\n ) {\n return maybe as BsdiffExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAwBA,IAAK,eAAL,yBAAA,cAAA;AACE,cAAA,aAAA,QAAA,KAAA;AACA,cAAA,aAAA,mBAAA,KAAA;AACA,cAAA,aAAA,kBAAA,KAAA;AACA,cAAA,aAAA,mBAAA,KAAA;;EAJG,gBAAA,EAAA,CAKJ;AAED,IAAI;AAEJ,eAAsB,kBACpB,MACA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S,gBAAgB,QAAgC;CACvD,MAAM,SAAS,gBAAgB,OAAO;AACtC,KAAI,OACF,QAAO;AAGT,OAAM,IAAI,WAAW,gBAAgB,qCAAqC;;AAG5E,SAAS,gBAAgB,QAA4C;AACnE,KAAI,UAAU,OAAO,WAAW,UAAU;EACxC,MAAM,QAAQ;AACd,MACE,iBAAiB,MAAM,OAAO,IAC9B,OAAO,MAAM,UAAU,cACvB,OAAO,MAAM,YAAY,cACzB,OAAO,MAAM,iBAAiB,cAC9B,OAAO,MAAM,gBAAgB,cAC7B,OAAO,MAAM,eAAe,cAC5B,OAAO,MAAM,eAAe,cAC5B,OAAO,MAAM,gBAAgB,WAE7B,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","names":[],"sources":["../../src/internal/bytes.ts"],"mappings":";KAAY,KAAA,GAAQ,UAAU,CAAC,WAAA;AAAA,KACnB,SAAA,GAAY,UAAA,CAAW,eAAA,IAAmB,eAAA;AAAA,iBAEtC,YAAA,CAAa,KAAA,EAAO,SAAA,GAAY,KAAK;AAAA,iBAgBrC,WAAA,CAAY,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,KAAK;AAAA,iBAY9B,UAAA,CAAW,KAAA,EAAO,UAAA,CAAW,eAAA,IAAmB,KAAA"}
1
+ {"version":3,"file":"bytes.d.ts","names":[],"sources":["../../src/internal/bytes.ts"],"mappings":";KAAY,KAAA,GAAQ,UAAA,CAAW,WAAA;AAAA,KACnB,SAAA,GAAY,UAAA,CAAW,eAAA,IAAmB,eAAA;AAAA,iBAEtC,YAAA,CAAa,KAAA,EAAO,SAAA,GAAY,KAAA;AAAA,iBAgBhC,WAAA,CAAY,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,KAAA;AAAA,iBAYzB,UAAA,CAAW,KAAA,EAAO,UAAA,CAAW,eAAA,IAAmB,KAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.js","names":[],"sources":["../../src/internal/bytes.ts"],"sourcesContent":["export type Bytes = Uint8Array<ArrayBuffer>;\nexport type BytesLike = Uint8Array<ArrayBufferLike> | ArrayBufferLike;\n\nexport function toUint8Array(value: BytesLike): Bytes {\n if (value instanceof Uint8Array) {\n return Uint8Array.from(value);\n }\n if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n if (\n typeof SharedArrayBuffer !== \"undefined\" &&\n value instanceof SharedArrayBuffer\n ) {\n return Uint8Array.from(new Uint8Array(value));\n }\n throw new TypeError(\"Expected Uint8Array or ArrayBufferLike\");\n}\n\nexport function equalsBytes(a: Bytes, b: Bytes): boolean {\n if (a.byteLength !== b.byteLength) {\n return false;\n }\n for (let i = 0; i < a.byteLength; i += 1) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\nexport function cloneBytes(value: Uint8Array<ArrayBufferLike>): Bytes {\n return Uint8Array.from(value);\n}\n"],"mappings":";AAGA,SAAgB,aAAa,OAAyB;CACpD,IAAI,iBAAiB,YACnB,OAAO,WAAW,KAAK,KAAK;CAE9B,IAAI,iBAAiB,aACnB,OAAO,IAAI,WAAW,KAAK;CAE7B,IACE,OAAO,sBAAsB,eAC7B,iBAAiB,mBAEjB,OAAO,WAAW,KAAK,IAAI,WAAW,KAAK,CAAC;CAE9C,MAAM,IAAI,UAAU,wCAAwC;AAC9D;AAEA,SAAgB,YAAY,GAAU,GAAmB;CACvD,IAAI,EAAE,eAAe,EAAE,YACrB,OAAO;CAET,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,YAAY,KAAK,GACrC,IAAI,EAAE,OAAO,EAAE,IACb,OAAO;CAGX,OAAO;AACT;AAEA,SAAgB,WAAW,OAA2C;CACpE,OAAO,WAAW,KAAK,KAAK;AAC9B"}
1
+ {"version":3,"file":"bytes.js","names":[],"sources":["../../src/internal/bytes.ts"],"sourcesContent":["export type Bytes = Uint8Array<ArrayBuffer>;\nexport type BytesLike = Uint8Array<ArrayBufferLike> | ArrayBufferLike;\n\nexport function toUint8Array(value: BytesLike): Bytes {\n if (value instanceof Uint8Array) {\n return Uint8Array.from(value);\n }\n if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n if (\n typeof SharedArrayBuffer !== \"undefined\" &&\n value instanceof SharedArrayBuffer\n ) {\n return Uint8Array.from(new Uint8Array(value));\n }\n throw new TypeError(\"Expected Uint8Array or ArrayBufferLike\");\n}\n\nexport function equalsBytes(a: Bytes, b: Bytes): boolean {\n if (a.byteLength !== b.byteLength) {\n return false;\n }\n for (let i = 0; i < a.byteLength; i += 1) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\nexport function cloneBytes(value: Uint8Array<ArrayBufferLike>): Bytes {\n return Uint8Array.from(value);\n}\n"],"mappings":";AAGA,SAAgB,aAAa,OAAyB;AACpD,KAAI,iBAAiB,WACnB,QAAO,WAAW,KAAK,MAAM;AAE/B,KAAI,iBAAiB,YACnB,QAAO,IAAI,WAAW,MAAM;AAE9B,KACE,OAAO,sBAAsB,eAC7B,iBAAiB,kBAEjB,QAAO,WAAW,KAAK,IAAI,WAAW,MAAM,CAAC;AAE/C,OAAM,IAAI,UAAU,yCAAyC;;AAG/D,SAAgB,YAAY,GAAU,GAAmB;AACvD,KAAI,EAAE,eAAe,EAAE,WACrB,QAAO;AAET,MAAK,IAAI,IAAI,GAAG,IAAI,EAAE,YAAY,KAAK,EACrC,KAAI,EAAE,OAAO,EAAE,GACb,QAAO;AAGX,QAAO;;AAGT,SAAgB,WAAW,OAA2C;AACpE,QAAO,WAAW,KAAK,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"hermes-validate.d.ts","names":[],"sources":["../../src/internal/hermes-validate.ts"],"mappings":";;;KAWK,YAAA;EACH,OAAO;AAAA;AAAA,iBAaa,oBAAA,CACpB,KAAA,EAAO,KAAA,GACN,OAAA,CAAQ,YAAA"}
1
+ {"version":3,"file":"hermes-validate.d.ts","names":[],"sources":["../../src/internal/hermes-validate.ts"],"mappings":";;;KAWK,YAAA;EACH,OAAA;AAAA;AAAA,iBAaoB,oBAAA,CACpB,KAAA,EAAO,KAAA,GACN,OAAA,CAAQ,YAAA"}
@@ -1,5 +1,13 @@
1
1
  import { HdiffError } from "../errors.js";
2
2
  //#region src/internal/hermes-validate.ts
3
+ var ValidateCode = /* @__PURE__ */ function(ValidateCode) {
4
+ ValidateCode[ValidateCode["OK"] = 0] = "OK";
5
+ ValidateCode[ValidateCode["TOO_SMALL"] = 1] = "TOO_SMALL";
6
+ ValidateCode[ValidateCode["INVALID_MAGIC"] = 2] = "INVALID_MAGIC";
7
+ ValidateCode[ValidateCode["DELTA_MAGIC"] = 3] = "DELTA_MAGIC";
8
+ ValidateCode[ValidateCode["INVALID_LENGTH"] = 4] = "INVALID_LENGTH";
9
+ return ValidateCode;
10
+ }(ValidateCode || {});
3
11
  let wasmPromise;
4
12
  async function validateExecutionHbc(input) {
5
13
  const wasm = await getHermesValidator();
@@ -8,7 +16,7 @@ async function validateExecutionHbc(input) {
8
16
  try {
9
17
  if (input.byteLength > 0) new Uint8Array(wasm.memory.buffer, ptr, input.byteLength).set(input);
10
18
  const code = wasm.validate(ptr, input.byteLength);
11
- if (code !== 0) throw mapValidationError(code);
19
+ if (code !== ValidateCode.OK) throw mapValidationError(code);
12
20
  return { version: wasm.version(ptr) >>> 0 };
13
21
  } finally {
14
22
  if (input.byteLength > 0) wasm.dealloc(ptr, input.byteLength);
@@ -17,7 +25,7 @@ async function validateExecutionHbc(input) {
17
25
  ensureMemorySize(wasm.memory, input.byteLength);
18
26
  new Uint8Array(wasm.memory.buffer, 0, input.byteLength).set(input);
19
27
  const code = wasm.validate(0, input.byteLength);
20
- if (code !== 0) throw mapValidationError(code);
28
+ if (code !== ValidateCode.OK) throw mapValidationError(code);
21
29
  return { version: wasm.version(0) >>> 0 };
22
30
  }
23
31
  async function getHermesValidator() {
@@ -46,8 +54,8 @@ function ensureMemorySize(memory, requiredBytes) {
46
54
  memory.grow(additionalPages);
47
55
  }
48
56
  function mapValidationError(code) {
49
- if (code === 3) return new HdiffError("NON_EXECUTION_FORM", "Input HBC is delta-form. execution-form HBC is required.");
50
- if (code === 1 || code === 2 || code === 4) return new HdiffError("INVALID_HBC", "Input is not a valid execution-form HBC");
57
+ if (code === ValidateCode.DELTA_MAGIC) return new HdiffError("NON_EXECUTION_FORM", "Input HBC is delta-form. execution-form HBC is required.");
58
+ if (code === ValidateCode.TOO_SMALL || code === ValidateCode.INVALID_MAGIC || code === ValidateCode.INVALID_LENGTH) return new HdiffError("INVALID_HBC", "Input is not a valid execution-form HBC");
51
59
  return new HdiffError("INVALID_HBC", `Unknown Hermes validation error: ${code}`);
52
60
  }
53
61
  function isWasmModuleLike(mod) {
@@ -1 +1 @@
1
- {"version":3,"file":"hermes-validate.js","names":[],"sources":["../../src/internal/hermes-validate.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\nimport type { Bytes } from \"./bytes.js\";\n\ntype HermesValidateExports = {\n memory: WebAssembly.Memory;\n validate: (ptr: number, len: number) => number;\n version: (ptr: number) => number;\n alloc?: (len: number) => number;\n dealloc?: (ptr: number, len: number) => void;\n};\n\ntype ValidatedHbc = {\n version: number;\n};\n\nenum ValidateCode {\n OK = 0,\n TOO_SMALL = 1,\n INVALID_MAGIC = 2,\n DELTA_MAGIC = 3,\n INVALID_LENGTH = 4,\n}\n\nlet wasmPromise: Promise<HermesValidateExports> | undefined;\n\nexport async function validateExecutionHbc(\n input: Bytes,\n): Promise<ValidatedHbc> {\n const wasm = await getHermesValidator();\n if (typeof wasm.alloc === \"function\" && typeof wasm.dealloc === \"function\") {\n const ptr = wasm.alloc(input.byteLength);\n try {\n if (input.byteLength > 0) {\n new Uint8Array(wasm.memory.buffer, ptr, input.byteLength).set(input);\n }\n\n const code = wasm.validate(ptr, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(ptr) >>> 0 };\n } finally {\n if (input.byteLength > 0) {\n wasm.dealloc(ptr, input.byteLength);\n }\n }\n }\n\n ensureMemorySize(wasm.memory, input.byteLength);\n const view = new Uint8Array(wasm.memory.buffer, 0, input.byteLength);\n view.set(input);\n\n const code = wasm.validate(0, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(0) >>> 0 };\n}\n\nasync function getHermesValidator(): Promise<HermesValidateExports> {\n wasmPromise ??= loadHermesValidator();\n return wasmPromise;\n}\n\nasync function loadHermesValidator(): Promise<HermesValidateExports> {\n const precompiled = getPrecompiledHermesModule();\n const directExports = asHermesExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toHermesExports(instance.exports);\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"No precompiled Hermes validator WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledHermesModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction ensureMemorySize(\n memory: WebAssembly.Memory,\n requiredBytes: number,\n): void {\n const pageSize = 64 * 1024;\n const currentBytes = memory.buffer.byteLength;\n if (currentBytes >= requiredBytes) {\n return;\n }\n\n const bytesNeeded = requiredBytes - currentBytes;\n const additionalPages = Math.ceil(bytesNeeded / pageSize);\n memory.grow(additionalPages);\n}\n\nfunction mapValidationError(code: number): HdiffError {\n if (code === ValidateCode.DELTA_MAGIC) {\n return new HdiffError(\n \"NON_EXECUTION_FORM\",\n \"Input HBC is delta-form. execution-form HBC is required.\",\n );\n }\n if (\n code === ValidateCode.TOO_SMALL ||\n code === ValidateCode.INVALID_MAGIC ||\n code === ValidateCode.INVALID_LENGTH\n ) {\n return new HdiffError(\n \"INVALID_HBC\",\n \"Input is not a valid execution-form HBC\",\n );\n }\n return new HdiffError(\n \"INVALID_HBC\",\n `Unknown Hermes validation error: ${code}`,\n );\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toHermesExports(source: unknown): HermesValidateExports {\n const direct = asHermesExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"Hermes validator WASM exports are incomplete\",\n );\n}\n\nfunction asHermesExports(source: unknown): HermesValidateExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<HermesValidateExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.validate === \"function\" &&\n typeof maybe.version === \"function\"\n ) {\n return maybe as HermesValidateExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAuBA,IAAI;AAEJ,eAAsB,qBACpB,OACuB;CACvB,MAAM,OAAO,MAAM,mBAAmB;CACtC,IAAI,OAAO,KAAK,UAAU,cAAc,OAAO,KAAK,YAAY,YAAY;EAC1E,MAAM,MAAM,KAAK,MAAM,MAAM,UAAU;EACvC,IAAI;GACF,IAAI,MAAM,aAAa,GACrB,IAAI,WAAW,KAAK,OAAO,QAAQ,KAAK,MAAM,UAAU,EAAE,IAAI,KAAK;GAGrE,MAAM,OAAO,KAAK,SAAS,KAAK,MAAM,UAAU;GAChD,IAAI,SAAA,GACF,MAAM,mBAAmB,IAAI;GAG/B,OAAO,EAAE,SAAS,KAAK,QAAQ,GAAG,MAAM,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BAAiB,KAAyC;CACjE,IAAI,eAAe,YAAY,QAC7B,OAAO;CAET,OAAO,OAAO,UAAU,SAAS,KAAK,GAAG,MAAM;AACjD;AAEA,SAAS,iBAAiB,QAA+C;CACvE,IAAI,kBAAkB,YAAY,QAChC,OAAO;CAET,OACE,OAAO,UAAU,SAAS,KAAK,MAAM,MAAM;AAE/C;AAEA,SAAS,gBAAgB,QAAwC;CAC/D,MAAM,SAAS,gBAAgB,MAAM;CACrC,IAAI,QACF,OAAO;CAGT,MAAM,IAAI,WACR,eACA,8CACF;AACF;AAEA,SAAS,gBAAgB,QAAoD;CAC3E,IAAI,UAAU,OAAO,WAAW,UAAU;EACxC,MAAM,QAAQ;EACd,IACE,iBAAiB,MAAM,MAAM,KAC7B,OAAO,MAAM,aAAa,cAC1B,OAAO,MAAM,YAAY,YAEzB,OAAO;CAEX;AAEF"}
1
+ {"version":3,"file":"hermes-validate.js","names":[],"sources":["../../src/internal/hermes-validate.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\nimport type { Bytes } from \"./bytes.js\";\n\ntype HermesValidateExports = {\n memory: WebAssembly.Memory;\n validate: (ptr: number, len: number) => number;\n version: (ptr: number) => number;\n alloc?: (len: number) => number;\n dealloc?: (ptr: number, len: number) => void;\n};\n\ntype ValidatedHbc = {\n version: number;\n};\n\nenum ValidateCode {\n OK = 0,\n TOO_SMALL = 1,\n INVALID_MAGIC = 2,\n DELTA_MAGIC = 3,\n INVALID_LENGTH = 4,\n}\n\nlet wasmPromise: Promise<HermesValidateExports> | undefined;\n\nexport async function validateExecutionHbc(\n input: Bytes,\n): Promise<ValidatedHbc> {\n const wasm = await getHermesValidator();\n if (typeof wasm.alloc === \"function\" && typeof wasm.dealloc === \"function\") {\n const ptr = wasm.alloc(input.byteLength);\n try {\n if (input.byteLength > 0) {\n new Uint8Array(wasm.memory.buffer, ptr, input.byteLength).set(input);\n }\n\n const code = wasm.validate(ptr, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(ptr) >>> 0 };\n } finally {\n if (input.byteLength > 0) {\n wasm.dealloc(ptr, input.byteLength);\n }\n }\n }\n\n ensureMemorySize(wasm.memory, input.byteLength);\n const view = new Uint8Array(wasm.memory.buffer, 0, input.byteLength);\n view.set(input);\n\n const code = wasm.validate(0, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(0) >>> 0 };\n}\n\nasync function getHermesValidator(): Promise<HermesValidateExports> {\n wasmPromise ??= loadHermesValidator();\n return wasmPromise;\n}\n\nasync function loadHermesValidator(): Promise<HermesValidateExports> {\n const precompiled = getPrecompiledHermesModule();\n const directExports = asHermesExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toHermesExports(instance.exports);\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"No precompiled Hermes validator WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledHermesModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction ensureMemorySize(\n memory: WebAssembly.Memory,\n requiredBytes: number,\n): void {\n const pageSize = 64 * 1024;\n const currentBytes = memory.buffer.byteLength;\n if (currentBytes >= requiredBytes) {\n return;\n }\n\n const bytesNeeded = requiredBytes - currentBytes;\n const additionalPages = Math.ceil(bytesNeeded / pageSize);\n memory.grow(additionalPages);\n}\n\nfunction mapValidationError(code: number): HdiffError {\n if (code === ValidateCode.DELTA_MAGIC) {\n return new HdiffError(\n \"NON_EXECUTION_FORM\",\n \"Input HBC is delta-form. execution-form HBC is required.\",\n );\n }\n if (\n code === ValidateCode.TOO_SMALL ||\n code === ValidateCode.INVALID_MAGIC ||\n code === ValidateCode.INVALID_LENGTH\n ) {\n return new HdiffError(\n \"INVALID_HBC\",\n \"Input is not a valid execution-form HBC\",\n );\n }\n return new HdiffError(\n \"INVALID_HBC\",\n `Unknown Hermes validation error: ${code}`,\n );\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toHermesExports(source: unknown): HermesValidateExports {\n const direct = asHermesExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"Hermes validator WASM exports are incomplete\",\n );\n}\n\nfunction asHermesExports(source: unknown): HermesValidateExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<HermesValidateExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.validate === \"function\" &&\n typeof maybe.version === \"function\"\n ) {\n return maybe as HermesValidateExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAeA,IAAK,eAAL,yBAAA,cAAA;AACE,cAAA,aAAA,QAAA,KAAA;AACA,cAAA,aAAA,eAAA,KAAA;AACA,cAAA,aAAA,mBAAA,KAAA;AACA,cAAA,aAAA,iBAAA,KAAA;AACA,cAAA,aAAA,oBAAA,KAAA;;EALG,gBAAA,EAAA,CAMJ;AAED,IAAI;AAEJ,eAAsB,qBACpB,OACuB;CACvB,MAAM,OAAO,MAAM,oBAAoB;AACvC,KAAI,OAAO,KAAK,UAAU,cAAc,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Ac,gBAAgB;CACpC,MAAM,kBAAkB,KAAK,KAAK,cAAc,SAAS;AACzD,QAAO,KAAK,gBAAgB;;AAG9B,SAAS,mBAAmB,MAA0B;AACpD,KAAI,SAAS,aAAa,YACxB,QAAO,IAAI,WACT,sBACA,2DACD;AAEH,KACE,SAAS,aAAa,aACtB,SAAS,aAAa,iBACtB,SAAS,aAAa,eAEtB,QAAO,IAAI,WACT,eACA,0CACD;AAEH,QAAO,IAAI,WACT,eACA,oCAAoC,OACrC;;AAGH,SAAS,iBAAiB,KAAyC;AACjE,KAAI,eAAe,YAAY,OAC7B,QAAO;AAET,QAAO,OAAO,UAAU,SAAS,KAAK,IAAI,KAAK;;AAGjD,SAAS,iBAAiB,QAA+C;AACvE,KAAI,kBAAkB,YAAY,OAChC,QAAO;AAET,QACE,OAAO,UAAU,SAAS,KAAK,OAAO,KAAK;;AAI/C,SAAS,gBAAgB,QAAwC;CAC/D,MAAM,SAAS,gBAAgB,OAAO;AACtC,KAAI,OACF,QAAO;AAGT,OAAM,IAAI,WACR,eACA,+CACD;;AAGH,SAAS,gBAAgB,QAAoD;AAC3E,KAAI,UAAU,OAAO,WAAW,UAAU;EACxC,MAAM,QAAQ;AACd,MACE,iBAAiB,MAAM,OAAO,IAC9B,OAAO,MAAM,aAAa,cAC1B,OAAO,MAAM,YAAY,WAEzB,QAAO"}
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","names":[],"sources":["../src/node.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\n\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadNodeWasmModule());\n\nfunction loadNodeWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Node runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAMA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,GAAG;AAEtE,uBAAuB,mBAAmB,CAAC;AAE3C,SAAS,qBAAyC;CAChD,IAAI;EACF,OAAO,IAAI,YAAY,OAAO,aAAa,cAAc,CAAC;CAC5D,QAAQ;EACN,MAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,SAAS,GACzE;CACF;AACF"}
1
+ {"version":3,"file":"node.js","names":[],"sources":["../src/node.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\n\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadNodeWasmModule());\n\nfunction loadNodeWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Node runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAMA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,oBAAoB,CAAC;AAE5C,SAAS,qBAAyC;AAChD,KAAI;AACF,SAAO,IAAI,YAAY,OAAO,aAAa,eAAe,CAAC;SACrD;AACN,QAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,UAAU,GACzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"precompiled.d.ts","names":[],"sources":["../src/precompiled.ts"],"mappings":";iBAMgB,sBAAA,CAAuB,UAAA,EAAY,WAAA,CAAY,MAAM"}
1
+ {"version":3,"file":"precompiled.d.ts","names":[],"sources":["../src/precompiled.ts"],"mappings":";iBAMgB,sBAAA,CAAuB,UAAA,EAAY,WAAA,CAAY,MAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"precompiled.js","names":[],"sources":["../src/precompiled.ts"],"sourcesContent":["type HdiffGlobal = {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n};\n\nexport function installPrecompiledWasm(wasmModule: WebAssembly.Module): void {\n const hdiffGlobal = globalThis as HdiffGlobal;\n\n if (hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ = wasmModule;\n }\n}\n"],"mappings":";AAMA,SAAgB,uBAAuB,YAAsC;CAC3E,MAAM,cAAc;CAEpB,IAAI,YAAY,+BAA+B,KAAA,GAC7C,YAAY,6BAA6B;CAE3C,IAAI,YAAY,sCAAsC,KAAA,GACpD,YAAY,oCAAoC;CAElD,IAAI,YAAY,0CAA0C,KAAA,GACxD,YAAY,wCAAwC;AAExD"}
1
+ {"version":3,"file":"precompiled.js","names":[],"sources":["../src/precompiled.ts"],"sourcesContent":["type HdiffGlobal = {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n};\n\nexport function installPrecompiledWasm(wasmModule: WebAssembly.Module): void {\n const hdiffGlobal = globalThis as HdiffGlobal;\n\n if (hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ = wasmModule;\n }\n}\n"],"mappings":";AAMA,SAAgB,uBAAuB,YAAsC;CAC3E,MAAM,cAAc;AAEpB,KAAI,YAAY,+BAA+B,KAAA,EAC7C,aAAY,6BAA6B;AAE3C,KAAI,YAAY,sCAAsC,KAAA,EACpD,aAAY,oCAAoC;AAElD,KAAI,YAAY,0CAA0C,KAAA,EACxD,aAAY,wCAAwC"}
@@ -1 +1 @@
1
- {"version":3,"file":"worker.js","names":[],"sources":["../src/worker.ts"],"sourcesContent":["import hdiffWasmModule from \"../assets/hdiff.wasm\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\ninstallPrecompiledWasm(hdiffWasmModule);\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,uBAAuB,eAAe"}
1
+ {"version":3,"file":"worker.js","names":[],"sources":["../src/worker.ts"],"sourcesContent":["import hdiffWasmModule from \"../assets/hdiff.wasm\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\ninstallPrecompiledWasm(hdiffWasmModule);\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,uBAAuB,gBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/bsdiff",
3
- "version": "0.31.4",
3
+ "version": "0.33.0",
4
4
  "description": "Hot Updater BSdiff library that produces BSDIFF40 patches for RN bspatch flows",
5
5
  "license": "MIT AND BSD-2-Clause AND bzip2-1.0.6",
6
6
  "type": "module",
@@ -56,7 +56,7 @@
56
56
  "repository": "https://github.com/gronxb/hot-updater",
57
57
  "devDependencies": {
58
58
  "@types/node": "^25.3.2",
59
- "tsdown": "0.22.0",
59
+ "tsdown": "0.21.6",
60
60
  "typescript": "^6.0.2",
61
61
  "vitest": "4.1.4",
62
62
  "wrangler": "^4.69.0"