eth-compress 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +95 -58
- package/_cjs/index.cjs +1 -1
- package/_cjs/index.cjs.map +3 -3
- package/_cjs/index.node.cjs +1 -1
- package/_cjs/index.node.cjs.map +3 -3
- package/_cjs/jit-compressor.cjs +1 -1
- package/_cjs/jit-compressor.cjs.map +3 -3
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +3 -3
- package/_esm/index.node.js +1 -1
- package/_esm/index.node.js.map +3 -3
- package/_esm/jit-compressor.js +1 -1
- package/_esm/jit-compressor.js.map +3 -3
- package/_types/compiler/jit.d.ts +3 -1
- package/_types/compiler/jit.d.ts.map +1 -1
- package/_types/compiler/opcodes.d.ts +0 -1
- package/_types/compiler/opcodes.d.ts.map +1 -1
- package/_types/compiler/utils.d.ts +13 -24
- package/_types/compiler/utils.d.ts.map +1 -1
- package/_types/contracts.d.ts +5 -14
- package/_types/contracts.d.ts.map +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/jit-compressor.d.ts +2 -1
- package/_types/jit-compressor.d.ts.map +1 -1
- package/index.ts +2 -2
- package/jit-compressor.ts +32 -15
- package/package.json +16 -12
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
## eth-compress
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A compact client-side module for compressing Ethereum JSON-RPC requests, targeting **lower latency** and gas-efficient **read-only calls** with large calldata.
|
|
4
4
|
|
|
5
|
-
It combines [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.3)-compliant negotiation for client-to-server compression, with optional JIT-compiled calldata compression
|
|
5
|
+
It combines [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.3)-compliant negotiation for client-to-server compression, with optional JIT-compiled calldata compression.
|
|
6
6
|
|
|
7
|
-
_Plug'n
|
|
7
|
+
_Plug 'n' play with viem and a simple API_
|
|
8
8
|
|
|
9
9
|
### Scope
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- HTTP
|
|
10
|
+
- **Read-only** `eth_call`s.
|
|
11
|
+
- Min. input threshold: > 1150 bytes.
|
|
12
|
+
- HTTP: Uses RFC 9110-compliant `Content-Encoding` negotiation (gzip/deflate).
|
|
13
|
+
- EVM/JIT: Routes `eth_call`s through a transient decompressor contract.
|
|
13
14
|
|
|
14
15
|
### Installation
|
|
15
16
|
|
|
@@ -17,9 +18,9 @@ _Plug'n Play with viem & with a simple API_
|
|
|
17
18
|
npm i eth-compress
|
|
18
19
|
```
|
|
19
20
|
---
|
|
20
|
-
### HTTP request compression
|
|
21
|
+
### HTTP request compression
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
Transparently compresses request bodies using the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream).
|
|
23
24
|
|
|
24
25
|
```ts
|
|
25
26
|
import { compressModule } from 'eth-compress';
|
|
@@ -72,18 +73,6 @@ const client = createPublicClient({
|
|
|
72
73
|
});
|
|
73
74
|
```
|
|
74
75
|
|
|
75
|
-
Proactive:
|
|
76
|
-
```ts
|
|
77
|
-
import { compressModule } from 'eth-compress';
|
|
78
|
-
|
|
79
|
-
const client = createPublicClient({
|
|
80
|
-
chain: base,
|
|
81
|
-
transport: http(rpcUrl, {
|
|
82
|
-
fetchFn: (url, init) => compressModule(url, init, 'proactive'),
|
|
83
|
-
}),
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
76
|
JIT calldata compression:
|
|
88
77
|
```ts
|
|
89
78
|
import { compressModule } from 'eth-compress';
|
|
@@ -96,77 +85,125 @@ const client = createPublicClient({
|
|
|
96
85
|
}),
|
|
97
86
|
});
|
|
98
87
|
```
|
|
99
|
-
#### thats it.
|
|
100
88
|
----
|
|
101
89
|
### Compatibility
|
|
102
|
-
- Preserves viem semantics: responses and error handling are unchanged; only the request
|
|
103
|
-
- Works in Node and modern browsers that support the
|
|
90
|
+
- Preserves viem semantics: responses and error handling are unchanged; only the request body is compressed.
|
|
91
|
+
- Works in Node and modern browsers that support the CompressionStream API.
|
|
92
|
+
<br><a href="https://caniuse.com/mdn-api_compressionstream">Chrome/Edge ≥ 80; Firefox ≥ 113; Safari/iOS ≥ 16.4</a>
|
|
104
93
|
|
|
105
94
|
<br>
|
|
106
95
|
|
|
107
96
|
----
|
|
108
97
|
|
|
109
|
-
###
|
|
98
|
+
### Calldata compression for `eth_call`
|
|
110
99
|
|
|
111
|
-
|
|
100
|
+
Eligible `eth_call`s are routed through a transient decompressor contract (injected via `stateDiff`).
|
|
112
101
|
|
|
113
102
|
```ts
|
|
114
103
|
import { compress_call } from 'eth-compress/compressor';
|
|
115
104
|
|
|
116
105
|
const payload = {
|
|
117
106
|
method: 'eth_call',
|
|
118
|
-
params: [
|
|
119
|
-
{
|
|
120
|
-
to: '0x…',
|
|
121
|
-
data: '0x…', // potentially large calldata
|
|
122
|
-
},
|
|
123
|
-
'latest',
|
|
124
|
-
],
|
|
107
|
+
params: [{ to: '0x…', data: '0x…' }, 'latest'],
|
|
125
108
|
};
|
|
126
109
|
|
|
127
|
-
const compressedPayload = compress_call(payload);
|
|
110
|
+
const compressedPayload = compress_call(payload);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Signature
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
compress_call(payload, alg?, forward?, revert?, clean_env?)
|
|
128
117
|
```
|
|
129
118
|
|
|
130
|
-
|
|
119
|
+
| Param | Type | Default | Description |
|
|
120
|
+
|---|---|---|---|
|
|
121
|
+
| `payload` | `any` | — | JSON-RPC `eth_call` payload |
|
|
122
|
+
| `alg` | `'jit' \| 'flz' \| 'cd'` | auto | Force a specific compression algorithm |
|
|
123
|
+
| `forward` | `ForwardMode` | `'call'` | How the decompressor forwards to the target contract |
|
|
124
|
+
| `revert` | `boolean` | `false` | If `true`, output data is returned via `REVERT` instead of `RETURN` |
|
|
125
|
+
| `clean_env` | `boolean` | `false` | JIT-only: disable environment opcode substitutions (`SELFBALANCE`, `ADDRESS`, `CALLER`, `CALLDATASIZE`) |
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
- **FLZ / CD**: Uses `LibZip.flzCompress` and `LibZip.cdCompress` from `solady` for fast LZ and calldata RLE compression.
|
|
127
|
+
#### Forward modes
|
|
134
128
|
|
|
135
|
-
|
|
129
|
+
`ForwardMode` controls what the generated decompressor bytecode does after decompression. All three algorithms (JIT, FLZ, CD) support the same forward modes.
|
|
136
130
|
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
| `forward` | `revert` | Behavior |
|
|
132
|
+
|---|---|---|
|
|
133
|
+
| `'call'` | `false` | `CALL` target contract, `RETURN` its returndata |
|
|
134
|
+
| `'call'` | `true` | `CALL` target contract, `REVERT` with its returndata |
|
|
135
|
+
| `'staticcall'` | `false` | `STATICCALL` target, `RETURN` its returndata |
|
|
136
|
+
| `'staticcall'` | `true` | `STATICCALL` target, `REVERT` with its returndata |
|
|
137
|
+
| `'delegatecall'` | `false` | `DELEGATECALL` target, `RETURN` its returndata |
|
|
138
|
+
| `'delegatecall'` | `true` | `DELEGATECALL` target, `REVERT` with its returndata |
|
|
139
|
+
| `'none'` | `false` | `RETURN` the decompressed data directly (no forwarding) |
|
|
140
|
+
| `'none'` | `true` | `REVERT` with the decompressed data directly (no forwarding) |
|
|
141
|
+
|
|
142
|
+
When `forward` is `'none'`, `clean_env` is forced on — environment opcode substitutions are disabled since there is no forwarded call context.
|
|
143
|
+
|
|
144
|
+
#### Examples
|
|
145
|
+
|
|
146
|
+
Default (CALL + RETURN):
|
|
147
|
+
```ts
|
|
148
|
+
compress_call(payload);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
STATICCALL forwarding with FLZ:
|
|
152
|
+
```ts
|
|
153
|
+
compress_call(payload, 'flz', 'staticcall');
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
DELEGATECALL, revert with returndata:
|
|
157
|
+
```ts
|
|
158
|
+
compress_call(payload, undefined, 'delegatecall', true);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Get decompressed calldata back via REVERT (useful as initcode or for off-chain extraction):
|
|
162
|
+
```ts
|
|
163
|
+
compress_call(payload, 'jit', 'none', true);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Algorithm selection
|
|
167
|
+
|
|
168
|
+
`compress_call` can be passed directly to `compressModule` as a custom transform. For eligible `eth_call`s, it chooses between:
|
|
169
|
+
|
|
170
|
+
- **JIT**: Compiles a one-off decompressor contract that reconstructs calldata word-by-word.
|
|
171
|
+
- **FLZ**: Uses `LibZip.flzCompress` from `solady` for FastLZ (LZ77) compression.
|
|
172
|
+
- **CD**: Uses `LibZip.cdCompress` from `solady` for calldata run-length encoding.
|
|
173
|
+
|
|
174
|
+
- **Size gating**:
|
|
175
|
+
- `< 1150 bytes`: no compression.
|
|
139
176
|
- `≥ 1150 bytes`: compression considered.
|
|
140
|
-
-
|
|
141
|
-
- `~3000
|
|
177
|
+
- `< ~3000 or ≥ ~8000 bytes`: JIT preferred (best ratio at small and large sizes).
|
|
178
|
+
- `~3000 – ~8000 bytes`: best of JIT, FLZ, and CD is picked.
|
|
142
179
|
|
|
143
180
|
- **Algorithm choice**:
|
|
144
181
|
- For mid-sized payloads, FLZ and CD are tried and the smaller output is chosen.
|
|
145
|
-
- For larger
|
|
146
|
-
- The thresholds are
|
|
147
|
-
aiming to keep the total request size within the [Ethernet MTU](https://en.wikipedia.org/wiki/Maximum_transmission_unit).
|
|
182
|
+
- For larger ones, JIT is used directly, prioritizing gas efficiency.
|
|
183
|
+
- The thresholds are tuned for total request size, aiming for the [Ethernet MTU](https://en.wikipedia.org/wiki/Maximum_transmission_unit).
|
|
148
184
|
|
|
149
185
|
### Important considerations
|
|
150
186
|
|
|
151
|
-
The
|
|
187
|
+
The calldata compressor is **experimental** and intended for auxiliary/bulk dApp read-only `eth_call`s. Use two viem clients to separate concerns.
|
|
152
188
|
|
|
153
189
|
### Compression Ratio & Gas
|
|
154
|
-
| Tx Size Range | # Txns | Avg. Tx Size| JIT Ratio | FLZ Ratio | CD Ratio | JIT Gas | FLZ Gas | CD Gas |
|
|
155
|
-
|------------------------|--------|-------------------|:-------------------------:|:----------------:|:----------------:|:---------------:|:---------------:|:---------------:|
|
|
156
|
-
| **> 8 KB** | 129 | 14.90 kb | 2.99x | **3.62x** | 3.21x | **8.02k** | 323k | 242k |
|
|
157
|
-
| **3–8 KB** | 260 | 4.82 kb | 2.77x | 2.59x | **2.81x** | **4.45k** | 138k | 88.9k |
|
|
158
|
-
| **1.15–3 KB** | 599 | 2.02 kb | **2.89x** | 1.91x | 2.58x | **3.35k** | 68.4k | 35.8k |
|
|
159
190
|
|
|
160
|
-
|
|
191
|
+
| Tx Size Range | # Txns | Avg. Tx Size | JIT Ratio | FLZ Ratio | CD Ratio | JIT Gas | FLZ Gas | CD Gas |
|
|
192
|
+
|---|---|---|---|---|---|---|---|---|
|
|
193
|
+
| **> 8 KB** | 129 | 14.92 kb | **2.99x** | 3.63x | 2.90x | **8.02k** | 211.87k | 78.02k |
|
|
194
|
+
| **3–8 KB** | 260 | 4.82 kb | **2.79x** | 2.61x | 2.29x | **4.45k** | 89.41k | 29.40k |
|
|
195
|
+
| **1.15–3 KB** | 599 | 2.02 kb | **2.99x** | 1.99x | 1.80x | **3.38k** | 46.16k | 13.62k |
|
|
196
|
+
|
|
197
|
+
<sub>Excludes txns not compressible to <70% of its original size.</sub>
|
|
161
198
|
|
|
162
|
-
### Compression
|
|
163
|
-
- **JIT calldata compiler
|
|
199
|
+
### Compression flavors
|
|
200
|
+
- **JIT calldata compiler**: Views calldata as a zero‑initialized memory image and synthesizes bytecode that rebuilds it word-by-word in-place.
|
|
164
201
|
|
|
165
202
|
In the first pass it walks the data in 32-byte slices, detects non-zero segments per word, and for each word chooses the cheapest of three strategies: store a literal tail, assemble segments using SHL/OR, or reuse an earlier word via MLOAD/MSTORE.
|
|
166
|
-
|
|
167
|
-
In the second pass it materialises this plan into concrete PUSH/MSTORE/SHL/OR/DUP opcodes, pre-seeds the stack with frequently used constants, and appends a small CALL/RETURNDATA stub that forwards the reconstructed calldata to the original `to` address.
|
|
168
|
-
|
|
169
|
-
The execution is realized through a `stateDiff` passed together with the `eth_call`. The 4‑byte selector is right‑aligned in the first 32‑byte slot so that the rest of the calldata can be reconstructed on mostly word‑aligned boundaries, with the decompressor stateDiff being placed at `0x00000000000000000000000000000000000000e0` such that `0xe0` can be obtained from `ADDRESS` with a single opcode instead of an explicit literal.
|
|
170
203
|
|
|
171
|
-
|
|
204
|
+
In the second pass it materializes this plan into concrete PUSH/MSTORE/SHL/OR/DUP opcodes, pre-seeds the stack with frequently used constants, and appends a small CALL/RETURNDATA stub that forwards the reconstructed calldata to the original `to` address.
|
|
205
|
+
|
|
206
|
+
The 4‑byte selector is right‑aligned in the first 32‑byte slot so that the rest of the calldata can be reconstructed on mostly word‑aligned boundaries, with the decompressor stateDiff being placed at `0xe0` to obtain this common offset from `ADDRESS` with a single opcode instead of PUSH1 + literal.
|
|
207
|
+
|
|
208
|
+
- **FastLZ (FLZ)** and **calldata-RLE (CD)** forwarders are minimally adapted from Solady's [`LibZip.sol`](https://github.com/Vectorized/solady/blob/main/src/utils/LibZip.sol) and inlined as raw bytecode compiled from pure Yul. Both support all forwarding modes (`call`, `staticcall`, `delegatecall`) and the `revert` flag, with the target address patched into the bytecode at generation time.
|
|
172
209
|
|
package/_cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var u=Object.defineProperty;var
|
|
1
|
+
var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var R=(n,e)=>{for(var o in e)u(n,o,{get:e[o],enumerable:!0})},C=(n,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of b(e))!w.call(n,t)&&t!==o&&u(n,t,{get:()=>e[t],enumerable:!(s=m(e,t))||s.enumerable});return n};var E=n=>C(u({},"__esModule",{value:!0}),n);var v={};R(v,{MIN_BODY_SIZE:()=>_,compressModule:()=>M});module.exports=E(v);var _=1150,q=typeof CompressionStream<"u",S=new Map,I=["gzip","deflate"];async function M(n,e,o){let s=n instanceof Request?n:null,t=typeof n=="string"?n:n instanceof Request?n.url:n.toString(),r=typeof e?.body=="string"?e.body:null;if(typeof o=="function"){if(s&&!e)return fetch(s);let f=e?.body;if(r)try{let a=o(JSON.parse(r));a!==void 0&&(f=JSON.stringify(a))}catch{}return fetch(s??t,{...e,body:f})}let c=S.get(t),g=o==="gzip"||o==="deflate",i=q?g?o:o==="proactive"?c===-1?null:c??"gzip":typeof c=="string"?c:null:null,y=!!i&&!!r&&r.length>=1150,p={...e,priority:"high"},h=new Headers(p.headers);y&&(p.body=await new Response(new Blob([r]).stream().pipeThrough(new CompressionStream(i))).blob(),h.set("Content-Encoding",i)),p.headers=h;let d=await fetch(s??t,p);if(!g&&c===void 0){let a=d.headers.get("Accept-Encoding")?.split(",").map(l=>l.trim()).find(l=>I.includes(l))??-1;S.set(t,o==="proactive"&&y&&d.ok?i:a)}return d}0&&(module.exports={MIN_BODY_SIZE,compressModule});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/_cjs/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export const MIN_BODY_SIZE = 1150;\n\nconst _cache = new Map<string, string | -1>();\nconst _enc = ['gzip', 'deflate'] as const;\ntype SupportedEncoding = (typeof _enc)[number];\n\nexport type PayloadTransform = (payload: unknown) => unknown;\nexport type CompressionMode = 'passive' | 'proactive' | 'gzip' | 'deflate' | PayloadTransform;\n\n/**\n * @param input - URL or Request\n * @param init - Request options\n * @param mode - Compression mode:\n * - 'passive' (default): discover support via Accept-Encoding header first\n * - 'proactive': compress with gzip first, adjust if server rejects\n * - 'gzip' | 'deflate': use specified encoding directly (known support)\n * - PayloadTransform function: transform payload, skip HTTP compression\n */\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n mode?: CompressionMode,\n): Promise<Response> {\n const req = input instanceof Request ? input : null;\n const url =\n typeof input === 'string' ? input : input instanceof Request ? input.url : input.toString();\n const bodyStr = typeof init?.body === 'string' ? init.body : null;\n\n // Custom transform: apply and skip HTTP compression\n if (typeof mode === 'function') {\n if (req && !init) return fetch(req);\n let body = init?.body;\n if (bodyStr)\n try {\n const next = mode(JSON.parse(bodyStr));\n if (next !== undefined) body = JSON.stringify(next);\n } catch {}\n return fetch(req ?? url, { ...init, body });\n }\n\n const cached = _cache.get(url);\n const
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAAO,IAAME,EAAgB,KAEvBG,EAAS,IAAI,IACbC,EAAO,CAAC,OAAQ,SAAS,EAe/B,
|
|
6
|
-
"names": ["index_exports", "__export", "MIN_BODY_SIZE", "compressModule", "__toCommonJS", "_cache", "_enc", "input", "init", "mode", "req", "url", "bodyStr", "body", "next", "cached", "
|
|
4
|
+
"sourcesContent": ["export const MIN_BODY_SIZE = 1150;\n\nconst _hasCS = typeof CompressionStream !== 'undefined';\nconst _cache = new Map<string, string | -1>();\nconst _enc = ['gzip', 'deflate'] as const;\ntype SupportedEncoding = (typeof _enc)[number];\n\nexport type PayloadTransform = (payload: unknown) => unknown;\nexport type CompressionMode = 'passive' | 'proactive' | 'gzip' | 'deflate' | PayloadTransform;\n\n/**\n * @param input - URL or Request\n * @param init - Request options\n * @param mode - Compression mode:\n * - 'passive' (default): discover support via Accept-Encoding header first\n * - 'proactive': compress with gzip first, adjust if server rejects\n * - 'gzip' | 'deflate': use specified encoding directly (known support)\n * - PayloadTransform function: transform payload, skip HTTP compression\n */\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n mode?: CompressionMode,\n): Promise<Response> {\n const req = input instanceof Request ? input : null;\n const url =\n typeof input === 'string' ? input : input instanceof Request ? input.url : input.toString();\n const bodyStr = typeof init?.body === 'string' ? init.body : null;\n\n // Custom transform: apply and skip HTTP compression\n if (typeof mode === 'function') {\n if (req && !init) return fetch(req);\n let body = init?.body;\n if (bodyStr)\n try {\n const next = mode(JSON.parse(bodyStr));\n if (next !== undefined) body = JSON.stringify(next);\n } catch {}\n return fetch(req ?? url, { ...init, body });\n }\n\n const cached = _cache.get(url);\n const known = mode === 'gzip' || mode === 'deflate';\n const encoding = !_hasCS\n ? null\n : known\n ? (mode as SupportedEncoding)\n : mode === 'proactive'\n ? cached === -1\n ? null\n : (cached ?? 'gzip')\n : typeof cached === 'string'\n ? cached\n : null;\n\n const shouldCompress = !!encoding && !!bodyStr && bodyStr.length >= MIN_BODY_SIZE;\n const opts: RequestInit = { ...init, priority: 'high' as RequestPriority };\n const headers = new Headers(opts.headers);\n if (shouldCompress) {\n opts.body = await new Response(\n new Blob([bodyStr!])\n .stream()\n .pipeThrough(new CompressionStream(encoding as CompressionFormat)),\n ).blob();\n headers.set('Content-Encoding', encoding);\n }\n opts.headers = headers;\n\n const response = await fetch(req ?? url, opts);\n\n // Cache discovery for passive/proactive (not known modes)\n if (!known && cached === undefined) {\n const header = response.headers.get('Accept-Encoding');\n const discovered =\n header\n ?.split(',')\n .map((e) => e.trim())\n .find((e): e is SupportedEncoding => _enc.includes(e as SupportedEncoding)) ?? -1;\n _cache.set(\n url,\n mode === 'proactive' && shouldCompress ? (response.ok ? encoding! : discovered) : discovered,\n );\n }\n\n return response;\n}\n"],
|
|
5
|
+
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAAO,IAAME,EAAgB,KAEvBG,EAAS,OAAO,kBAAsB,IACtCC,EAAS,IAAI,IACbC,EAAO,CAAC,OAAQ,SAAS,EAe/B,eAAsBJ,EACpBK,EACAC,EACAC,EACmB,CACnB,IAAMC,EAAMH,aAAiB,QAAUA,EAAQ,KACzCI,EACJ,OAAOJ,GAAU,SAAWA,EAAQA,aAAiB,QAAUA,EAAM,IAAMA,EAAM,SAAS,EACtFK,EAAU,OAAOJ,GAAM,MAAS,SAAWA,EAAK,KAAO,KAG7D,GAAI,OAAOC,GAAS,WAAY,CAC9B,GAAIC,GAAO,CAACF,EAAM,OAAO,MAAME,CAAG,EAClC,IAAIG,EAAOL,GAAM,KACjB,GAAII,EACF,GAAI,CACF,IAAME,EAAOL,EAAK,KAAK,MAAMG,CAAO,CAAC,EACjCE,IAAS,SAAWD,EAAO,KAAK,UAAUC,CAAI,EACpD,MAAQ,CAAC,CACX,OAAO,MAAMJ,GAAOC,EAAK,CAAE,GAAGH,EAAM,KAAAK,CAAK,CAAC,CAC5C,CAEA,IAAME,EAASV,EAAO,IAAIM,CAAG,EACvBK,EAAQP,IAAS,QAAUA,IAAS,UACpCQ,EAAYb,EAEdY,EACGP,EACDA,IAAS,YACPM,IAAW,GACT,KACCA,GAAU,OACb,OAAOA,GAAW,SAChBA,EACA,KATN,KAWEG,EAAiB,CAAC,CAACD,GAAY,CAAC,CAACL,GAAWA,EAAQ,QAAU,KAC9DO,EAAoB,CAAE,GAAGX,EAAM,SAAU,MAA0B,EACnEY,EAAU,IAAI,QAAQD,EAAK,OAAO,EACpCD,IACFC,EAAK,KAAO,MAAM,IAAI,SACpB,IAAI,KAAK,CAACP,CAAQ,CAAC,EAChB,OAAO,EACP,YAAY,IAAI,kBAAkBK,CAA6B,CAAC,CACrE,EAAE,KAAK,EACPG,EAAQ,IAAI,mBAAoBH,CAAQ,GAE1CE,EAAK,QAAUC,EAEf,IAAMC,EAAW,MAAM,MAAMX,GAAOC,EAAKQ,CAAI,EAG7C,GAAI,CAACH,GAASD,IAAW,OAAW,CAElC,IAAMO,EADSD,EAAS,QAAQ,IAAI,iBAAiB,GAG/C,MAAM,GAAG,EACV,IAAKE,GAAMA,EAAE,KAAK,CAAC,EACnB,KAAMA,GAA8BjB,EAAK,SAASiB,CAAsB,CAAC,GAAK,GACnFlB,EAAO,IACLM,EACAF,IAAS,aAAeS,GAAkBG,EAAS,GAAKJ,EAA0BK,CACpF,CACF,CAEA,OAAOD,CACT",
|
|
6
|
+
"names": ["index_exports", "__export", "MIN_BODY_SIZE", "compressModule", "__toCommonJS", "_hasCS", "_cache", "_enc", "input", "init", "mode", "req", "url", "bodyStr", "body", "next", "cached", "known", "encoding", "shouldCompress", "opts", "headers", "response", "discovered", "e"]
|
|
7
7
|
}
|
package/_cjs/index.node.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var C=Object.create;var d=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var E=(t,s)=>{for(var e in s)d(t,e,{get:s[e],enumerable:!0})},b=(t,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of z(s))!D.call(t,o)&&o!==e&&d(t,o,{get:()=>s[o],enumerable:!(n=R(s,o))||n.enumerable});return t};var I=(t,s,e)=>(e=t!=null?C(q(t)):{},b(s||!t||!t.__esModule?d(e,"default",{value:t,enumerable:!0}):e,t)),_=t=>b(d({},"__esModule",{value:!0}),t);var M={};E(M,{MIN_BODY_SIZE:()=>k,compressModule:()=>x});module.exports=_(M);var r=I(require("node:zlib"),1);var k=1150,v=typeof CompressionStream<"u",S=new Map,T=["gzip","deflate"];async function x(t,s,e){let n=t instanceof Request?t:null,o=typeof t=="string"?t:t instanceof Request?t.url:t.toString(),a=typeof s?.body=="string"?s.body:null;if(typeof e=="function"){if(n&&!s)return fetch(n);let g=s?.body;if(a)try{let c=e(JSON.parse(a));c!==void 0&&(g=JSON.stringify(c))}catch{}return fetch(n??o,{...s,body:g})}let i=S.get(o),y=e==="gzip"||e==="deflate",l=v?y?e:e==="proactive"?i===-1?null:i??"gzip":typeof i=="string"?i:null:null,m=!!l&&!!a&&a.length>=1150,p={...s,priority:"high"},h=new Headers(p.headers);m&&(p.body=await new Response(new Blob([a]).stream().pipeThrough(new CompressionStream(l))).blob(),h.set("Content-Encoding",l)),p.headers=h;let f=await fetch(n??o,p);if(!y&&i===void 0){let c=f.headers.get("Accept-Encoding")?.split(",").map(u=>u.trim()).find(u=>T.includes(u))??-1;S.set(o,e==="proactive"&&m&&f.ok?l:c)}return f}var w=(t,s)=>Object.assign(t,{writable:new WritableStream({write(e){return s.write(e),Promise.resolve()},close(){return s.end(),Promise.resolve()}}),readable:new ReadableStream({type:"bytes",start(e){s.on("data",n=>e.enqueue(n)),s.once("end",()=>e.close())}})});globalThis.CompressionStream||(globalThis.CompressionStream=class{constructor(s){let e;s==="deflate"?e=r.default.createDeflate():s==="gzip"?e=r.default.createGzip():s==="br"?e=r.default.createBrotliCompress():e=r.default.createDeflateRaw(),w(this,e)}});globalThis.DecompressionStream||(globalThis.DecompressionStream=class{constructor(s){let e;s==="deflate"?e=r.default.createInflate():s==="gzip"?e=r.default.createGunzip():s==="br"?e=r.default.createBrotliDecompress():e=r.default.createInflateRaw(),w(this,e)}});0&&(module.exports={MIN_BODY_SIZE,compressModule});
|
|
2
2
|
//# sourceMappingURL=index.node.cjs.map
|
package/_cjs/index.node.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.node.ts", "../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import zlib from 'node:zlib';\n\n// Polyfill for CompressionStream/DecompressionStream in older versions of Node.js & Bun\nconst make = (ctx: any, handle: any) =>\n Object.assign(ctx, {\n writable: new WritableStream({\n write(chunk) {\n handle.write(chunk);\n return Promise.resolve();\n },\n close() {\n handle.end();\n return Promise.resolve();\n },\n }),\n readable: new ReadableStream({\n type: 'bytes',\n start(ctrl) {\n handle.on('data', (chunk: any) => ctrl.enqueue(chunk));\n handle.once('end', () => ctrl.close());\n },\n }),\n });\n\nif (!globalThis.CompressionStream) {\n globalThis.CompressionStream = class CompressionStream {\n constructor(format: string) {\n let handle;\n if (format === 'deflate') {\n handle = zlib.createDeflate();\n } else if (format === 'gzip') {\n handle = zlib.createGzip();\n } else if (format === 'br') {\n handle = zlib.createBrotliCompress();\n } else {\n handle = zlib.createDeflateRaw();\n }\n make(this, handle);\n }\n } as any;\n}\n\nif (!globalThis.DecompressionStream) {\n globalThis.DecompressionStream = class DecompressionStream {\n constructor(format: string) {\n let handle;\n if (format === 'deflate') {\n handle = zlib.createInflate();\n } else if (format === 'gzip') {\n handle = zlib.createGunzip();\n } else if (format === 'br') {\n handle = zlib.createBrotliDecompress();\n } else {\n handle = zlib.createInflateRaw();\n }\n make(this, handle);\n }\n } as any;\n}\n\nexport * from './index';\n", "export const MIN_BODY_SIZE = 1150;\n\nconst _cache = new Map<string, string | -1>();\nconst _enc = ['gzip', 'deflate'] as const;\ntype SupportedEncoding = (typeof _enc)[number];\n\nexport type PayloadTransform = (payload: unknown) => unknown;\nexport type CompressionMode = 'passive' | 'proactive' | 'gzip' | 'deflate' | PayloadTransform;\n\n/**\n * @param input - URL or Request\n * @param init - Request options\n * @param mode - Compression mode:\n * - 'passive' (default): discover support via Accept-Encoding header first\n * - 'proactive': compress with gzip first, adjust if server rejects\n * - 'gzip' | 'deflate': use specified encoding directly (known support)\n * - PayloadTransform function: transform payload, skip HTTP compression\n */\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n mode?: CompressionMode,\n): Promise<Response> {\n const req = input instanceof Request ? input : null;\n const url =\n typeof input === 'string' ? input : input instanceof Request ? input.url : input.toString();\n const bodyStr = typeof init?.body === 'string' ? init.body : null;\n\n // Custom transform: apply and skip HTTP compression\n if (typeof mode === 'function') {\n if (req && !init) return fetch(req);\n let body = init?.body;\n if (bodyStr)\n try {\n const next = mode(JSON.parse(bodyStr));\n if (next !== undefined) body = JSON.stringify(next);\n } catch {}\n return fetch(req ?? url, { ...init, body });\n }\n\n const cached = _cache.get(url);\n const
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAiB,0BCAV,IAAMC,EAAgB,KAEvBC,EAAS,IAAI,IACbC,EAAO,CAAC,OAAQ,SAAS,EAe/B,eAAsBC,EACpBC,EACAC,EACAC,EACmB,CACnB,IAAMC,EAAMH,aAAiB,QAAUA,EAAQ,KACzCI,EACJ,OAAOJ,GAAU,SAAWA,EAAQA,aAAiB,QAAUA,EAAM,IAAMA,EAAM,SAAS,EACtFK,EAAU,OAAOJ,GAAM,MAAS,SAAWA,EAAK,KAAO,KAG7D,GAAI,OAAOC,GAAS,WAAY,CAC9B,GAAIC,GAAO,CAACF,EAAM,OAAO,MAAME,CAAG,EAClC,IAAIG,EAAOL,GAAM,KACjB,GAAII,EACF,GAAI,CACF,IAAME,EAAOL,EAAK,KAAK,MAAMG,CAAO,CAAC,EACjCE,IAAS,SAAWD,EAAO,KAAK,UAAUC,CAAI,EACpD,MAAQ,CAAC,CACX,OAAO,MAAMJ,GAAOC,EAAK,CAAE,GAAGH,EAAM,KAAAK,CAAK,CAAC,CAC5C,CAEA,IAAME,EAASX,EAAO,IAAIO,CAAG,EACvBK,
|
|
6
|
-
"names": ["index_node_exports", "__export", "MIN_BODY_SIZE", "compressModule", "__toCommonJS", "import_node_zlib", "MIN_BODY_SIZE", "_cache", "_enc", "compressModule", "input", "init", "mode", "req", "url", "bodyStr", "body", "next", "cached", "
|
|
4
|
+
"sourcesContent": ["import zlib from 'node:zlib';\n\n// Polyfill for CompressionStream/DecompressionStream in older versions of Node.js & Bun\nconst make = (ctx: any, handle: any) =>\n Object.assign(ctx, {\n writable: new WritableStream({\n write(chunk) {\n handle.write(chunk);\n return Promise.resolve();\n },\n close() {\n handle.end();\n return Promise.resolve();\n },\n }),\n readable: new ReadableStream({\n type: 'bytes',\n start(ctrl) {\n handle.on('data', (chunk: any) => ctrl.enqueue(chunk));\n handle.once('end', () => ctrl.close());\n },\n }),\n });\n\nif (!globalThis.CompressionStream) {\n globalThis.CompressionStream = class CompressionStream {\n constructor(format: string) {\n let handle;\n if (format === 'deflate') {\n handle = zlib.createDeflate();\n } else if (format === 'gzip') {\n handle = zlib.createGzip();\n } else if (format === 'br') {\n handle = zlib.createBrotliCompress();\n } else {\n handle = zlib.createDeflateRaw();\n }\n make(this, handle);\n }\n } as any;\n}\n\nif (!globalThis.DecompressionStream) {\n globalThis.DecompressionStream = class DecompressionStream {\n constructor(format: string) {\n let handle;\n if (format === 'deflate') {\n handle = zlib.createInflate();\n } else if (format === 'gzip') {\n handle = zlib.createGunzip();\n } else if (format === 'br') {\n handle = zlib.createBrotliDecompress();\n } else {\n handle = zlib.createInflateRaw();\n }\n make(this, handle);\n }\n } as any;\n}\n\nexport * from './index';\n", "export const MIN_BODY_SIZE = 1150;\n\nconst _hasCS = typeof CompressionStream !== 'undefined';\nconst _cache = new Map<string, string | -1>();\nconst _enc = ['gzip', 'deflate'] as const;\ntype SupportedEncoding = (typeof _enc)[number];\n\nexport type PayloadTransform = (payload: unknown) => unknown;\nexport type CompressionMode = 'passive' | 'proactive' | 'gzip' | 'deflate' | PayloadTransform;\n\n/**\n * @param input - URL or Request\n * @param init - Request options\n * @param mode - Compression mode:\n * - 'passive' (default): discover support via Accept-Encoding header first\n * - 'proactive': compress with gzip first, adjust if server rejects\n * - 'gzip' | 'deflate': use specified encoding directly (known support)\n * - PayloadTransform function: transform payload, skip HTTP compression\n */\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n mode?: CompressionMode,\n): Promise<Response> {\n const req = input instanceof Request ? input : null;\n const url =\n typeof input === 'string' ? input : input instanceof Request ? input.url : input.toString();\n const bodyStr = typeof init?.body === 'string' ? init.body : null;\n\n // Custom transform: apply and skip HTTP compression\n if (typeof mode === 'function') {\n if (req && !init) return fetch(req);\n let body = init?.body;\n if (bodyStr)\n try {\n const next = mode(JSON.parse(bodyStr));\n if (next !== undefined) body = JSON.stringify(next);\n } catch {}\n return fetch(req ?? url, { ...init, body });\n }\n\n const cached = _cache.get(url);\n const known = mode === 'gzip' || mode === 'deflate';\n const encoding = !_hasCS\n ? null\n : known\n ? (mode as SupportedEncoding)\n : mode === 'proactive'\n ? cached === -1\n ? null\n : (cached ?? 'gzip')\n : typeof cached === 'string'\n ? cached\n : null;\n\n const shouldCompress = !!encoding && !!bodyStr && bodyStr.length >= MIN_BODY_SIZE;\n const opts: RequestInit = { ...init, priority: 'high' as RequestPriority };\n const headers = new Headers(opts.headers);\n if (shouldCompress) {\n opts.body = await new Response(\n new Blob([bodyStr!])\n .stream()\n .pipeThrough(new CompressionStream(encoding as CompressionFormat)),\n ).blob();\n headers.set('Content-Encoding', encoding);\n }\n opts.headers = headers;\n\n const response = await fetch(req ?? url, opts);\n\n // Cache discovery for passive/proactive (not known modes)\n if (!known && cached === undefined) {\n const header = response.headers.get('Accept-Encoding');\n const discovered =\n header\n ?.split(',')\n .map((e) => e.trim())\n .find((e): e is SupportedEncoding => _enc.includes(e as SupportedEncoding)) ?? -1;\n _cache.set(\n url,\n mode === 'proactive' && shouldCompress ? (response.ok ? encoding! : discovered) : discovered,\n );\n }\n\n return response;\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["index_node_exports", "__export", "MIN_BODY_SIZE", "compressModule", "__toCommonJS", "import_node_zlib", "MIN_BODY_SIZE", "_hasCS", "_cache", "_enc", "compressModule", "input", "init", "mode", "req", "url", "bodyStr", "body", "next", "cached", "known", "encoding", "shouldCompress", "opts", "headers", "response", "discovered", "e", "make", "ctx", "handle", "chunk", "ctrl", "format", "zlib"]
|
|
7
7
|
}
|
package/_cjs/jit-compressor.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var rt=Object.defineProperty;var _t=Object.getOwnPropertyDescriptor;var Ot=Object.getOwnPropertyNames;var kt=Object.prototype.hasOwnProperty;var Wt=(s,o)=>{for(var l in o)rt(s,l,{get:o[l],enumerable:!0})},Ft=(s,o,l,m)=>{if(o&&typeof o=="object"||typeof o=="function")for(let f of Ot(o))!kt.call(s,f)&&f!==l&&rt(s,f,{get:()=>o[f],enumerable:!(m=_t(o,f))||m.enumerable});return s};var qt=s=>Ft(rt({},"__esModule",{value:!0}),s);var Ht={};Wt(Ht,{compress_call:()=>Lt});module.exports=qt(Ht);var at=require("solady");var mt=(1n<<128n)-1n,M=(1n<<256n)-1n;var tt=s=>~s&M;var dt=(s,o)=>s&o&M,xt=(s,o)=>(s|o)&M,ht=(s,o)=>(s^o)&M,pt=(s,o)=>s+o&M,st=(s,o)=>s-o&M,ot=(s,o)=>o<<s&M,it=(s,o)=>o>>s&M,ct=(s,o)=>{let l=Number(s)+1,m=(1n<<BigInt(l*8))-1n,f=1n<<BigInt(l*8-1),d=o&m;return((d&f)!==0n?d|~m&M:d)&M};var O=s=>s.replace(/^0x/,"").toLowerCase(),zt=s=>{let o=O(s),l=o.length,m=new Uint8Array(l/2);for(let f=0;f<l;f+=2)m[f/2]=Number.parseInt(o.slice(f,f+2),16);return m},Z=s=>{let o="";for(let l=0;l<s.length;l++)o+=s[l].toString(16).padStart(2,"0");return o},yt=(s,o)=>{let l=O(s),m=zt(l),f=new Uint8Array(o+m.length);f.set(m,o);let d=f.length,w=Math.ceil(d/32),k=w*32,N=new Array(w),I=new Array(w),z=new Map,S=new Map,p=null;for(let r=0;r<w;r++){let u=r*32,b=new Uint8Array(32);if(u<d){let c=Math.min(u+32,d);b.set(f.subarray(u,c),0)}N[r]=b;let C=Z(b),L=S.get(C),nt=p===C;if(L)L.freq+=1,nt||(L.normFreq+=1),L.lastWordIndex=r,L.lastOffset=u,z.set(C,L.freq);else{let c={freq:1,normFreq:1,firstWordIndex:r,lastWordIndex:r,firstOffset:u,lastOffset:u,reuseCost:-1};S.set(C,c),z.set(C,1)}p=C;let U=[];for(let c=0;c<32;){for(;c<32&&b[c]===0;)++c;if(c>=32)break;let q=c;for(;c<32&&b[c]!==0;)++c;U.push({s:q,e:c-1})}I[r]=U}for(let r of S.values()){let b=(r.firstOffset===0?0:Math.ceil(Math.log2(r.firstOffset+1)/8))+3,C=r.normFreq*32,L=r.normFreq*b;r.reuseCost=C>L?b:-1}let W=new Uint8Array(32),x=r=>r<0||r>=w?W:N[r],F=r=>r<0||r>=w?[]:I[r],j=r=>{let u=new Uint8Array(32);if(r<0||r>=d)return u;let b=Math.min(r+32,d);return u.set(f.slice(r,b),0),u},V=(r,u)=>{if(u<=0)return new Uint8Array(0);let b=new Uint8Array(u);if(r<0||r>=d)return b;let C=Math.min(r+u,d);return b.set(f.slice(r,C),0),b};return{hex:l,buffer:f,roundedLength:k,padding:o,dataLength:m.length,wordCount:w,wordFreq:z,wordStats:S,getWord:x,getSegments:F,mload:j,slice:V}};var ft=function(s,o,l){let m=28,f=yt(s,m),d=224n,w=O(o).padStart(16,"0"),k=l?BigInt("0x"+O(l)):96n,N=new Set([0n,32n,d,k,BigInt("0x"+w)]),I=2n,z=Array.from(f.wordFreq.entries()).map(([t,e])=>[BigInt("0x"+t),e]).filter(([t])=>!N.has(t));z.length>0&&(I=z.reduce((t,e)=>e[1]>t[1]?e:t)[0]);let{wordCount:S}=f,p=[],W=[],x=[],F=0,j=new Map,V=!0,r=t=>t+31&-32,u=t=>{let e=x.lastIndexOf(t);return e=e===-1?-1:x.length-1-e,e>15?-1:e},b=new Map,C=new Map,L=0,nt=(t,e,n)=>t.set(e,(t.get(e)||0)+n),U=(t,e)=>{p.push(t),W.push(e??null)},c=(t,e=1)=>{x.push(t),e!==0&&nt(b,t,e),++L,C.set(t,L)},q=()=>[x.pop(),x.pop()],lt=(t,e)=>{F=r(t+e)},D=(t,e)=>{if(t==128){let n=x[x.length-1];c(n,V?0:1)}if(t==80&&x.pop(),t==71&&c(I,0),t==48&&c(d,0),t==51&&c(k,0),t==54&&c(32n,0),t==89&&c(BigInt(F),0),t===11){let[n,i]=q();c(ct(n,i),1)}if(t==25){let n=x.pop();c(tt(n),0)}if(t===24){let[n,i]=q();c(ht(n,i),1)}if(t==22){let[n,i]=q();c(dt(n,i),1)}if(t==23){let[n,i]=q();c(xt(n,i),1)}if(t==1){let[n,i]=q();c(pt(n,i),1)}if(t===3){let[n,i]=q();c(st(i,n),1)}if(t==27){let[n,i]=q();c(ot(n,i),1)}if(t==28){let[n,i]=q();c(it(n,i),1)}if(t>=96&&t<=127||t===95){let n=0n;for(let g of e||[])n=n<<8n|BigInt(g);if(n==I){c(n,0),U(71);return}if(n==d){c(n,0),U(48);return}if(n==k){c(n,0),U(51);return}if(n==32n){c(n,0),U(54);return}if(n===BigInt(F)&&n!==0n){c(n,0),U(89);return}let i=u(n);if(i!==-1&&t!==95){c(n,V?1:0),U(128+i);return}if(n===M){c(n,0),U(95),U(25);return}c(n,1),U(t,e||null);return}if(t===81){let n=Number(x.pop());c(j.has(n)?j.get(n):0n,0)}if(t===82){let[n,i]=q(),g=Number(n);j.set(g,i&M),lt(g,32)}if(t===83){let[n,i]=q();lt(Number(n),1)}U(t,e||null)},$=t=>D(t),Bt=t=>{if(t===0n)return 0;let e=0,n=t<0n?-t:t;for(;n>0n;)++e,n>>=8n;return e},P=t=>t===0n?1:1+Bt(t),X=t=>{let e=typeof t=="bigint"?t:BigInt(t);if(e>0n&&e===BigInt(F))return D(89);if(e===32n)return D(54);if(e===0n)return D(95);let n=e,i=[];for(;n!==0n;)i.unshift(Number(n&0xffn)),n>>=8n;return D(95+i.length,i)},ut=t=>D(95+t.length,Array.from(t)),Y=[],B=t=>{Y.push({t:"num",v:t}),X(t)},bt=t=>{Y.push({t:"bytes",b:t}),ut(t)},y=t=>{Y.push({t:"op",o:t}),$(t)},At=t=>{let e=0,n=!0;for(let{s:i,e:g}of t)e+=1+(g-i+1),31-g>0&&(e+=3),n||(e+=1),n=!1;return e},gt=(t,e)=>{let n=t.slice(e[0].s),i=0n;for(let a of n)i=i<<8n|BigInt(a);let g=1+n.length,E=At(e),_=g,v=()=>bt(n),G=tt(i),J=P(G)+1;J<_&&(_=J,v=()=>{B(G),y(25)});let R=st(0n,i),h=1+P(R)+1;h<_&&(_=h,v=()=>{B(0),B(R),y(3)});for(let a=1;a<n.length;a++){let T=(1n<<BigInt(a*8))-1n,H=i&T;if(ct(BigInt(a-1),H)===i&&(H&1n<<BigInt(a*8-1))!==0n){let K=P(H)+2+1;K<_&&(_=K,v=()=>{B(H),B(a-1),y(11)});break}}for(let a=8;a<=248;a+=8){let T=it(BigInt(a),i);if(T===0n)break;let H=tt(T);if(ot(BigInt(a),H)===i){let K=P(H)+P(BigInt(a))+2;K<_&&(_=K,v=()=>{B(H),B(a),y(27),y(25)})}}return E<_&&(_=E,v=()=>{let a=!0;for(let{s:T,e:H}of e){let Q=31-H;bt(t.slice(T,H+1)),Q>0&&(B(Q*8),y(27)),a||y(23),a=!1}}),{literal:n,literalVal:i,bestCost:_,bestEmit:v,literalCost:g,shlCost:E}},A=0;for(;A<S;){let t=A*32,e=f.getWord(A),n=f.getSegments(A);if(!n.length){++A;continue}let i=Z(e),g=1;for(;A+g<S;){let h=f.getWord(A+g);if(!f.getSegments(A+g).length||Z(h)!==i)break;++g}if(g>=2){let{bestEmit:h}=gt(e,n);h(),y(128),B(t),y(82);for(let T=1;T<g;T++)y(128),y(89),y(82);let a=f.wordStats.get(i);a&&a.lastWordIndex<=A+g-1&&y(80),A+=g;continue}let{literalCost:E,shlCost:_,bestCost:v,bestEmit:G}=gt(e,n);if(E>8){let h=f.wordStats.get(i);if(h&&h.reuseCost!==-1&&A>h.firstWordIndex){let a=h.firstOffset===0?0:Math.ceil(Math.log2(h.firstOffset+1)/8);if(E>h.reuseCost+a){B(h.firstOffset),y(81),B(t),y(82),++A;continue}}}let J=n.every(({s:h,e:a})=>h===a),R=n.length*3;if(J&&R<v&&R<=_){for(let{s:h}of n)B(e[h]),B(t+h),y(83);++A;continue}G(),B(t),y(82),++A}let Mt=Y.slice();p=[],W=[],x=[],F=0,j=new Map,V=!1;let It=new Set([0n,32n,I,d,k]);Array.from(b.entries()).filter(([t,e])=>e>1&&!It.has(t)).map(([t,e])=>{let n=P(t),i=e*(n-1)-n;return{val:t,uses:e,net:i,p:n}}).sort((t,e)=>e.net!==t.net?e.net-t.net:e.uses!==t.uses?e.uses-t.uses:t.p-e.p).filter(t=>t.net>0&&t.val<=mt).slice(0,15).forEach(({val:t})=>{X(t)});for(let t of Mt)t.t==="num"?X(t.v):t.t==="bytes"?ut(t.b):t.t==="op"&&$(t.o);$(95),$(95),X(f.dataLength),X(m);let et=[];for(let t=0;t<p.length;++t)et.push(p[t]),p[t]>=96&&p[t]<=127&&W[t]&&et.push(...W[t]);let Ct="0x"+Z(new Uint8Array(et))+"345f355af13d5f5f3e3d5ff3",Ut="0x"+O(w).padStart(64,"0");return{bytecode:Ct,calldata:Ut,to:"0x"+d.toString(16).padStart(40,"0"),from:O(k.toString(16)).padStart(40,"0"),balance:I.toString(16)}};var wt=s=>`0x365f73${O(s)}815b838110602f575f80848134865af1503d5f803e3d5ff35b803590815f1a8060051c908115609857600190600783149285831a6007018118840218600201948383011a90601f1660081b0101808603906020811860208211021890815f5b80830151818a015201858110609257505050600201019201916018565b82906075565b6001929350829150019101925f5b82811060b3575001916018565b85851060c1575b60010160a6565b936001818192355f1a878501530194905060ba56`;var St=s=>`0x5f5f5b368110602d575f8083813473${O(s)}5af1503d5f803e3d5ff35b600180820192909160031981019035185f1a8015604c57815301906002565b505f19815282820192607f9060031981019035185f1a818111156072575b160101906002565b838101368437606a56`;var Lt=function(s,o){let{method:l,params:m}=s;if(l&&l!=="eth_call")return s;let f=m?.[0]||s,d=m?.[1],w=m?.[2];if(w&&Object.keys(w).length>0||!f?.to||!f?.data||Object.keys(f).some(r=>!["to","data","from"].includes(r)))return s;let k=f.data.length;if(k<1150)return s;let N="0x"+O(f.data),I=f.to,z=f.from,S,p,W,x,F;if(o==="jit"||!o&&(k<3e3||k>=8e3)){let r=ft(N,I,z);S=r.bytecode,p=r.calldata,W=r.to,x=r.from,F=r.balance}else{let r=o?null:ft(N,I,z),u=o==="flz"||!o?at.LibZip.flzCompress(N):null,b=o==="cd"||!o&&u?at.LibZip.cdCompress(N):null;o==="flz"||!o&&u&&(!b||u.length<b.length)?(p=u,S=wt(I)):(p=b,S=St(I)),W="0x"+224n.toString(16).padStart(40,"0"),x=z?O(z).padStart(16,"0"):void 0,F="0",!o&&r&&r.bytecode.length+r.calldata.length<S.length+p.length&&(S=r.bytecode,p=r.calldata,W=r.to,x=r.from,F=r.balance)}if(S.length+p.length>=k)return s;let j={code:S,balance:"0x"+F},V={to:W,data:p};return x&&(V.from="0x"+x),{...s,params:[V,d,{...w,[W]:j}]}};
|
|
1
|
+
var ut=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Zt=Object.prototype.hasOwnProperty;var Yt=(r,e)=>{for(var a in e)ut(r,a,{get:e[a],enumerable:!0})},vt=(r,e,a,b)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Kt(e))!Zt.call(r,l)&&l!==a&&ut(r,l,{get:()=>e[l],enumerable:!(b=Rt(e,l))||b.enumerable});return r};var Gt=r=>vt(ut({},"__esModule",{value:!0}),r);var fn={};Yt(fn,{compress_call:()=>cn});module.exports=Gt(fn);var yt=require("solady");var Ct=(1n<<128n)-1n,W=(1n<<256n)-1n;var ft=r=>~r&W;var Ut=(r,e)=>r&e&W,Wt=(r,e)=>(r|e)&W,Ft=(r,e)=>(r^e)&W,zt=(r,e)=>r+e&W,bt=(r,e)=>r-e&W,dt=(r,e)=>e<<r&W,gt=(r,e)=>e>>r&W,xt=(r,e)=>{if(r>=31n)return e&W;let a=Number((r+1n)*8n);return BigInt.asUintN(256,BigInt.asIntN(a,e))};var P=r=>(r.charCodeAt(0)===48&&(r.charCodeAt(1)|32)===120?r.slice(2):r).toLowerCase(),Jt=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0")),kt=(()=>{let r=new Int8Array(103).fill(-1);for(let e=0;e<10;e++)r[48+e]=e;for(let e=0;e<6;e++)r[97+e]=10+e;return r})(),Qt=r=>{let e=P(r),a=e.length,b=new Uint8Array(a/2);for(let l=0,f=0;l<a;l+=2)b[f++]=kt[e.charCodeAt(l)]<<4|kt[e.charCodeAt(l+1)];return b},mt=r=>{let e="";for(let a=0;a<r.length;a++)e+=Jt[r[a]];return e},$t=new Uint8Array(32),tn=[],Ht=(r,e)=>{let a=P(r),b=Qt(a),l=new Uint8Array(e+b.length);l.set(b,e);let f=l.length,u=Math.ceil(f/32),S=u*32;if(f!==S){let i=new Uint8Array(S);i.set(l,0),l=i}let k=new Array(u),T=new Array(u),H=new Map,j=null,F=i=>{let p=i<<5;return l.subarray(p,p+32)};for(let i=0;i<u;i++){let p=i<<5,y=F(i),h=mt(y);T[i]=h;let O=H.get(h),d=j===h;if(O)O[0]+=1,d||(O[1]+=1),O[3]=i,O[5]=p;else{let w=[1,1,i,i,p,p,-1];H.set(h,w)}j=h;let V=[];for(let w=0;w<32;){for(;w<32&&y[w]===0;)++w;if(w>=32)break;let nt=w;for(;w<32&&y[w]!==0;)++w;V.push(nt<<8|w-1)}k[i]=V}for(let i of H.values()){let y=(i[4]===0?0:32-Math.clz32(i[4])+7>>3)+3;i[6]=32>y?y:-1}let D=i=>i<0||i>=u?$t:F(i),I=i=>i<0||i>=u?tn:k[i],A=(i,p)=>{if(p<=0)return new Uint8Array(0);let y=new Uint8Array(p);if(i<0||i>=f)return y;let h=Math.min(i+p,f);return y.set(l.subarray(i,h),0),y},m=i=>A(i,32);return{hex:a,buffer:l,roundedLength:S,padding:e,dataLength:b.length,wordCount:u,wordHexes:T,wordStats:H,getWord:D,getSegments:I,mload:m,slice:A}};var pt="0x00000000000000000000000000000000000000e0",v=r=>r.padStart(64,"0"),nn=v("0"),en=v("20"),rn=v("e0"),on="3d5f5f3e3d5ff3",sn="3d5f5f3e3d5ffd",ht=function(r,e,a,b="call",l=!1,f=!1){let u=a?P(a):null,S=f||b==="none",k=28,T=null,H=0,j=P(e).padStart(16,"0"),F=u?BigInt("0x"+u):96n,D=2n,I=[],A=[],m=[],i=0,p=[],y=!0,h=Ht(r,k),{wordCount:O}=h,d=224n,V=new Map,w=rn,nt=v(u??F.toString(16)),et=v(j);for(let[t,o]of h.wordStats){let n=o[0];t===nn||t===en||t===w||t===nt||t===et||n>H&&(H=n,T=t)}T&&(D=BigInt("0x"+T));let rt=t=>t+31&-32,Z=t=>{for(let o=m.length-1,n=0;n<16&&o>=0;--o,++n)if(m[o]===t)return n;return-1},jt=(t,o,n)=>t.set(o,(t.get(o)||0)+n),N=(t,o)=>{I.push(t),A.push(o??null),at+=BigInt(1+(t>=96&&t<=127?t-95:0))},g=(t,o=1)=>{m.push(t),o!==0&&jt(V,t,o)},E=()=>[m.pop(),m.pop()],St=(t,o)=>{i=rt(t+o)},at=0n,G=(t,o)=>{if(t===128&&g(m[m.length-1],y?0:1),t===80&&m.pop(),t===71&&g(D,0),t===48&&g(d,0),t===51&&g(F,0),t===54&&g(32n,0),t===89&&g(BigInt(i),0),t===11){let[n,s]=E();g(xt(n,s),1)}if(t===25&&g(ft(m.pop()),0),t===24){let[n,s]=E();g(Ft(n,s),1)}if(t===22){let[n,s]=E();g(Ut(n,s),1)}if(t===23){let[n,s]=E();g(Wt(n,s),1)}if(t===1){let[n,s]=E();g(zt(n,s),1)}if(t===3){let[n,s]=E();g(bt(s,n),1)}if(t===27){let[n,s]=E();g(dt(n,s),1)}if(t===28){let[n,s]=E();g(gt(n,s),1)}if(t>=96&&t<=127||t===95){let n=0n;for(let x of o||[])n=n<<8n|BigInt(x);if(!S){if(n===D){g(n,0),N(71);return}if(n===d){g(n,0),N(48);return}if(n===F){g(n,0),N(51);return}if(n===32n){g(n,0),N(54);return}}if(n===BigInt(i)&&n!=0n){g(n,0),N(89);return}let s=Z(n);if(s!=-1&&t!=95){g(n,y?1:0),N(128+s);return}if(!y&&t!==95&&n===at){g(n,0),N(88);return}if(n===W){g(n,0),N(95),N(25);return}g(n,1),N(t,o||null);return}if(t===81&&g(p[Number(m.pop())>>>5]??0n,0),t===82){let[n,s]=E(),x=Number(n);p[x>>>5]=s&W,St(x,32)}if(t===83){let[n,s]=E();St(Number(n),1)}N(t,o||null)},J=t=>G(t),At=t=>{if(t===0n)return 0;let o=0,n=t<0n?-t:t;for(;n>0n;)++o,n>>=8n;return o},R=t=>t===0n||t===1n||t!==0n&&t===BigInt(i)?1:t===W?2:1+At(t),K=t=>{let o=typeof t=="bigint"?t:BigInt(t);if(o>0n&&o===BigInt(i))return G(89);if(o===0n)return G(95);let n=o,s=At(n),x=new Uint8Array(s);for(let L=s-1;L>=0;--L)x[L]=Number(n&0xffn),n>>=8n;return G(95+s,x)},wt=t=>G(95+t.length,t),ot=[],C=t=>{ot.push({t:"num",v:t}),K(t)},_t=t=>{ot.push({t:"bytes",b:t}),wt(t)},B=t=>{ot.push({t:"op",o:t}),J(t)},Vt=t=>{let o=0,n=!0;for(let s=0;s<t.length;s++){let x=t[s],L=x>>>8,M=x&255;o+=1+(M-L+1),31-M>0&&(o+=3),n||(o+=1),n=!1}return o},Bt=(t,o)=>{let n=t.subarray(o[0]>>>8),s=0n;for(let c=0;c<n.length;c++)s=s<<8n|BigInt(n[c]);let x=R(s),L=Vt(o),M=x,q=()=>_t(n),it=ft(s),ct=R(it)+1;ct<M&&(M=ct,q=()=>{C(it),B(25)});let $=bt(0n,s),tt=R($)+2;tt<M&&(M=tt,q=()=>{C(0),C($),B(3)});for(let c=1;c<n.length;c++){let _=(1n<<BigInt(c*8))-1n,U=s&_;if(xt(BigInt(c-1),U)===s&&(U&1n<<BigInt(c*8-1))!==0n){let X=R(U)+3;X<M&&(M=X,q=()=>{C(U),C(c-1),B(11)});break}}for(let c=8;c<=248;c+=8){let _=gt(BigInt(c),s);if(_===0n)break;let U=ft(_);if(dt(BigInt(c),U)===s){let X=R(U)+R(BigInt(c))+2;X<M&&(M=X,q=()=>{C(U),C(c),B(27),B(25)})}}return L<M&&(M=L,q=()=>{let c=!0;for(let _=0;_<o.length;_++){let U=o[_],Y=U>>>8,X=U&255,It=31-X;_t(t.subarray(Y,X+1)),It>0&&(C(It*8),B(27)),c||B(23),c=!1}}),{literal:n,literalVal:s,bestCost:M,bestEmit:q,literalCost:x,shlCost:L}},z=0;for(;z<O;){let t=z*32,o=h.getWord(z),n=h.getSegments(z);if(!n.length){++z;continue}let s=h.wordHexes[z],x=z+1;for(;x<O&&!(!h.getSegments(x).length||h.wordHexes[x]!==s);)++x;let L=x-z;if(L>=2){let c=x-1,{bestEmit:_}=Bt(o,n);_(),B(128),C(t),B(82);for(let Y=1;Y<L;Y++)B(128),B(89),B(82);let U=h.wordStats.get(s);U&&U[3]<=c&&B(80),z=x;continue}let{literalCost:M,shlCost:q,bestCost:it,bestEmit:ct}=Bt(o,n);if(M>8){let c=h.wordStats.get(s);if(c&&c[6]!==-1&&z>c[2]){let _=c[4]===0?0:32-Math.clz32(c[4])+7>>3;if(M>c[6]+_){C(c[4]),B(81),C(t),B(82),++z;continue}}}let $=!0;for(let c=0;c<n.length;c++){let _=n[c];if(_>>>8!==(_&255)){$=!1;break}}let tt=n.length*3;if($&&tt<it&&tt<=q){for(let c=0;c<n.length;c++){let _=n[c]>>>8;C(o[_]),C(t+_),B(83)}++z;continue}ct(),C(t),B(82),++z}I=[],A=[],m=[],i=0,p=[],y=!1,at=0n;let st=[];for(let[t,o]of V)if(o>1&&t!==0n&&t!==32n&&t!==D&&t!==d&&t!==F&&t<=Ct){let n=R(t),s=o*(n-1)-n;s>0&&st.push({val:t,uses:o,net:s,p:n})}st.sort((t,o)=>o.net-t.net||o.uses-t.uses||t.p-o.p);for(let t=0;t<15&&t<st.length;++t)K(st[t].val);for(let t of ot)t.t==="num"?K(t.v):t.t==="bytes"?wt(t.b):t.t==="op"&&J(t.o);let Q="";b==="none"?(K(h.dataLength),K(k),J(l?253:243)):(J(95),J(95),K(h.dataLength),K(k),b==="call"?Q="345f355af1":b==="delegatecall"?Q="5f355af4":Q="5f355afa",Q+=l?sn:on);let Mt=I.length;for(let t=0;t<I.length;++t)I[t]>=96&&I[t]<=127&&A[t]&&(Mt+=A[t].length);let lt=new Uint8Array(Mt);for(let t=0,o=0;t<I.length;++t)lt[o++]=I[t],I[t]>=96&&I[t]<=127&&A[t]&&(lt.set(A[t],o),o+=A[t].length);let Et="0x"+mt(lt)+Q,Pt="0x"+v(j),qt=S?u?u.padStart(40,"0"):void 0:F.toString(16).padStart(40,"0"),Xt=S?"0":D.toString(16);return{bytecode:Et,calldata:Pt,to:pt,from:qt,balance:Xt}};var Dt=(r,e,a,b,l)=>{let f=u=>u.toString(16).padStart(2,"0");return"5b803590815f1a918260051c908160"+f(r)+"575050906002818360018095013586520101920101906002565b600260078396949314958260011a87020194611f0082870193886001011a9160081b16019560018701968503930101945f198301518452808211602083111760"+f(e)+"575b50505001600201906002565b6020811860208211021891825b82811060"+f(a)+"575060"+f(b)+"565b8181015f19015185820152830160"+f(l)+"56"},Lt="578082527f"+"7f".repeat(32)+"8082168101909117171980157fc0c8c8d0c8e8d0d8c8e8e0e8d0d8e0f0c8d0e8d0e0e0d8f0d0d0e0d8f8f8f8f8601f6f8421084210842108cc6318c6db6d54be660204081020408185821060071b86811c6001600160401b031060061b1795861c0260181a1c161a90911860031c019081019101368110",Ot=(r,e)=>"5b50"+r+"565b90610006565b60029060011a920191608081600101111561"+e+"575f19825201607e1901368210610006575f91508190"+r+"565b5f825201600101368210610006575f91508190"+r+"56";var Nt=(r,e="call",a=!1)=>{let b=a?"fd":"f3";if(e==="none")return"0x5f5f5b368110600c57505f"+b+Dt(53,132,156,120,145);let l=P(r).padStart(40,"0"),f=e==="call"?1:0,u=k=>k.toString(16).padStart(2,"0"),S=e==="delegatecall"?"f4":e==="call"?"f1":"fa";return"0x5f5f5b36811060"+u(50+f)+"575f808381"+(f?"34":"")+"73"+l+"5a"+S+"3d5f803e60"+u(46+f)+"573d5ffd5b3d5f"+b+Dt(91+f,170+f,194+f,158+f,183+f)};var Tt=(r,e="call",a=!1)=>{let b=a?"fd":"f3";if(e==="none")return"0x365f80375f365b8151805f1a156100cf"+Lt+"6100c957368111156100c35736900390035b36900336"+b+Ot("6100bd","6100fb");let l=P(r).padStart(40,"0"),f=e==="call"?1:0,u=k=>k.toString(16).padStart(2,"0"),S=e==="delegatecall"?"f4":e==="call"?"f1":"fa";return"0x365f80375f365b8151805f1a156100"+u(248+f)+Lt+"6100"+u(242+f)+"575f918291368111156100"+u(236+f)+"5736900390035b36900336"+(f?"34":"")+"73"+l+"5a"+S+"3d5f803e6100"+u(232+f)+"573d5ffd5b3d5f"+b+Ot("6100c1","01"+u(39+f))};var cn=function(r,e,a="call",b=!1,l=!1){let{method:f,params:u}=r;if(f&&f!=="eth_call")return r;let S=u?.[0]||r,k=u?.[1],T=u?.[2];if(!S?.to||!S?.data||(()=>{if(T)for(let d in T)return!0;for(let d in S)if(d!=="to"&&d!=="data"&&d!=="from")return!0;return!1})())return r;let H=S.data.length;if(H<1150)return r;let j=S.data,F=S.to,D=S.from,I=a==="none",A,m,i,p,y;if(I||e==="jit"||!e&&(H<3e3||H>=8e3)){let d=ht(j,F,D,a,b,l);A=d.bytecode,m=d.calldata,i=d.to,p=d.from,y=d.balance}else{let d=e?null:ht(j,F,D,a,b,l),V=e==="flz"||!e?yt.LibZip.flzCompress(j):null,w=e==="cd"||!e&&V?yt.LibZip.cdCompress(j):null;if(e==="flz"||!e&&V&&(!w||V.length<w.length))m=V,A=Nt(F,a,b);else{let et=w.replace(/^0x/,""),rt="";for(let Z=0;Z<8;Z+=2)rt+=(parseInt(et.substring(Z,Z+2),16)^255).toString(16).padStart(2,"0");m="0x"+rt+et.substring(8),A=Tt(F,a,b)}i=pt,p=D?P(D).padStart(16,"0"):void 0,y="0",!e&&d&&d.bytecode.length+d.calldata.length<A.length+m.length&&(A=d.bytecode,m=d.calldata,i=d.to,p=d.from,y=d.balance)}if(A.length+m.length>=H)return r;let h={code:A,balance:"0x"+y},O={to:i,data:m};return p&&(O.from="0x"+p),{...r,params:[O,k,{...T,[i]:h}]}};
|
|
2
2
|
//! @__PURE__
|
|
3
3
|
//# sourceMappingURL=jit-compressor.cjs.map
|