@afterpack/wasm 0.1.0 → 0.2.2
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/dist/api.js +10 -6
- package/dist/contract.d.ts +3 -1
- package/dist/engine.d.ts +3 -0
- package/dist/engine.js +11 -0
- package/dist/node.js +5 -1
- package/engine/afterpack_engine_bg.wasm +0 -0
- package/package.json +6 -2
- package/readme.md +3 -3
package/dist/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cloudApiBase } from "./cloud-base.js";
|
|
2
2
|
import { ObfuscationError } from "./contract.js";
|
|
3
|
-
import { engineVersion, processFile } from "./engine.js";
|
|
3
|
+
import { engineVersion, processFile, randomSeed } from "./engine.js";
|
|
4
4
|
export * from "./contract.js";
|
|
5
5
|
const DIAG_OUTPUT_UNPARSEABLE = "DIAG_OUTPUT_UNPARSEABLE";
|
|
6
6
|
function engineCrash(cause) {
|
|
@@ -51,7 +51,7 @@ class ObfuscatedFile {
|
|
|
51
51
|
const RETRYABLE_BACKOFF_SECONDS = [1, 4, 16];
|
|
52
52
|
const DEFAULT_RETRY_AFTER_SECONDS = 60;
|
|
53
53
|
const MAX_RETRY_AFTER_SECONDS = 120;
|
|
54
|
-
const REQUEST_TIMEOUT_MS =
|
|
54
|
+
const REQUEST_TIMEOUT_MS = 330_000;
|
|
55
55
|
function sleep(ms) {
|
|
56
56
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
57
57
|
}
|
|
@@ -201,7 +201,10 @@ async function requestCloudBatch(key, form) {
|
|
|
201
201
|
try {
|
|
202
202
|
response = await fetch(url, {
|
|
203
203
|
method: "POST",
|
|
204
|
-
headers: {
|
|
204
|
+
headers: {
|
|
205
|
+
Authorization: `Bearer ${key}`,
|
|
206
|
+
"X-AfterPack-Client-Timeout-Ms": String(REQUEST_TIMEOUT_MS),
|
|
207
|
+
},
|
|
205
208
|
body: form,
|
|
206
209
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
207
210
|
});
|
|
@@ -331,12 +334,13 @@ async function obfuscateAllCloud(files, paths, sources, key, config) {
|
|
|
331
334
|
export async function obfuscateAll(files, config) {
|
|
332
335
|
const paths = files.map((file, i) => enginePath(file, i, files.length));
|
|
333
336
|
const sources = files.map((file) => sourceToString(file.source));
|
|
334
|
-
|
|
335
|
-
|
|
337
|
+
const build = config?.seed === undefined ? { ...config, seed: randomSeed() } : config;
|
|
338
|
+
if (build.key !== undefined) {
|
|
339
|
+
return obfuscateAllCloud(files, paths, sources, build.key, build);
|
|
336
340
|
}
|
|
337
341
|
let results;
|
|
338
342
|
try {
|
|
339
|
-
results = files.map((file, i) => processFile(sources[i], file.sourceMap ?? "", JSON.stringify({ ...
|
|
343
|
+
results = files.map((file, i) => processFile(sources[i], file.sourceMap ?? "", JSON.stringify({ ...build, filePath: paths[i] })));
|
|
340
344
|
}
|
|
341
345
|
catch (cause) {
|
|
342
346
|
throw engineCrash(cause);
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** A named protection level. Sets `complexity`
|
|
1
|
+
/** A named protection level. Sets the `complexity` target; output size follows from it. */
|
|
2
2
|
export type Preset = "minify" | "light" | "medium" | "hard" | "extreme";
|
|
3
3
|
/** A kind of transformation that a region can allow or deny. */
|
|
4
4
|
export type TransformKind = ConfigurableTransform | "stringEncoding";
|
|
@@ -20,6 +20,8 @@ export interface RegionConfig {
|
|
|
20
20
|
end: number;
|
|
21
21
|
/** Overrides `complexity` inside the range. `0` applies no transformation there. */
|
|
22
22
|
complexity?: number;
|
|
23
|
+
/** Applies a preset inside the range, like the top-level `preset`. A `complexity` on the same range wins. */
|
|
24
|
+
preset?: Preset;
|
|
23
25
|
/** Overrides `inflation` inside the range. */
|
|
24
26
|
inflation?: {
|
|
25
27
|
/** The largest allowed output for the range, as a multiple of its input size. */
|
package/dist/engine.d.ts
CHANGED
|
@@ -7,5 +7,8 @@ export interface EngineOutput {
|
|
|
7
7
|
protectionMap?: ProtectionMap | null;
|
|
8
8
|
}
|
|
9
9
|
export declare function useModule(source: ModuleSource): void;
|
|
10
|
+
export type RandomFill = (words: Uint32Array) => void;
|
|
11
|
+
export declare function useRandom(fill: RandomFill): void;
|
|
12
|
+
export declare function randomSeed(): number;
|
|
10
13
|
export declare function engineVersion(): string;
|
|
11
14
|
export declare function processFile(source: string, inputSourceMap: string, configJson: string): EngineOutput;
|
package/dist/engine.js
CHANGED
|
@@ -5,6 +5,17 @@ let boundMemory = null;
|
|
|
5
5
|
export function useModule(source) {
|
|
6
6
|
loadModule = source;
|
|
7
7
|
}
|
|
8
|
+
let fillRandom = (words) => {
|
|
9
|
+
globalThis.crypto.getRandomValues(words);
|
|
10
|
+
};
|
|
11
|
+
export function useRandom(fill) {
|
|
12
|
+
fillRandom = fill;
|
|
13
|
+
}
|
|
14
|
+
export function randomSeed() {
|
|
15
|
+
const words = new Uint32Array(2);
|
|
16
|
+
fillRandom(words);
|
|
17
|
+
return (words[0] & 0x1f_ffff) * 0x1_0000_0000 + words[1];
|
|
18
|
+
}
|
|
8
19
|
function bind() {
|
|
9
20
|
if (bound)
|
|
10
21
|
return;
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { webcrypto } from "node:crypto";
|
|
1
2
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import { useModule } from "./engine.js";
|
|
3
|
+
import { useModule, useRandom } from "./engine.js";
|
|
4
|
+
useRandom((words) => {
|
|
5
|
+
webcrypto.getRandomValues(words);
|
|
6
|
+
});
|
|
3
7
|
useModule(() => new WebAssembly.Module(readFileSync(new URL("../engine/afterpack_engine_bg.wasm", import.meta.url))));
|
|
4
8
|
export * from "./api.js";
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@afterpack/wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "The AfterPack JavaScript obfuscator as WebAssembly, for Cloudflare Workers and Node",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node.js",
|
|
@@ -60,5 +60,9 @@
|
|
|
60
60
|
"afterpack"
|
|
61
61
|
],
|
|
62
62
|
"author": "AfterPack <hello@afterpack.dev>",
|
|
63
|
-
"license": "SEE LICENSE IN LICENSE"
|
|
63
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "git+https://github.com/afterpack-dev/afterpack.git"
|
|
67
|
+
}
|
|
64
68
|
}
|
package/readme.md
CHANGED
|
@@ -47,7 +47,7 @@ const results = await obfuscateAll([
|
|
|
47
47
|
{ path: "dist/vendor.js", source: vendorSource, sourceMap: vendorMap },
|
|
48
48
|
]);
|
|
49
49
|
|
|
50
|
-
await version(); // "0.1
|
|
50
|
+
await version(); // "0.2.1"
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
`obfuscate` accepts a string, a `Uint8Array`, or a file object `{ path, source, sourceMap }`, where `sourceMap` is the file's existing map to chain. Each result has `code`, `bytes`, `sourceMap` and `diagnostics`. The second argument is the config. See the [configuration reference](https://www.afterpack.dev/docs/config) and the [presets](https://www.afterpack.dev/docs/presets).
|
|
@@ -75,8 +75,8 @@ Without a key, this package runs AfterPack inside your Worker or Node process an
|
|
|
75
75
|
|
|
76
76
|
| Measure | Bytes | |
|
|
77
77
|
|---|---:|---|
|
|
78
|
-
| Raw `.wasm` |
|
|
79
|
-
| Gzipped | 1,
|
|
78
|
+
| Raw `.wasm` | 5,226,471 | 4.98 MiB |
|
|
79
|
+
| Gzipped | 1,564,621 | 1.49 MiB |
|
|
80
80
|
|
|
81
81
|
This fits Cloudflare's Worker size limit on both the free and paid plans. CPU time is the tighter limit: the free plan allows 10 ms per request, and obfuscating a 185 KB bundle at `complexity: 8` takes about 263 ms on an Apple M-series laptop. Plan on Workers Paid for real bundles.
|
|
82
82
|
|