eth-compress 0.2.1 → 0.3.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/README.md +72 -36
- package/_cjs/index.cjs +1 -2
- package/_cjs/index.cjs.map +4 -4
- package/_cjs/index.node.cjs +1 -2
- package/_cjs/index.node.cjs.map +4 -4
- package/_cjs/jit-compressor.cjs +2 -5
- package/_cjs/jit-compressor.cjs.map +4 -4
- package/_esm/index.js +1 -2
- package/_esm/index.js.map +4 -4
- package/_esm/index.node.js +1 -2
- package/_esm/index.node.js.map +4 -4
- package/_esm/jit-compressor.js +2 -5
- package/_esm/jit-compressor.js.map +4 -4
- package/_types/compiler/constants.d.ts +3 -0
- package/_types/compiler/constants.d.ts.map +1 -0
- package/_types/compiler/index.d.ts +4 -0
- package/_types/compiler/index.d.ts.map +1 -0
- package/_types/compiler/jit.d.ts +8 -0
- package/_types/compiler/jit.d.ts.map +1 -0
- package/_types/compiler/opcodes.d.ts +13 -0
- package/_types/compiler/opcodes.d.ts.map +1 -0
- package/_types/compiler/utils.d.ts +53 -0
- package/_types/compiler/utils.d.ts.map +1 -0
- package/_types/contracts.d.ts +15 -0
- package/_types/contracts.d.ts.map +1 -0
- package/_types/index.d.ts +10 -31
- package/_types/index.d.ts.map +1 -1
- package/_types/jit-compressor.d.ts +6 -20
- package/_types/jit-compressor.d.ts.map +1 -1
- package/index.node.ts +1 -1
- package/index.ts +64 -92
- package/jit-compressor.ts +81 -419
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -7,10 +7,9 @@ It combines [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.
|
|
|
7
7
|
_Plug'n Play with viem & with a simple API_
|
|
8
8
|
|
|
9
9
|
### Scope
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- For reference: Large eth_call's >70kb at a <40% compression ratio result in roughly 30-40% latency reduction. (precise benefits largely depend on a variety of factors, non-the-less the said estimate is a sane projection for the average case)
|
|
10
|
+
- Only **read-only** `eth_call`s.
|
|
11
|
+
- Only compresses above a size threshold, and only when it **strictly** reduces request size (HTTP: >1150 bytes; JIT calldata has a similar gate).
|
|
12
|
+
- HTTP uses standard `Content-Encoding` negotiation (e.g. gzip/deflate). EVM mode routes eligible `eth_call`s through a temporary decompressor contract and forwards to the original `to` via state overrides.
|
|
14
13
|
|
|
15
14
|
### Installation
|
|
16
15
|
|
|
@@ -18,9 +17,9 @@ _Plug'n Play with viem & with a simple API_
|
|
|
18
17
|
npm i eth-compress
|
|
19
18
|
```
|
|
20
19
|
---
|
|
21
|
-
### HTTP request compression
|
|
20
|
+
### HTTP request compression (transport-level)
|
|
22
21
|
|
|
23
|
-
`eth-compress` exposes a `fetch`-compatible function that transparently compresses JSON-RPC request bodies using
|
|
22
|
+
`eth-compress` exposes a `fetch`-compatible function that transparently compresses JSON-RPC request bodies using the CompressionStreams API, when the target RPC endpoint supports it and the payload is large enough to benefit.
|
|
24
23
|
|
|
25
24
|
```ts
|
|
26
25
|
import { compressModule } from 'eth-compress';
|
|
@@ -36,39 +35,64 @@ const response = await compressModule('https://rpc.example.org', {
|
|
|
36
35
|
});
|
|
37
36
|
```
|
|
38
37
|
|
|
39
|
-
###
|
|
38
|
+
### Compression modes
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
| Mode | Behavior |
|
|
41
|
+
|------|----------|
|
|
42
|
+
| `'passive'` | Discover support from response `Accept-Encoding` header |
|
|
43
|
+
| `'proactive'` | Send gzip; discover alternative / lacking support via `Accept-Encoding` response header, error or success |
|
|
44
|
+
| `'gzip'` / `'deflate'` | Use specified encoding directly |
|
|
45
|
+
| `(payload) => ...` | Custom transform; server expected to understand |
|
|
46
46
|
|
|
47
47
|
<br>
|
|
48
48
|
|
|
49
49
|
----
|
|
50
50
|
### viem integration
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
Passive (default):
|
|
54
53
|
```ts
|
|
55
54
|
import { createPublicClient, http } from 'viem';
|
|
56
|
-
import {
|
|
57
|
-
import { compressModule, compressModuleWithJIT } from 'eth-compress';
|
|
55
|
+
import { compressModule } from 'eth-compress';
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const client = createPublicClient({
|
|
58
|
+
chain: base,
|
|
59
|
+
transport: http(rpcUrl, { fetchFn: compressModule }),
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Known gzip support:
|
|
64
|
+
```ts
|
|
65
|
+
import { compressModule } from 'eth-compress';
|
|
66
|
+
|
|
67
|
+
const client = createPublicClient({
|
|
61
68
|
chain: base,
|
|
62
69
|
transport: http(rpcUrl, {
|
|
63
|
-
fetchFn: compressModule,
|
|
70
|
+
fetchFn: (url, init) => compressModule(url, init, 'gzip'),
|
|
64
71
|
}),
|
|
65
72
|
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Proactive:
|
|
76
|
+
```ts
|
|
77
|
+
import { compressModule } from 'eth-compress';
|
|
66
78
|
|
|
67
|
-
|
|
68
|
-
const jitCompressedClient = createPublicClient({
|
|
79
|
+
const client = createPublicClient({
|
|
69
80
|
chain: base,
|
|
70
81
|
transport: http(rpcUrl, {
|
|
71
|
-
fetchFn:
|
|
82
|
+
fetchFn: (url, init) => compressModule(url, init, 'proactive'),
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
JIT calldata compression:
|
|
88
|
+
```ts
|
|
89
|
+
import { compressModule } from 'eth-compress';
|
|
90
|
+
import { compress_call } from 'eth-compress/compressor';
|
|
91
|
+
|
|
92
|
+
const client = createPublicClient({
|
|
93
|
+
chain: base,
|
|
94
|
+
transport: http(rpcUrl, {
|
|
95
|
+
fetchFn: (url, init) => compressModule(url, init, compress_call),
|
|
72
96
|
}),
|
|
73
97
|
});
|
|
74
98
|
```
|
|
@@ -82,10 +106,9 @@ const jitCompressedClient = createPublicClient({
|
|
|
82
106
|
|
|
83
107
|
----
|
|
84
108
|
|
|
85
|
-
### eth_call JIT calldata compression
|
|
109
|
+
### eth_call JIT calldata compression (application-level)
|
|
86
110
|
|
|
87
|
-
|
|
88
|
-
The goal here is the same: **reduce request size -> latency** for large `eth_call` payloads, and secondarily to **stay under eth_call gas/memory limits** by reducing calldata size and gas footprint.
|
|
111
|
+
Implemented purely at the application layer: the client rewrites eligible `eth_call`s and injects a JIT decompressor via `stateOverride`/`stateDiff`.
|
|
89
112
|
|
|
90
113
|
```ts
|
|
91
114
|
import { compress_call } from 'eth-compress/compressor';
|
|
@@ -104,33 +127,46 @@ const payload = {
|
|
|
104
127
|
const compressedPayload = compress_call(payload); // safe to send instead of `payload`
|
|
105
128
|
```
|
|
106
129
|
|
|
107
|
-
`compress_call` can be
|
|
108
|
-
For eligible `eth_call`s it chooses between:
|
|
130
|
+
`compress_call` can be passed directly to `compressModule` as a custom transform. For eligible `eth_call`s it chooses between:
|
|
109
131
|
|
|
110
132
|
- **JIT**: Compiles just-in-time, a one-off decompressor contract that reconstructs calldata to forward the call.
|
|
111
133
|
- **FLZ / CD**: Uses `LibZip.flzCompress` and `LibZip.cdCompress` from `solady` for fast LZ and calldata RLE compression.
|
|
112
134
|
|
|
113
135
|
Selection logic (subject to change, but current behaviour):
|
|
114
136
|
|
|
115
|
-
- **Size gating**:
|
|
116
|
-
- `< 1150 bytes`: no compression.
|
|
137
|
+
- **Size gating (JIT / EVM path)**:
|
|
138
|
+
- `< 1150 bytes (effective payload)`: no EVM-level compression.
|
|
117
139
|
- `≥ 1150 bytes`: compression considered.
|
|
118
|
-
- `
|
|
119
|
-
-
|
|
140
|
+
- `size ≤ ~3000 bytes or > ~8000 bytes`: JIT is preferred.
|
|
141
|
+
- `~3000 ≤ size ≤ ~8000 bytes`: Best of 3
|
|
120
142
|
|
|
121
143
|
- **Algorithm choice**:
|
|
122
144
|
- For mid-sized payloads, FLZ and CD are tried and the smaller output is chosen.
|
|
123
|
-
- For larger payloads, JIT is used directly,
|
|
145
|
+
- For larger payloads, JIT is used directly, prioritizing gas efficiency.
|
|
124
146
|
- The thresholds are chosen with consideration for request header overhead & latency,
|
|
125
147
|
aiming to keep the total request size within the [Ethernet MTU](https://en.wikipedia.org/wiki/Maximum_transmission_unit).
|
|
126
148
|
|
|
149
|
+
### Important considerations
|
|
150
|
+
|
|
151
|
+
The JIT calldata compressor is **experimental** and intended for read-only `eth_call`s that fetch auxiliary/bulk dApp data (dashboards, analytics, non-critical views). Avoid using it for critical user flows. Ideally you use two viem clients if you intend to use that feature: one with JIT enabled for auxiliary reads, and one without for critical data.
|
|
152
|
+
|
|
153
|
+
### 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 |
|
|
127
159
|
|
|
128
|
-
|
|
129
|
-
- **JIT calldata compiler (`compress_call` JIT mode)**: Views the calldata as a zero‑initialized memory image and synthesises bytecode that rebuilds it word-by-word in-place. 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, under a rough opcode-count cost model. 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. 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. Achieves higher compression ratios compared to both FastLZ & Run-Length-Encoding (-10-15%) for smaller calldata <3kb, and roughly on par above 8kb (except in cases with deeply nested calls and types, minimally worse), at a fraction of the gas footprint (<5%).
|
|
160
|
+
<sub>Excludes txns not compressible <70% of original size.</sub>
|
|
130
161
|
|
|
131
|
-
|
|
162
|
+
### Compression flavours
|
|
163
|
+
- **JIT calldata compiler (`compress_call` JIT mode)**: Views the calldata as a zero‑initialized memory image and synthesises bytecode that rebuilds it word-by-word in-place.
|
|
132
164
|
|
|
133
|
-
|
|
165
|
+
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.
|
|
134
170
|
|
|
135
171
|
Both the FastLZ and calldata-RLE forwarders are minimally adopted from Solady's [`LibZip.sol`](https://github.com/Vectorized/solady/blob/main/src/utils/LibZip.sol) and inlined as raw bytecode. To avoid Solidity's wrapper overhead the code is compiled from pure yul.
|
|
136
172
|
|
package/_cjs/index.cjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
//! @__PURE__
|
|
1
|
+
var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var o in e)u(n,o,{get:e[o],enumerable:!0})},E=(n,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of w(e))!R.call(n,t)&&t!==o&&u(n,t,{get:()=>e[t],enumerable:!(s=b(e,t))||s.enumerable});return n};var q=n=>E(u({},"__esModule",{value:!0}),n);var v={};C(v,{MIN_BODY_SIZE:()=>_,compressModule:()=>M});module.exports=q(v);var _=1150,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),m=typeof CompressionStream<"u",g=o==="gzip"||o==="deflate",i=m?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});
|
|
3
2
|
//# sourceMappingURL=index.cjs.map
|
package/_cjs/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/
|
|
4
|
-
"sourcesContent": ["import { LibZip } from 'solady';\n\nconst MAX_160_BIT = (1n << 128n) - 1n;\n\nconst _normHex = (hex: string): string => hex.replace(/^0x/, '').toLowerCase();\n\nconst _hexToUint8Array = (hex: string): Uint8Array => {\n const normalized = _normHex(hex);\n const len = normalized.length;\n const bytes = new Uint8Array(len / 2);\n for (let i = 0; i < len; i += 2) {\n bytes[i / 2] = Number.parseInt(normalized.slice(i, i + 2), 16);\n }\n return bytes;\n};\n\nconst _uint8ArrayToHex = (bytes: Uint8Array): string => {\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += bytes[i].toString(16).padStart(2, '0');\n }\n return hex;\n};\n\n/**\n * Generates FastLZ (LZ77) decompressor bytecode. The generated code decompresses incoming calldata and forwards it to the target address.\n * @param address - Target contract address\n * @see {@link https://github.com/Vectorized/solady/blob/main/src/utils/LibZip.sol}\n * @pure\n */\n//! @__PURE__\nexport const flzFwdBytecode = (address: string): string =>\n `0x365f73${_normHex(address)}815b838110602f575f80848134865af1503d5f803e3d5ff35b803590815f1a8060051c908115609857600190600783149285831a6007018118840218600201948383011a90601f1660081b0101808603906020811860208211021890815f5b80830151818a015201858110609257505050600201019201916018565b82906075565b6001929350829150019101925f5b82811060b3575001916018565b85851060c1575b60010160a6565b936001818192355f1a878501530194905060ba56`;\n\n/**\n * Generates RLE (run-length encoded) decompressor bytecode. The generated code decompresses incoming calldata and forwards it to the target address.\n * @param address - Target contract address\n * @see {@link https://github.com/Vectorized/solady/blob/main/src/utils/LibZip.sol}\n * @pure\n */\n//! @__PURE__\nexport const rleFwdBytecode = (address: string): string =>\n `0x5f5f5b368110602d575f8083813473${_normHex(address)}5af1503d5f803e3d5ff35b600180820192909160031981019035185f1a8015604c57815301906002565b505f19815282820192607f9060031981019035185f1a818111156072575b160101906002565b838101368437606a56`;\n\n/**\n * JIT Compiles decompressor bytecode\n * @param calldata - Calldata to compress\n * @pure\n */\n//! @__PURE__\nexport const jitBytecode = function (calldata: string): string {\n return _jitDecompressor('0x' + _normHex(calldata));\n};\n\nconst _jitDecompressor = function (calldata: string): string {\n const hex = _normHex(calldata);\n const originalBuf = _hexToUint8Array(hex);\n\n // Right\u2011align the 4\u2011byte selector in the first 32\u2011byte slot (offset 28),\n // so that everything after the selector is reconstructed on mostly\n // word\u2011aligned boundaries. This keeps the ABI words (and therefore most\n // calldata reconstruction) 32\u2011byte aligned in memory.\n // That way we avoid encoding offsets for writes (most of the time),\n const padding = 28;\n const buf = new Uint8Array(padding + originalBuf.length);\n buf.set(originalBuf, padding);\n\n const n = buf.length;\n\n let ops: number[] = [];\n let data: (number[] | null)[] = [];\n let stack: bigint[] = [];\n let trackedMemSize = 0;\n let mem = new Map<number, bigint>();\n const getStackIdx = (val: bigint): number => {\n const idx = stack.lastIndexOf(val);\n return idx === -1 ? -1 : stack.length - 1 - idx;\n };\n\n const opFreq = new Map<number, number>();\n const dataFreq = new Map<number[] | null, number>();\n const stackFreq = new Map<bigint, number>();\n const wordCache = new Map<string, number>();\n const wordCacheCost = new Map<string, number>();\n const roundUp32 = (x: number) => (x + 31) & ~31;\n\n let pushCounter = 0;\n const stackCnt = new Map<bigint, number>();\n\n const pop2 = (): [bigint, bigint] => [stack.pop()!, stack.pop()!];\n const MASK32 = (1n << 256n) - 1n;\n\n const ctr = <K>(m: Map<K, number>, k: K, delta: number) => m.set(k, (m.get(k) || 0) + delta);\n const inc = <K>(m: Map<K, number>, k: K) => ctr(m, k, 1);\n const dec = <K>(m: Map<K, number>, k: K) => ctr(m, k, -1);\n const pushOp = (op: number) => {\n ops.push(op);\n inc(opFreq, op);\n };\n const pushD = (d: number[] | null) => {\n data.push(d || null);\n inc(dataFreq, d || null);\n };\n const pushS = (v: bigint, freq: number = 1) => {\n stack.push(v);\n ctr(stackFreq, v, freq);\n ++pushCounter;\n stackCnt.set(v, pushCounter);\n };\n\n const trackMem = (offset: number, size: number) => {\n trackedMemSize = roundUp32(offset + size);\n };\n\n const addOp = (op: number, imm?: number[]) => {\n if (op === 0x36) {\n pushS(32n, 0);\n } else if (op === 0x59) {\n pushS(BigInt(trackedMemSize), 0);\n } else if (op === 0x1b) {\n let [shift, val] = pop2();\n if (ops[ops.length - 1] == 144) {\n ops.pop();\n data.pop();\n [shift, val] = [val, shift];\n }\n pushS((val << BigInt(shift)) & MASK32);\n } else if (op === 0x17) {\n // OR\n const [a, b] = pop2();\n if (ops[ops.length - 1] == 144) {\n ops.pop();\n data.pop();\n }\n pushS((a | b) & MASK32);\n } else if ((op >= 0x60 && op <= 0x7f) || op === 0x5f) {\n // PUSH\n let v = 0n;\n for (const b of imm || []) v = (v << 8n) | BigInt(b);\n if (v == 224n) {\n // Special\u2011case the literal 0xe0 (224):\n // the decompressor is always deployed at 0x...00e0, so the final\n // byte of ADDRESS is exactly 0xe0. Since we must send our own\n // address with the eth_call anyway, we can synthesize this value\n // with a single opcode instead of encoding a literal, effectively\n // giving us one more hot constant slot on the stack.\n pushS(v);\n pushOp(0x30); // ADDRESS\n pushD(null);\n return;\n }\n const idx = getStackIdx(v);\n if (idx !== -1 && op != 0x5f) {\n const last = stackFreq.get(v) == 0;\n if (idx == 0 && last) {\n dec(stackFreq, v);\n return;\n }\n if (idx == 1 && last) {\n pushOp(144);\n const [a, b] = pop2();\n stack.push(b);\n stack.push(a);\n pushD(null);\n dec(stackFreq, v);\n return;\n }\n pushS(v, -1);\n pushOp(128 + idx);\n pushD(null);\n return;\n }\n pushS(v);\n } else if (op === 0x51) {\n // MLOAD\n const k = Number(stack.pop()!);\n pushS(mem.has(k) ? mem.get(k)! : 0n);\n } else if (op === 0x52) {\n // MSTORE\n const [offset, value] = pop2();\n const k = Number(offset);\n mem.set(k, value & MASK32);\n trackMem(k, 32);\n } else if (op === 0x53) {\n // MSTORE8\n const [offset, _] = pop2();\n trackMem(Number(offset), 1);\n } else if (op === 0xf3) {\n // RETURN\n pop2();\n }\n pushOp(op);\n pushD(imm || null);\n };\n const isInStack = (w) => stack.includes(w) || w == 0xe0 || w == 32n;\n const op = (opcode: number) => addOp(opcode);\n const pushN = (value: number | bigint) => {\n if (value > 0 && value === trackedMemSize) return addOp(0x59);\n if (value == 32n) return addOp(0x36);\n if (!value) return addOp(0x5f, undefined); // PUSH0\n let v = BigInt(value);\n let bytes: number[] = [];\n while (v) {\n bytes.unshift(Number(v & 0xffn));\n v >>= 8n;\n }\n return addOp(0x5f + bytes.length, bytes);\n };\n const pushB = (buf: Uint8Array) => addOp(0x5f + buf.length, Array.from(buf));\n const cntWords = (hex: string, wordHex: string) =>\n (hex.match(new RegExp(wordHex, 'g')) || []).length;\n\n // Rough cost model\n const estShlCost = (seg: Array<{ s: number; e: number }>) => {\n let cost = 0;\n let first = true;\n for (const { s, e } of seg) {\n cost += 1 + e - s + 1; // PUSH segLen bytes\n if (31 - e > 0) cost += 1 /* PUSH1 */ + 1 /* shift byte */ + 1 /* SHL */;\n if (!first) cost += 1; // OR\n first = false;\n }\n return cost;\n };\n\n type PlanStep =\n | { t: 'num'; v: number | bigint }\n | { t: 'bytes'; b: Uint8Array }\n | { t: 'op'; o: number };\n\n const plan: PlanStep[] = [];\n const emitPushN = (v: number | bigint) => (plan.push({ t: 'num', v }), pushN(v));\n const emitPushB = (b: Uint8Array) => (plan.push({ t: 'bytes', b }), pushB(b));\n const emitOp = (o: number) => (plan.push({ t: 'op', o }), op(o));\n pushN(1n);\n // First pass: decide how to build each 32-byte word without emitting bytecode\n for (let base = 0; base < n; base += 32) {\n const word = new Uint8Array(32);\n word.set(buf.slice(base, Math.min(base + 32, n)), 0);\n\n const seg: Array<{ s: number; e: number }> = [];\n for (let i = 0; i < 32; ) {\n while (i < 32 && word[i] === 0) ++i;\n if (i >= 32) break;\n const s = i;\n while (i < 32 && word[i] !== 0) ++i;\n seg.push({ s, e: i - 1 });\n }\n\n if (!seg.length) continue;\n\n // Decide whether to build this word via SHL/OR or as a single literal word\n const literal = word.slice(seg[0].s);\n const literalCost = 1 + literal.length;\n let literalVal = 0n;\n for (const b of literal) literalVal = (literalVal << 8n) | BigInt(b);\n const baseBytes = Math.ceil(Math.log2(base + 1) / 8);\n const wordHex = _uint8ArrayToHex(word);\n if (literalCost > 8) {\n if (wordCache.has(wordHex)) {\n if (literalCost > wordCacheCost.get(wordHex)! + baseBytes) {\n emitPushN(wordCache.get(wordHex)!);\n emitOp(0x51);\n emitPushN(base);\n emitOp(0x52); // MSTORE\n continue;\n }\n } else if (wordCacheCost.get(wordHex) != -1) {\n const reuseCost = baseBytes + 3;\n const freq = cntWords(hex, wordHex);\n wordCacheCost.set(wordHex, freq * 32 > freq * reuseCost ? reuseCost : -1);\n wordCache.set(wordHex, base);\n }\n }\n\n // Convert literal bytes to bigint for stack comparison\n\n const byte8s = seg.every(({ s, e }) => s === e);\n if (isInStack(literal)) {\n emitPushB(literal);\n } else if (byte8s) {\n for (const { s } of seg) {\n emitPushN(word[s]);\n emitPushN(base + s);\n emitOp(0x53); // MSTORE8\n }\n continue;\n } else if (literalCost <= estShlCost(seg)) {\n emitPushB(literal);\n } else {\n let first = true;\n for (const { s, e } of seg) {\n const suffix0s = 31 - e;\n emitPushB(word.slice(s, e + 1));\n if (suffix0s > 0) {\n emitPushN(suffix0s * 8);\n emitOp(0x1b); // SHL\n }\n if (!first) emitOp(0x17); // OR\n first = false;\n }\n }\n emitPushN(base);\n emitOp(0x52); // MSTORE\n }\n\n ops = [];\n data = [];\n stack = [];\n trackedMemSize = 0;\n mem = new Map();\n // Pre 2nd pass. Push most frequent literals into stack.\n Array.from(stackFreq.entries())\n .filter(([val, freq]) => freq > 1 && val > 1n && val !== 32n && val !== 224n)\n .sort((a, b) => stackCnt.get(b[0])! - stackCnt.get(a[0])!)\n .filter(([val, _]) => {\n return typeof val === 'number' ? BigInt(val) : val <= MAX_160_BIT;\n })\n .slice(0, 13)\n .forEach(([val, _]) => {\n pushN(val);\n });\n pushN(1n);\n // Second pass: emit ops and track mem/stack\n for (const step of plan) {\n if (step.t === 'num') pushN(step.v);\n else if (step.t === 'bytes') pushB(step.b);\n else if (step.t === 'op') op(step.o);\n }\n\n // CALL stack layout (top to bottom): gas, address, value, argsOffset, argsSize, retOffset, retSize\n //\n // Opcodes breakdown:\n // - 0x5f5f: PUSH0 PUSH0 (retSize=0, retOffset=0)\n // - pushN(originalBuf.length): argsSize = actual data length\n // - pushN(padding): argsOffset (skip leading alignment bytes)\n // - 0x34: CALLVALUE (value)\n // - 0x5f35: PUSH0 CALLDATALOAD (address from calldata[0])\n // - 0x5a: GAS (remaining gas)\n // - 0xf1: CALL\n //\n // RETURNDATACOPY(destOffset=0, offset=0, length=RETURNDATASIZE):\n // - 0x3d5f5f3e: RETURNDATASIZE PUSH0 PUSH0 RETURNDATACOPY\n //\n // RETURN(offset=0, size=RETURNDATASIZE):\n // - 0x3d5ff3: RETURNDATASIZE PUSH0 RETURN\n\n op(0x5f); // PUSH0 (retSize)\n op(0x5f); // PUSH0 (retOffset)\n pushN(originalBuf.length); // argsSize = actual data length\n pushN(padding); // argsOffset = padding\n\n const out: number[] = [];\n for (let i = 0; i < ops.length; ++i) {\n out.push(ops[i]);\n if (ops[i] >= 0x60 && ops[i] <= 0x7f && data[i]) out.push(...data[i]!);\n }\n\n // - CALLVALUE, load target address from calldata[0], GAS, CALL\n // - RETURNDATACOPY(0, 0, RETURNDATASIZE)\n // - RETURN(0, RETURNDATASIZE)\n return '0x' + _uint8ArrayToHex(new Uint8Array(out)) + '345f355af13d5f5f3e3d5ff3';\n};\n\nconst MIN_SIZE_FOR_COMPRESSION = 1150;\nconst DECOMPRESSOR_ADDRESS = '0x00000000000000000000000000000000000000e0';\n\nconst _jit = 'jit';\nconst _flz = 'flz';\nconst _cd = 'cd';\n\n/**\n * Compresses eth_call payload using JIT, FastLZ (FLZ), or calldata RLE (CD) compression.\n * Auto-selects best algorithm if not specified. Only compresses if >800 bytes and beneficial.\n * @param payload - eth_call RPC payload\n * @param alg - 'jit' | 'flz' | 'cd' | undefined (auto)\n * @returns (un)compressed eth_call payload\n * @pure\n */\n//! @__PURE__\nexport const compress_call = function (payload: any, alg?: string): any {\n const rpcMethod = payload.params?.[0]?.method || payload.method;\n if (rpcMethod && rpcMethod !== 'eth_call') return payload;\n\n // Extract data and target address from params[0] if available, otherwise top-level\n const txObj = payload.params?.[0] || payload;\n const blockParam = payload.params?.[1] || 'latest';\n const existingStateOverride = payload.params?.[2] || {};\n\n // If there are any existing state overrides for the decompressor address, do not compress\n const hex = _normHex(txObj.data || '0x');\n const originalSize = (txObj.data || '0x').length;\n if (originalSize < MIN_SIZE_FOR_COMPRESSION || (existingStateOverride[DECOMPRESSOR_ADDRESS])) return payload;\n\n const targetAddress = txObj.to || '';\n const data = '0x' + hex;\n\n const autoSelect = !alg && originalSize < 1150;\n const flz = alg === _flz || autoSelect ? LibZip.flzCompress(data) : null;\n const cd = alg === _cd || autoSelect ? LibZip.cdCompress(data) : null;\n let selectedMethod = alg;\n if (!selectedMethod) {\n selectedMethod =\n originalSize >= 1150 && (originalSize < 3000 || originalSize >= 8000)\n ? _jit\n : originalSize >= 3000 && originalSize < 8000\n ? flz!.length < cd!.length\n ? _flz\n : _cd\n : _cd;\n }\n\n let bytecode: string;\n let calldata: string;\n\n if (selectedMethod === _jit) {\n bytecode = _jitDecompressor(data);\n calldata = '0x' + _normHex(targetAddress).padStart(64, '0');\n } else {\n const isFlz = selectedMethod === _flz;\n calldata = isFlz ? flz! : cd!;\n bytecode = isFlz ? flzFwdBytecode(targetAddress) : rleFwdBytecode(targetAddress);\n }\n\n const compressedSize = bytecode.length + calldata.length;\n if (compressedSize >= originalSize) return payload;\n\n return {\n ...payload,\n params: [\n {\n ...txObj,\n to: DECOMPRESSOR_ADDRESS,\n data: calldata,\n },\n blockParam,\n {\n ...existingStateOverride,\n [DECOMPRESSOR_ADDRESS]: { code: bytecode },\n },\n ],\n };\n};\n", "const _sup_enc = new Map<string, string[] | -1>();\nconst _enc = ['deflate-raw', 'deflate', 'gzip'];\nlet supported: string | -1 | null = typeof CompressionStream === 'undefined' ? -1 : null;\n\nexport type PayloadTransform = (payload: unknown) => unknown;\n\n/**\n * Fetch-compatible function that applies HTTP compression (gzip/deflate) to requests.\n * Optionally transforms request payloads before sending.\n *\n * @param input - The resource URL, Request object, or URL string\n * @param init - Optional request initialization options\n * @param transformPayload - Optional function to transform the request payload\n * @returns A Promise that resolves to the Response\n */\n//! @__PURE__\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n): Promise<Response>;\n\n//! @__PURE__\nexport async function compressModule(\n input: string | URL | Request,\n init: RequestInit | undefined,\n transformPayload?: PayloadTransform,\n): Promise<Response>;\n\n//! @__PURE__\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n transformPayload?: PayloadTransform,\n): Promise<Response> {\n const url =\n typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url;\n\n const cached = _sup_enc.get(url);\n supported = supported === -1 ? -1 : cached === -1 ? -1 : (cached?.[0] ?? null);\n\n // Only apply the optional payload transform\n // when native HTTP compression is not available for this URL.\n if (transformPayload && init?.body && typeof init.body === 'string') {\n if (supported === -1 || supported === null) {\n try {\n const parsed = JSON.parse(init.body as string);\n const next = transformPayload(parsed);\n if (next !== undefined) {\n init = {\n ...init,\n body: JSON.stringify(next),\n };\n }\n } catch {\n // Non-JSON bodies are left untouched.\n }\n }\n }\n\n if (supported && supported !== -1 && init?.body) {\n const compressed = await new Response(\n new Blob([init.body as string])\n .stream()\n .pipeThrough(new CompressionStream(supported as CompressionFormat)),\n ).blob();\n init = {\n ...init,\n body: compressed,\n headers: { ...(init && init.headers), 'Content-Encoding': supported },\n };\n }\n const response = await fetch(url, init);\n\n if (supported === null) {\n const encodings = response.headers\n .get('Accept-Encoding')\n ?.split(',')\n .filter((e) => _enc.includes(e));\n _sup_enc.set(url, encodings?.length ? encodings : -1);\n }\n\n return response;\n}\n\n/**\n * Combines HTTP compression with EVM JIT compression.\n * Just pass this as `fetchFn` to viem's http transport.\n *\n * @param input - The resource URL or Request object\n * @param init - Optional request initialization options\n * @returns A Promise that resolves to the Response\n *\n * @example\n * ```ts\n * const client = createPublicClient({\n * transport: http(rpcUrl, { fetchFn: compressModuleWithJIT })\n * })\n * ```\n *\n * If the target RPC endpoint and runtime support native HTTP compression,\n * this helper prefers that path and will not apply JIT calldata compression;\n * the JIT-based transform is used as a legacy/fallback path when HTTP\n * content-encoding is unavailable.\n * @pure\n */\n//! @__PURE__\nexport const compressModuleWithJIT = (\n input: RequestInfo | URL,\n init?: RequestInit,\n): Promise<Response> => {\n return import('./jit-compressor').then(({ compress_call }) =>\n compressModule(input, init, compress_call),\n );\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
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 hasCS = typeof CompressionStream !== 'undefined';\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,IAAI,IACbC,EAAO,CAAC,OAAQ,SAAS,EAe/B,eAAsBH,EACpBI,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,EAAQ,OAAO,kBAAsB,IACrCC,EAAQR,IAAS,QAAUA,IAAS,UACpCS,EAAYF,EAEdC,EACGR,EACDA,IAAS,YACPM,IAAW,GACT,KACCA,GAAU,OACb,OAAOA,GAAW,SAChBA,EACA,KATN,KAWEI,EAAiB,CAAC,CAACD,GAAY,CAAC,CAACN,GAAWA,EAAQ,QAAU,KAC9DQ,EAAoB,CAAE,GAAGZ,EAAM,SAAU,MAA0B,EACnEa,EAAU,IAAI,QAAQD,EAAK,OAAO,EACpCD,IACFC,EAAK,KAAO,MAAM,IAAI,SACpB,IAAI,KAAK,CAACR,CAAQ,CAAC,EAChB,OAAO,EACP,YAAY,IAAI,kBAAkBM,CAA6B,CAAC,CACrE,EAAE,KAAK,EACPG,EAAQ,IAAI,mBAAoBH,CAAQ,GAE1CE,EAAK,QAAUC,EAEf,IAAMC,EAAW,MAAM,MAAMZ,GAAOC,EAAKS,CAAI,EAG7C,GAAI,CAACH,GAASF,IAAW,OAAW,CAElC,IAAMQ,EADSD,EAAS,QAAQ,IAAI,iBAAiB,GAG/C,MAAM,GAAG,EACV,IAAKE,GAAMA,EAAE,KAAK,CAAC,EACnB,KAAMA,GAA8BlB,EAAK,SAASkB,CAAsB,CAAC,GAAK,GACnFnB,EAAO,IACLM,EACAF,IAAS,aAAeU,GAAkBG,EAAS,GAAKJ,EAA0BK,CACpF,CACF,CAEA,OAAOD,CACT",
|
|
6
|
+
"names": ["index_exports", "__export", "MIN_BODY_SIZE", "compressModule", "__toCommonJS", "_cache", "_enc", "input", "init", "mode", "req", "url", "bodyStr", "body", "next", "cached", "hasCS", "known", "encoding", "shouldCompress", "opts", "headers", "response", "discovered", "e"]
|
|
7
7
|
}
|
package/_cjs/index.node.cjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
//! @__PURE__
|
|
1
|
+
var R=Object.create;var d=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var I=(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 q(s))!E.call(t,o)&&o!==e&&d(t,o,{get:()=>s[o],enumerable:!(n=z(s,o))||n.enumerable});return t};var v=(t,s,e)=>(e=t!=null?R(D(t)):{},b(s||!t||!t.__esModule?d(e,"default",{value:t,enumerable:!0}):e,t)),T=t=>b(d({},"__esModule",{value:!0}),t);var M={};I(M,{MIN_BODY_SIZE:()=>k,compressModule:()=>x});module.exports=T(M);var r=v(require("node:zlib"),1);var k=1150,S=new Map,_=["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),C=typeof CompressionStream<"u",y=e==="gzip"||e==="deflate",l=C?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=>_.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});
|
|
3
2
|
//# sourceMappingURL=index.node.cjs.map
|
package/_cjs/index.node.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/
|
|
4
|
-
"sourcesContent": ["import { LibZip } from 'solady';\n\nconst MAX_160_BIT = (1n << 128n) - 1n;\n\nconst _normHex = (hex: string): string => hex.replace(/^0x/, '').toLowerCase();\n\nconst _hexToUint8Array = (hex: string): Uint8Array => {\n const normalized = _normHex(hex);\n const len = normalized.length;\n const bytes = new Uint8Array(len / 2);\n for (let i = 0; i < len; i += 2) {\n bytes[i / 2] = Number.parseInt(normalized.slice(i, i + 2), 16);\n }\n return bytes;\n};\n\nconst _uint8ArrayToHex = (bytes: Uint8Array): string => {\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += bytes[i].toString(16).padStart(2, '0');\n }\n return hex;\n};\n\n/**\n * Generates FastLZ (LZ77) decompressor bytecode. The generated code decompresses incoming calldata and forwards it to the target address.\n * @param address - Target contract address\n * @see {@link https://github.com/Vectorized/solady/blob/main/src/utils/LibZip.sol}\n * @pure\n */\n//! @__PURE__\nexport const flzFwdBytecode = (address: string): string =>\n `0x365f73${_normHex(address)}815b838110602f575f80848134865af1503d5f803e3d5ff35b803590815f1a8060051c908115609857600190600783149285831a6007018118840218600201948383011a90601f1660081b0101808603906020811860208211021890815f5b80830151818a015201858110609257505050600201019201916018565b82906075565b6001929350829150019101925f5b82811060b3575001916018565b85851060c1575b60010160a6565b936001818192355f1a878501530194905060ba56`;\n\n/**\n * Generates RLE (run-length encoded) decompressor bytecode. The generated code decompresses incoming calldata and forwards it to the target address.\n * @param address - Target contract address\n * @see {@link https://github.com/Vectorized/solady/blob/main/src/utils/LibZip.sol}\n * @pure\n */\n//! @__PURE__\nexport const rleFwdBytecode = (address: string): string =>\n `0x5f5f5b368110602d575f8083813473${_normHex(address)}5af1503d5f803e3d5ff35b600180820192909160031981019035185f1a8015604c57815301906002565b505f19815282820192607f9060031981019035185f1a818111156072575b160101906002565b838101368437606a56`;\n\n/**\n * JIT Compiles decompressor bytecode\n * @param calldata - Calldata to compress\n * @pure\n */\n//! @__PURE__\nexport const jitBytecode = function (calldata: string): string {\n return _jitDecompressor('0x' + _normHex(calldata));\n};\n\nconst _jitDecompressor = function (calldata: string): string {\n const hex = _normHex(calldata);\n const originalBuf = _hexToUint8Array(hex);\n\n // Right\u2011align the 4\u2011byte selector in the first 32\u2011byte slot (offset 28),\n // so that everything after the selector is reconstructed on mostly\n // word\u2011aligned boundaries. This keeps the ABI words (and therefore most\n // calldata reconstruction) 32\u2011byte aligned in memory.\n // That way we avoid encoding offsets for writes (most of the time),\n const padding = 28;\n const buf = new Uint8Array(padding + originalBuf.length);\n buf.set(originalBuf, padding);\n\n const n = buf.length;\n\n let ops: number[] = [];\n let data: (number[] | null)[] = [];\n let stack: bigint[] = [];\n let trackedMemSize = 0;\n let mem = new Map<number, bigint>();\n const getStackIdx = (val: bigint): number => {\n const idx = stack.lastIndexOf(val);\n return idx === -1 ? -1 : stack.length - 1 - idx;\n };\n\n const opFreq = new Map<number, number>();\n const dataFreq = new Map<number[] | null, number>();\n const stackFreq = new Map<bigint, number>();\n const wordCache = new Map<string, number>();\n const wordCacheCost = new Map<string, number>();\n const roundUp32 = (x: number) => (x + 31) & ~31;\n\n let pushCounter = 0;\n const stackCnt = new Map<bigint, number>();\n\n const pop2 = (): [bigint, bigint] => [stack.pop()!, stack.pop()!];\n const MASK32 = (1n << 256n) - 1n;\n\n const ctr = <K>(m: Map<K, number>, k: K, delta: number) => m.set(k, (m.get(k) || 0) + delta);\n const inc = <K>(m: Map<K, number>, k: K) => ctr(m, k, 1);\n const dec = <K>(m: Map<K, number>, k: K) => ctr(m, k, -1);\n const pushOp = (op: number) => {\n ops.push(op);\n inc(opFreq, op);\n };\n const pushD = (d: number[] | null) => {\n data.push(d || null);\n inc(dataFreq, d || null);\n };\n const pushS = (v: bigint, freq: number = 1) => {\n stack.push(v);\n ctr(stackFreq, v, freq);\n ++pushCounter;\n stackCnt.set(v, pushCounter);\n };\n\n const trackMem = (offset: number, size: number) => {\n trackedMemSize = roundUp32(offset + size);\n };\n\n const addOp = (op: number, imm?: number[]) => {\n if (op === 0x36) {\n pushS(32n, 0);\n } else if (op === 0x59) {\n pushS(BigInt(trackedMemSize), 0);\n } else if (op === 0x1b) {\n let [shift, val] = pop2();\n if (ops[ops.length - 1] == 144) {\n ops.pop();\n data.pop();\n [shift, val] = [val, shift];\n }\n pushS((val << BigInt(shift)) & MASK32);\n } else if (op === 0x17) {\n // OR\n const [a, b] = pop2();\n if (ops[ops.length - 1] == 144) {\n ops.pop();\n data.pop();\n }\n pushS((a | b) & MASK32);\n } else if ((op >= 0x60 && op <= 0x7f) || op === 0x5f) {\n // PUSH\n let v = 0n;\n for (const b of imm || []) v = (v << 8n) | BigInt(b);\n if (v == 224n) {\n // Special\u2011case the literal 0xe0 (224):\n // the decompressor is always deployed at 0x...00e0, so the final\n // byte of ADDRESS is exactly 0xe0. Since we must send our own\n // address with the eth_call anyway, we can synthesize this value\n // with a single opcode instead of encoding a literal, effectively\n // giving us one more hot constant slot on the stack.\n pushS(v);\n pushOp(0x30); // ADDRESS\n pushD(null);\n return;\n }\n const idx = getStackIdx(v);\n if (idx !== -1 && op != 0x5f) {\n const last = stackFreq.get(v) == 0;\n if (idx == 0 && last) {\n dec(stackFreq, v);\n return;\n }\n if (idx == 1 && last) {\n pushOp(144);\n const [a, b] = pop2();\n stack.push(b);\n stack.push(a);\n pushD(null);\n dec(stackFreq, v);\n return;\n }\n pushS(v, -1);\n pushOp(128 + idx);\n pushD(null);\n return;\n }\n pushS(v);\n } else if (op === 0x51) {\n // MLOAD\n const k = Number(stack.pop()!);\n pushS(mem.has(k) ? mem.get(k)! : 0n);\n } else if (op === 0x52) {\n // MSTORE\n const [offset, value] = pop2();\n const k = Number(offset);\n mem.set(k, value & MASK32);\n trackMem(k, 32);\n } else if (op === 0x53) {\n // MSTORE8\n const [offset, _] = pop2();\n trackMem(Number(offset), 1);\n } else if (op === 0xf3) {\n // RETURN\n pop2();\n }\n pushOp(op);\n pushD(imm || null);\n };\n const isInStack = (w) => stack.includes(w) || w == 0xe0 || w == 32n;\n const op = (opcode: number) => addOp(opcode);\n const pushN = (value: number | bigint) => {\n if (value > 0 && value === trackedMemSize) return addOp(0x59);\n if (value == 32n) return addOp(0x36);\n if (!value) return addOp(0x5f, undefined); // PUSH0\n let v = BigInt(value);\n let bytes: number[] = [];\n while (v) {\n bytes.unshift(Number(v & 0xffn));\n v >>= 8n;\n }\n return addOp(0x5f + bytes.length, bytes);\n };\n const pushB = (buf: Uint8Array) => addOp(0x5f + buf.length, Array.from(buf));\n const cntWords = (hex: string, wordHex: string) =>\n (hex.match(new RegExp(wordHex, 'g')) || []).length;\n\n // Rough cost model\n const estShlCost = (seg: Array<{ s: number; e: number }>) => {\n let cost = 0;\n let first = true;\n for (const { s, e } of seg) {\n cost += 1 + e - s + 1; // PUSH segLen bytes\n if (31 - e > 0) cost += 1 /* PUSH1 */ + 1 /* shift byte */ + 1 /* SHL */;\n if (!first) cost += 1; // OR\n first = false;\n }\n return cost;\n };\n\n type PlanStep =\n | { t: 'num'; v: number | bigint }\n | { t: 'bytes'; b: Uint8Array }\n | { t: 'op'; o: number };\n\n const plan: PlanStep[] = [];\n const emitPushN = (v: number | bigint) => (plan.push({ t: 'num', v }), pushN(v));\n const emitPushB = (b: Uint8Array) => (plan.push({ t: 'bytes', b }), pushB(b));\n const emitOp = (o: number) => (plan.push({ t: 'op', o }), op(o));\n pushN(1n);\n // First pass: decide how to build each 32-byte word without emitting bytecode\n for (let base = 0; base < n; base += 32) {\n const word = new Uint8Array(32);\n word.set(buf.slice(base, Math.min(base + 32, n)), 0);\n\n const seg: Array<{ s: number; e: number }> = [];\n for (let i = 0; i < 32; ) {\n while (i < 32 && word[i] === 0) ++i;\n if (i >= 32) break;\n const s = i;\n while (i < 32 && word[i] !== 0) ++i;\n seg.push({ s, e: i - 1 });\n }\n\n if (!seg.length) continue;\n\n // Decide whether to build this word via SHL/OR or as a single literal word\n const literal = word.slice(seg[0].s);\n const literalCost = 1 + literal.length;\n let literalVal = 0n;\n for (const b of literal) literalVal = (literalVal << 8n) | BigInt(b);\n const baseBytes = Math.ceil(Math.log2(base + 1) / 8);\n const wordHex = _uint8ArrayToHex(word);\n if (literalCost > 8) {\n if (wordCache.has(wordHex)) {\n if (literalCost > wordCacheCost.get(wordHex)! + baseBytes) {\n emitPushN(wordCache.get(wordHex)!);\n emitOp(0x51);\n emitPushN(base);\n emitOp(0x52); // MSTORE\n continue;\n }\n } else if (wordCacheCost.get(wordHex) != -1) {\n const reuseCost = baseBytes + 3;\n const freq = cntWords(hex, wordHex);\n wordCacheCost.set(wordHex, freq * 32 > freq * reuseCost ? reuseCost : -1);\n wordCache.set(wordHex, base);\n }\n }\n\n // Convert literal bytes to bigint for stack comparison\n\n const byte8s = seg.every(({ s, e }) => s === e);\n if (isInStack(literal)) {\n emitPushB(literal);\n } else if (byte8s) {\n for (const { s } of seg) {\n emitPushN(word[s]);\n emitPushN(base + s);\n emitOp(0x53); // MSTORE8\n }\n continue;\n } else if (literalCost <= estShlCost(seg)) {\n emitPushB(literal);\n } else {\n let first = true;\n for (const { s, e } of seg) {\n const suffix0s = 31 - e;\n emitPushB(word.slice(s, e + 1));\n if (suffix0s > 0) {\n emitPushN(suffix0s * 8);\n emitOp(0x1b); // SHL\n }\n if (!first) emitOp(0x17); // OR\n first = false;\n }\n }\n emitPushN(base);\n emitOp(0x52); // MSTORE\n }\n\n ops = [];\n data = [];\n stack = [];\n trackedMemSize = 0;\n mem = new Map();\n // Pre 2nd pass. Push most frequent literals into stack.\n Array.from(stackFreq.entries())\n .filter(([val, freq]) => freq > 1 && val > 1n && val !== 32n && val !== 224n)\n .sort((a, b) => stackCnt.get(b[0])! - stackCnt.get(a[0])!)\n .filter(([val, _]) => {\n return typeof val === 'number' ? BigInt(val) : val <= MAX_160_BIT;\n })\n .slice(0, 13)\n .forEach(([val, _]) => {\n pushN(val);\n });\n pushN(1n);\n // Second pass: emit ops and track mem/stack\n for (const step of plan) {\n if (step.t === 'num') pushN(step.v);\n else if (step.t === 'bytes') pushB(step.b);\n else if (step.t === 'op') op(step.o);\n }\n\n // CALL stack layout (top to bottom): gas, address, value, argsOffset, argsSize, retOffset, retSize\n //\n // Opcodes breakdown:\n // - 0x5f5f: PUSH0 PUSH0 (retSize=0, retOffset=0)\n // - pushN(originalBuf.length): argsSize = actual data length\n // - pushN(padding): argsOffset (skip leading alignment bytes)\n // - 0x34: CALLVALUE (value)\n // - 0x5f35: PUSH0 CALLDATALOAD (address from calldata[0])\n // - 0x5a: GAS (remaining gas)\n // - 0xf1: CALL\n //\n // RETURNDATACOPY(destOffset=0, offset=0, length=RETURNDATASIZE):\n // - 0x3d5f5f3e: RETURNDATASIZE PUSH0 PUSH0 RETURNDATACOPY\n //\n // RETURN(offset=0, size=RETURNDATASIZE):\n // - 0x3d5ff3: RETURNDATASIZE PUSH0 RETURN\n\n op(0x5f); // PUSH0 (retSize)\n op(0x5f); // PUSH0 (retOffset)\n pushN(originalBuf.length); // argsSize = actual data length\n pushN(padding); // argsOffset = padding\n\n const out: number[] = [];\n for (let i = 0; i < ops.length; ++i) {\n out.push(ops[i]);\n if (ops[i] >= 0x60 && ops[i] <= 0x7f && data[i]) out.push(...data[i]!);\n }\n\n // - CALLVALUE, load target address from calldata[0], GAS, CALL\n // - RETURNDATACOPY(0, 0, RETURNDATASIZE)\n // - RETURN(0, RETURNDATASIZE)\n return '0x' + _uint8ArrayToHex(new Uint8Array(out)) + '345f355af13d5f5f3e3d5ff3';\n};\n\nconst MIN_SIZE_FOR_COMPRESSION = 1150;\nconst DECOMPRESSOR_ADDRESS = '0x00000000000000000000000000000000000000e0';\n\nconst _jit = 'jit';\nconst _flz = 'flz';\nconst _cd = 'cd';\n\n/**\n * Compresses eth_call payload using JIT, FastLZ (FLZ), or calldata RLE (CD) compression.\n * Auto-selects best algorithm if not specified. Only compresses if >800 bytes and beneficial.\n * @param payload - eth_call RPC payload\n * @param alg - 'jit' | 'flz' | 'cd' | undefined (auto)\n * @returns (un)compressed eth_call payload\n * @pure\n */\n//! @__PURE__\nexport const compress_call = function (payload: any, alg?: string): any {\n const rpcMethod = payload.params?.[0]?.method || payload.method;\n if (rpcMethod && rpcMethod !== 'eth_call') return payload;\n\n // Extract data and target address from params[0] if available, otherwise top-level\n const txObj = payload.params?.[0] || payload;\n const blockParam = payload.params?.[1] || 'latest';\n const existingStateOverride = payload.params?.[2] || {};\n\n // If there are any existing state overrides for the decompressor address, do not compress\n const hex = _normHex(txObj.data || '0x');\n const originalSize = (txObj.data || '0x').length;\n if (originalSize < MIN_SIZE_FOR_COMPRESSION || (existingStateOverride[DECOMPRESSOR_ADDRESS])) return payload;\n\n const targetAddress = txObj.to || '';\n const data = '0x' + hex;\n\n const autoSelect = !alg && originalSize < 1150;\n const flz = alg === _flz || autoSelect ? LibZip.flzCompress(data) : null;\n const cd = alg === _cd || autoSelect ? LibZip.cdCompress(data) : null;\n let selectedMethod = alg;\n if (!selectedMethod) {\n selectedMethod =\n originalSize >= 1150 && (originalSize < 3000 || originalSize >= 8000)\n ? _jit\n : originalSize >= 3000 && originalSize < 8000\n ? flz!.length < cd!.length\n ? _flz\n : _cd\n : _cd;\n }\n\n let bytecode: string;\n let calldata: string;\n\n if (selectedMethod === _jit) {\n bytecode = _jitDecompressor(data);\n calldata = '0x' + _normHex(targetAddress).padStart(64, '0');\n } else {\n const isFlz = selectedMethod === _flz;\n calldata = isFlz ? flz! : cd!;\n bytecode = isFlz ? flzFwdBytecode(targetAddress) : rleFwdBytecode(targetAddress);\n }\n\n const compressedSize = bytecode.length + calldata.length;\n if (compressedSize >= originalSize) return payload;\n\n return {\n ...payload,\n params: [\n {\n ...txObj,\n to: DECOMPRESSOR_ADDRESS,\n data: calldata,\n },\n blockParam,\n {\n ...existingStateOverride,\n [DECOMPRESSOR_ADDRESS]: { code: bytecode },\n },\n ],\n };\n};\n", "import zlib from 'node:zlib';\n\n// Polyfill for CompressionStream/DecompressionStream in Node.js\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", "const _sup_enc = new Map<string, string[] | -1>();\nconst _enc = ['deflate-raw', 'deflate', 'gzip'];\nlet supported: string | -1 | null = typeof CompressionStream === 'undefined' ? -1 : null;\n\nexport type PayloadTransform = (payload: unknown) => unknown;\n\n/**\n * Fetch-compatible function that applies HTTP compression (gzip/deflate) to requests.\n * Optionally transforms request payloads before sending.\n *\n * @param input - The resource URL, Request object, or URL string\n * @param init - Optional request initialization options\n * @param transformPayload - Optional function to transform the request payload\n * @returns A Promise that resolves to the Response\n */\n//! @__PURE__\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n): Promise<Response>;\n\n//! @__PURE__\nexport async function compressModule(\n input: string | URL | Request,\n init: RequestInit | undefined,\n transformPayload?: PayloadTransform,\n): Promise<Response>;\n\n//! @__PURE__\nexport async function compressModule(\n input: string | URL | Request,\n init?: RequestInit,\n transformPayload?: PayloadTransform,\n): Promise<Response> {\n const url =\n typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url;\n\n const cached = _sup_enc.get(url);\n supported = supported === -1 ? -1 : cached === -1 ? -1 : (cached?.[0] ?? null);\n\n // Only apply the optional payload transform\n // when native HTTP compression is not available for this URL.\n if (transformPayload && init?.body && typeof init.body === 'string') {\n if (supported === -1 || supported === null) {\n try {\n const parsed = JSON.parse(init.body as string);\n const next = transformPayload(parsed);\n if (next !== undefined) {\n init = {\n ...init,\n body: JSON.stringify(next),\n };\n }\n } catch {\n // Non-JSON bodies are left untouched.\n }\n }\n }\n\n if (supported && supported !== -1 && init?.body) {\n const compressed = await new Response(\n new Blob([init.body as string])\n .stream()\n .pipeThrough(new CompressionStream(supported as CompressionFormat)),\n ).blob();\n init = {\n ...init,\n body: compressed,\n headers: { ...(init && init.headers), 'Content-Encoding': supported },\n };\n }\n const response = await fetch(url, init);\n\n if (supported === null) {\n const encodings = response.headers\n .get('Accept-Encoding')\n ?.split(',')\n .filter((e) => _enc.includes(e));\n _sup_enc.set(url, encodings?.length ? encodings : -1);\n }\n\n return response;\n}\n\n/**\n * Combines HTTP compression with EVM JIT compression.\n * Just pass this as `fetchFn` to viem's http transport.\n *\n * @param input - The resource URL or Request object\n * @param init - Optional request initialization options\n * @returns A Promise that resolves to the Response\n *\n * @example\n * ```ts\n * const client = createPublicClient({\n * transport: http(rpcUrl, { fetchFn: compressModuleWithJIT })\n * })\n * ```\n *\n * If the target RPC endpoint and runtime support native HTTP compression,\n * this helper prefers that path and will not apply JIT calldata compression;\n * the JIT-based transform is used as a legacy/fallback path when HTTP\n * content-encoding is unavailable.\n * @pure\n */\n//! @__PURE__\nexport const compressModuleWithJIT = (\n input: RequestInfo | URL,\n init?: RequestInit,\n): Promise<Response> => {\n return import('./jit-compressor').then(({ compress_call }) =>\n compressModule(input, init, compress_call),\n );\n};\n"],
|
|
5
|
-
"mappings": "imBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,mBAAAE,GAAA,mBAAAC,GAAA,gBAAAC,GAAA,mBAAAC,KAAA,IAAAC,EAEMC,GAEAC,EAEAC,GAUAC,GAeOP,GAUAE,GASAD,GAIPO,GAsTAC,GACAC,EAEAC,GACAC,EACAC,EAWOd,GA5Xbe,GAAAC,GAAA,KAAAZ,EAAuB,kBAEjBC,IAAe,IAAM,MAAQ,GAE7BC,EAAYW,GAAwBA,EAAI,QAAQ,MAAO,EAAE,EAAE,YAAY,EAEvEV,GAAoBU,GAA4B,CACpD,IAAMC,EAAaZ,EAASW,CAAG,EACzBE,EAAMD,EAAW,OACjBE,EAAQ,IAAI,WAAWD,EAAM,CAAC,EACpC,QAASE,EAAI,EAAGA,EAAIF,EAAKE,GAAK,EAC5BD,EAAMC,EAAI,CAAC,EAAI,OAAO,SAASH,EAAW,MAAMG,EAAGA,EAAI,CAAC,EAAG,EAAE,EAE/D,OAAOD,CACT,EAEMZ,GAAoBY,GAA8B,CACtD,IAAIH,EAAM,GACV,QAASI,EAAI,EAAGA,EAAID,EAAM,OAAQC,IAChCJ,GAAOG,EAAMC,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,EAAG,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AC1B,IAAIH,EACAG,IAAW,UACbH,EAAS,EAAAI,QAAK,cAAc,EACnBD,IAAW,OACpBH,EAAS,EAAAI,QAAK,aAAa,EAClBD,IAAW,KACpBH,EAAS,EAAAI,QAAK,uBAAuB,EAErCJ,EAAS,EAAAI,QAAK,iBAAiB,EAEjCN,GAAK,KAAME,CAAM,CACnB,CACF",
|
|
6
|
-
"names": ["
|
|
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 hasCS = typeof CompressionStream !== 'undefined';\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": "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,EAAQ,OAAO,kBAAsB,IACrCC,EAAQR,IAAS,QAAUA,IAAS,UACpCS,EAAYF,EAEdC,EACGR,EACDA,IAAS,YACPM,IAAW,GACT,KACCA,GAAU,OACb,OAAOA,GAAW,SAChBA,EACA,KATN,KAWEI,EAAiB,CAAC,CAACD,GAAY,CAAC,CAACN,GAAWA,EAAQ,QAAU,KAC9DQ,EAAoB,CAAE,GAAGZ,EAAM,SAAU,MAA0B,EACnEa,EAAU,IAAI,QAAQD,EAAK,OAAO,EACpCD,IACFC,EAAK,KA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CACF,GAGG,WAAW,sBACd,WAAW,oBAAsB,KAA0B,CACzD,YAAYG,EAAgB,CAC1B,IAAIH,EACAG,IAAW,UACbH,EAAS,EAAAI,QAAK,cAAc,EACnBD,IAAW,OACpBH,EAAS,EAAAI,QAAK,aAAa,EAClBD,IAAW,KACpBH,EAAS,EAAAI,QAAK,uBAAuB,EAErCJ,EAAS,EAAAI,QAAK,iBAAiB,EAEjCN,EAAK,KAAME,CAAM,CACnB,CACF",
|
|
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", "hasCS", "known", "encoding", "shouldCompress", "opts", "headers", "response", "discovered", "e", "make", "ctx", "handle", "chunk", "ctrl", "format", "zlib"]
|
|
7
7
|
}
|
package/_cjs/jit-compressor.cjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
const it=s=>`0x5f5f5b368110602d575f8083813473${y(s)}5af1503d5f803e3d5ff35b600180820192909160031981019035185f1a8015604c57815301906002565b505f19815282820192607f9060031981019035185f1a818111156072575b160101906002565b838101368437606a56`;//! @__PURE__
|
|
4
|
-
const Mt=function(s){return st("0x"+y(s))},st=function(s){const r=y(s),c=dt(r),u=28,f=new Uint8Array(u+c.length);f.set(c,u);const z=f.length;let a=[],l=[],b=[],h=0,M=new Map;const O=t=>{const n=b.lastIndexOf(t);return n===-1?-1:b.length-1-n},U=new Map,A=new Map,m=new Map,p=new Map,k=new Map,K=t=>t+31&-32;let G=0;const D=new Map,_=()=>[b.pop(),b.pop()],q=(1n<<256n)-1n,H=(t,n,e)=>t.set(n,(t.get(n)||0)+e),J=(t,n)=>H(t,n,1),Q=(t,n)=>H(t,n,-1),N=t=>{a.push(t),J(U,t)},E=t=>{l.push(t||null),J(A,t||null)},x=(t,n=1)=>{b.push(t),H(m,t,n),++G,D.set(t,G)},Y=(t,n)=>{h=K(t+n)},B=(t,n)=>{if(t===54)x(32n,0);else if(t===89)x(BigInt(h),0);else if(t===27){let[e,i]=_();a[a.length-1]==144&&(a.pop(),l.pop(),[e,i]=[i,e]),x(i<<BigInt(e)&q)}else if(t===23){const[e,i]=_();a[a.length-1]==144&&(a.pop(),l.pop()),x((e|i)&q)}else if(t>=96&&t<=127||t===95){let e=0n;for(const g of n||[])e=e<<8n|BigInt(g);if(e==224n){x(e),N(48),E(null);return}const i=O(e);if(i!==-1&&t!=95){const g=m.get(e)==0;if(i==0&&g){Q(m,e);return}if(i==1&&g){N(144);const[R,j]=_();b.push(j),b.push(R),E(null),Q(m,e);return}x(e,-1),N(128+i),E(null);return}x(e)}else if(t===81){const e=Number(b.pop());x(M.has(e)?M.get(e):0n)}else if(t===82){const[e,i]=_(),g=Number(e);M.set(g,i&q),Y(g,32)}else if(t===83){const[e,i]=_();Y(Number(e),1)}else t===243&&_();N(t),E(n||null)},ct=t=>b.includes(t)||t==224||t==32n,F=t=>B(t),S=t=>{if(t>0&&t===h)return B(89);if(t==32n)return B(54);if(!t)return B(95,void 0);let n=BigInt(t),e=[];for(;n;)e.unshift(Number(n&0xffn)),n>>=8n;return B(95+e.length,e)},v=t=>B(95+t.length,Array.from(t)),ft=(t,n)=>(t.match(new RegExp(n,"g"))||[]).length,lt=t=>{let n=0,e=!0;for(const{s:i,e:g}of t)n+=1+g-i+1,31-g>0&&(n+=3),e||(n+=1),e=!1;return n},P=[],I=t=>(P.push({t:"num",v:t}),S(t)),T=t=>(P.push({t:"bytes",b:t}),v(t)),C=t=>(P.push({t:"op",o:t}),F(t));S(1n);for(let t=0;t<z;t+=32){const n=new Uint8Array(32);n.set(f.slice(t,Math.min(t+32,z)),0);const e=[];for(let o=0;o<32;){for(;o<32&&n[o]===0;)++o;if(o>=32)break;const d=o;for(;o<32&&n[o]!==0;)++o;e.push({s:d,e:o-1})}if(!e.length)continue;const i=n.slice(e[0].s),g=1+i.length;let R=0n;for(const o of i)R=R<<8n|BigInt(o);const j=Math.ceil(Math.log2(t+1)/8),w=et(n);if(g>8){if(p.has(w)){if(g>k.get(w)+j){I(p.get(w)),C(81),I(t),C(82);continue}}else if(k.get(w)!=-1){const o=j+3,d=ft(r,w);k.set(w,d*32>d*o?o:-1),p.set(w,t)}}const ut=e.every(({s:o,e:d})=>o===d);if(ct(i))T(i);else if(ut){for(const{s:o}of e)I(n[o]),I(t+o),C(83);continue}else if(g<=lt(e))T(i);else{let o=!0;for(const{s:d,e:tt}of e){const nt=31-tt;T(n.slice(d,tt+1)),nt>0&&(I(nt*8),C(27)),o||C(23),o=!1}}I(t),C(82)}a=[],l=[],b=[],h=0,M=new Map,Array.from(m.entries()).filter(([t,n])=>n>1&&t>1n&&t!==32n&&t!==224n).sort((t,n)=>D.get(n[0])-D.get(t[0])).filter(([t,n])=>typeof t=="number"?BigInt(t):t<=xt).slice(0,13).forEach(([t,n])=>{S(t)}),S(1n);for(const t of P)t.t==="num"?S(t.v):t.t==="bytes"?v(t.b):t.t==="op"&&F(t.o);F(95),F(95),S(c.length),S(u);const L=[];for(let t=0;t<a.length;++t)L.push(a[t]),a[t]>=96&&a[t]<=127&&l[t]&&L.push(...l[t]);return"0x"+et(new Uint8Array(L))+"345f355af13d5f5f3e3d5ff3"},St=1150,$="0x00000000000000000000000000000000000000e0",rt="jit",V="flz",W="cd";//! @__PURE__
|
|
5
|
-
const wt=function(s,r){const c=s.params?.[0]?.method||s.method;if(c&&c!=="eth_call")return s;const u=s.params?.[0]||s,f=s.params?.[1]||"latest",z=s.params?.[2]||{},a=y(u.data||"0x"),l=(u.data||"0x").length;if(l<St||z[$])return s;const b=u.to||"",h="0x"+a,M=!r&&l<1150,O=r===V||M?X.LibZip.flzCompress(h):null,U=r===W||M?X.LibZip.cdCompress(h):null;let A=r;A||(A=l>=1150&&(l<3e3||l>=8e3)?rt:l>=3e3&&l<8e3&&O.length<U.length?V:W);let m,p;if(A===rt)m=st(h),p="0x"+y(b).padStart(64,"0");else{const K=A===V;p=K?O:U,m=K?ot(b):it(b)}return m.length+p.length>=l?s:{...s,params:[{...u,to:$,data:p},f,{...z,[$]:{code:m}}]}};
|
|
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}]}};
|
|
2
|
+
//! @__PURE__
|
|
6
3
|
//# sourceMappingURL=jit-compressor.cjs.map
|