@chainfoundry/chaincodec-wasm-node 0.1.0 → 0.1.1

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 ADDED
@@ -0,0 +1,200 @@
1
+ # @chainfoundry/chaincodec-wasm
2
+
3
+ WebAssembly bindings for chaincodec — universal EVM ABI decoder for browsers, Deno, and edge runtimes.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@chainfoundry/chaincodec-wasm)](https://www.npmjs.com/package/@chainfoundry/chaincodec-wasm)
6
+ [![license](https://img.shields.io/npm/l/@chainfoundry/chaincodec-wasm)](LICENSE)
7
+
8
+ Browser-ready WASM build of [chaincodec-evm](https://crates.io/crates/chaincodec-evm) — decode `eth_getLogs` entries, compute topic0 fingerprints, and decode ABI calldata entirely client-side. No server, no native dependencies.
9
+
10
+ ---
11
+
12
+ ## Packages
13
+
14
+ Two packages are published from the same WASM build:
15
+
16
+ | Package | Target | Use case |
17
+ |---------|--------|----------|
18
+ | [`@chainfoundry/chaincodec-wasm`](https://www.npmjs.com/package/@chainfoundry/chaincodec-wasm) | ESM (browser) | React, Vue, Svelte, Vite |
19
+ | [`@chainfoundry/chaincodec-wasm-node`](https://www.npmjs.com/package/@chainfoundry/chaincodec-wasm-node) | CJS (Node.js) | Node without native bindings |
20
+
21
+ For Node.js production workloads, prefer [@chainfoundry/chaincodec](https://www.npmjs.com/package/@chainfoundry/chaincodec) (native napi-rs bindings) for better throughput.
22
+
23
+ ---
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ # Browser / Vite / webpack
29
+ npm install @chainfoundry/chaincodec-wasm
30
+
31
+ # Node.js (WASM fallback — no native binaries required)
32
+ npm install @chainfoundry/chaincodec-wasm-node
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Browser / Vite / webpack
38
+
39
+ ```typescript
40
+ import init, { EvmDecoder, MemoryRegistry, computeFingerprint }
41
+ from '@chainfoundry/chaincodec-wasm';
42
+
43
+ // WASM must be initialized once before use
44
+ await init();
45
+
46
+ // Load a CSDL schema from a string
47
+ const csdl = await fetch('/schemas/erc20.csdl').then(r => r.text());
48
+ const registry = new MemoryRegistry();
49
+ registry.loadFromString(csdl);
50
+
51
+ // Decode a log from eth_getLogs
52
+ const decoder = new EvmDecoder();
53
+
54
+ const rawLog = {
55
+ chain: 'ethereum',
56
+ txHash: '0xabc...',
57
+ blockNumber: BigInt(19500000),
58
+ logIndex: 0,
59
+ address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
60
+ topics: [
61
+ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
62
+ '0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045',
63
+ '0x000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b',
64
+ ],
65
+ data: '0x00000000000000000000000000000000000000000000000000000000000f4240',
66
+ };
67
+
68
+ const fp = decoder.fingerprint(rawLog);
69
+ const schema = registry.getByFingerprint(fp);
70
+
71
+ if (schema) {
72
+ const event = decoder.decodeEvent(rawLog, schema);
73
+ console.log(event.schemaName); // "ERC20Transfer"
74
+ console.log(event.fields.from); // "0xd8da6bf2..."
75
+ console.log(event.fields.value); // "1000000"
76
+ }
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Node.js (WASM fallback)
82
+
83
+ ```javascript
84
+ const { EvmDecoder, MemoryRegistry } = require('@chainfoundry/chaincodec-wasm-node');
85
+
86
+ // No init() needed for the Node.js CJS build
87
+ const registry = new MemoryRegistry();
88
+ registry.loadFromString(fs.readFileSync('./schemas/erc20.csdl', 'utf-8'));
89
+
90
+ const decoder = new EvmDecoder();
91
+ const fp = decoder.fingerprint(rawLog);
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Compute topic0 fingerprint
97
+
98
+ ```typescript
99
+ import init, { computeFingerprint } from '@chainfoundry/chaincodec-wasm';
100
+ await init();
101
+
102
+ const fp = computeFingerprint('Transfer(address,address,uint256)');
103
+ // "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
104
+ ```
105
+
106
+ This is useful for building event filters without a backend:
107
+
108
+ ```typescript
109
+ const filter = {
110
+ address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
111
+ topics: [computeFingerprint('Transfer(address,address,uint256)')],
112
+ };
113
+ // Pass to eth_getLogs, viem watchEvent, ethers.js filter, etc.
114
+ ```
115
+
116
+ ---
117
+
118
+ ## Usage with Deno
119
+
120
+ ```typescript
121
+ import init, { EvmDecoder } from 'npm:@chainfoundry/chaincodec-wasm';
122
+ await init();
123
+
124
+ const decoder = new EvmDecoder();
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Usage with Cloudflare Workers
130
+
131
+ ```typescript
132
+ // wrangler.toml: compatibility_flags = ["nodejs_compat"]
133
+ import init, { EvmDecoder } from '@chainfoundry/chaincodec-wasm';
134
+
135
+ export default {
136
+ async fetch(request: Request): Promise<Response> {
137
+ await init();
138
+ const decoder = new EvmDecoder();
139
+ // ...
140
+ return new Response('ok');
141
+ },
142
+ };
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Bundle size
148
+
149
+ | Target | .wasm size | JS glue | Total (gzip) |
150
+ |--------|-----------|---------|-------------|
151
+ | Browser ESM | ~850 KB | ~12 KB | ~280 KB |
152
+ | Node.js CJS | ~850 KB | ~10 KB | ~280 KB |
153
+
154
+ The WASM binary is optimized with `wasm-opt -O3`. For browser use, serve the `.wasm` file with `Content-Type: application/wasm` for streaming instantiation.
155
+
156
+ ---
157
+
158
+ ## API reference
159
+
160
+ ### `EvmDecoder`
161
+
162
+ | Method | Description |
163
+ |--------|-------------|
164
+ | `fingerprint(log)` | Compute topic0 fingerprint from a raw log |
165
+ | `decodeEvent(log, schema)` | Decode a log into named `NormalizedValue` fields |
166
+
167
+ ### `MemoryRegistry`
168
+
169
+ | Method | Description |
170
+ |--------|-------------|
171
+ | `loadFromString(csdl)` | Parse and register schemas from a CSDL YAML string |
172
+ | `getByFingerprint(fp)` | Look up schema by topic0 hash |
173
+ | `getByName(name)` | Look up schema by name |
174
+
175
+ ### Functions
176
+
177
+ | Function | Description |
178
+ |----------|-------------|
179
+ | `computeFingerprint(sig)` | Compute keccak256 topic0 from a Solidity event signature |
180
+ | `init()` | Initialize the WASM module (browser ESM only) |
181
+
182
+ ---
183
+
184
+ ## Differences from the native Node.js package
185
+
186
+ | Feature | `@chainfoundry/chaincodec` (napi) | `@chainfoundry/chaincodec-wasm` |
187
+ |---------|----------------------------------|--------------------------------|
188
+ | Runtime | Node.js only | Browser, Deno, Workers, Node.js |
189
+ | Throughput | ~6M events/sec (Rayon) | ~500K events/sec (single-thread) |
190
+ | Install size | ~2 MB (.node binary) | ~850 KB (.wasm) |
191
+ | Native deps | Yes (pre-built) | None |
192
+ | `init()` required | No | Yes (browser ESM only) |
193
+
194
+ Use the napi package for server-side indexers. Use the WASM package for browser dApps, edge functions, and zero-native-dep environments.
195
+
196
+ ---
197
+
198
+ ## License
199
+
200
+ MIT — see [LICENSE](https://github.com/DarshanKumar89/chainkit/blob/main/LICENSE)
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chainfoundry/chaincodec-wasm-node",
3
3
  "description": "WebAssembly bindings for chaincodec — Node.js CJS bundle",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "chaincodec_wasm_bg.wasm",