webevm 0.0.0 → 0.6.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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +693 -0
  3. package/dist/engine.d.ts +69 -0
  4. package/dist/engine.d.ts.map +1 -0
  5. package/dist/engine.js +269 -0
  6. package/dist/engine.js.map +1 -0
  7. package/dist/index.d.ts +12 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +21 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/intrinsic-gas.d.ts +149 -0
  12. package/dist/intrinsic-gas.d.ts.map +1 -0
  13. package/dist/intrinsic-gas.js +94 -0
  14. package/dist/intrinsic-gas.js.map +1 -0
  15. package/dist/node.d.ts +3 -0
  16. package/dist/node.d.ts.map +1 -0
  17. package/dist/node.js +1931 -0
  18. package/dist/node.js.map +1 -0
  19. package/dist/persistence.d.ts +22 -0
  20. package/dist/persistence.d.ts.map +1 -0
  21. package/dist/persistence.js +54 -0
  22. package/dist/persistence.js.map +1 -0
  23. package/dist/revm-state-store.d.ts +89 -0
  24. package/dist/revm-state-store.d.ts.map +1 -0
  25. package/dist/revm-state-store.js +394 -0
  26. package/dist/revm-state-store.js.map +1 -0
  27. package/dist/revm.d.ts +124 -0
  28. package/dist/revm.d.ts.map +1 -0
  29. package/dist/revm.js +657 -0
  30. package/dist/revm.js.map +1 -0
  31. package/dist/sender-recovery.d.ts +78 -0
  32. package/dist/sender-recovery.d.ts.map +1 -0
  33. package/dist/sender-recovery.js +53 -0
  34. package/dist/sender-recovery.js.map +1 -0
  35. package/dist/state-manager.d.ts +327 -0
  36. package/dist/state-manager.d.ts.map +1 -0
  37. package/dist/state-manager.js +439 -0
  38. package/dist/state-manager.js.map +1 -0
  39. package/dist/storage-keys.d.ts +21 -0
  40. package/dist/storage-keys.d.ts.map +1 -0
  41. package/dist/storage-keys.js +113 -0
  42. package/dist/storage-keys.js.map +1 -0
  43. package/dist/types.d.ts +696 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +12 -0
  46. package/dist/types.js.map +1 -0
  47. package/dist/worker-client.d.ts +21 -0
  48. package/dist/worker-client.d.ts.map +1 -0
  49. package/dist/worker-client.js +77 -0
  50. package/dist/worker-client.js.map +1 -0
  51. package/dist/worker-entry.d.ts +32 -0
  52. package/dist/worker-entry.d.ts.map +1 -0
  53. package/dist/worker-entry.js +29 -0
  54. package/dist/worker-entry.js.map +1 -0
  55. package/dist/worker-host.d.ts +75 -0
  56. package/dist/worker-host.d.ts.map +1 -0
  57. package/dist/worker-host.js +188 -0
  58. package/dist/worker-host.js.map +1 -0
  59. package/package.json +90 -2
  60. package/src/engine.ts +300 -0
  61. package/src/index.ts +46 -0
  62. package/src/intrinsic-gas.ts +191 -0
  63. package/src/node.ts +2150 -0
  64. package/src/persistence.ts +80 -0
  65. package/src/revm-state-store.ts +455 -0
  66. package/src/revm.ts +809 -0
  67. package/src/sender-recovery.ts +142 -0
  68. package/src/state-manager.ts +531 -0
  69. package/src/storage-keys.ts +150 -0
  70. package/src/types.ts +717 -0
  71. package/src/worker-client.ts +112 -0
  72. package/src/worker-entry.ts +31 -0
  73. package/src/worker-host.ts +232 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAE/C,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,MAAM,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IAAI,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC"}
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ /** EIP-1193-style JSON-RPC error (what we throw for honest gaps). */
2
+ export class RpcError extends Error {
3
+ code;
4
+ data;
5
+ constructor(code, message, data) {
6
+ super(message);
7
+ this.name = 'RpcError';
8
+ this.code = code;
9
+ this.data = data;
10
+ }
11
+ }
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuBA,qEAAqE;AACrE,MAAM,OAAO,QAAS,SAAQ,KAAK;IACzB,IAAI,CAAS;IACb,IAAI,CAAW;IACxB,YAAY,IAAY,EAAE,OAAe,EAAE,IAAc;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD"}
@@ -0,0 +1,21 @@
1
+ import type { NodeOptions, SlimNode } from './types.js';
2
+ export interface WorkerNodeOptions extends NodeOptions {
3
+ /**
4
+ * A Worker already pointing at this package's worker-entry, or at a module of
5
+ * your own that called `exposeNode()` (`webevm/worker-host`), which is the
6
+ * shape for a Worker that builds its own engine. Consumers create it themselves
7
+ * so the bundler controls chunking:
8
+ * new Worker(new URL('webevm/worker-entry', import.meta.url),
9
+ * {type: 'module'})
10
+ */
11
+ worker: Worker;
12
+ /**
13
+ * NOT AVAILABLE ON THIS PATH, and typed `never` so it is a compile error
14
+ * rather than a runtime surprise (it is also refused at runtime, for JS
15
+ * consumers). See the refusal in {@link createWorkerNode} for why, and for the
16
+ * supported way to run a non-default engine inside a Worker.
17
+ */
18
+ engine?: never;
19
+ }
20
+ export declare function createWorkerNode(opts: WorkerNodeOptions): Promise<SlimNode>;
21
+ //# sourceMappingURL=worker-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-client.d.ts","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACX,WAAW,EACX,QAAQ,EAGR,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACrD;;;;;;;OAOG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CACf;AAED,wBAAsB,gBAAgB,CACrC,IAAI,EAAE,iBAAiB,GACrB,OAAO,CAAC,QAAQ,CAAC,CAsEnB"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * worker-client.ts — the OPTIONAL main-thread side. Wraps a Worker (running
3
+ * ./worker-entry.ts) over comlink and returns the SAME `{ request, mine,
4
+ * dumpState, loadState, ... }` shape as `createNode()`. So `createNode()` (main
5
+ * thread) and `createWorkerNode()` (Worker) are interchangeable one-liners and
6
+ * the consumer never hand-rolls the comlink plumbing.
7
+ */
8
+ import { wrap, proxy } from 'comlink';
9
+ export async function createWorkerNode(opts) {
10
+ const { worker, ...nodeOptions } = opts;
11
+ // AN ENGINE CANNOT CROSS THIS BOUNDARY, and says so. `WorkerNodeOptions`
12
+ // extends `NodeOptions`, so `engine` is structurally in scope here, but these
13
+ // options are STRUCTURED-CLONED into the Worker and an `Engine` is a
14
+ // function-bearing object: comlink would throw an opaque `DataCloneError` from
15
+ // deep inside its own postMessage, which is exactly the plausible-looking
16
+ // failure this package's honest-edge convention exists to prevent. Cloning
17
+ // could not work in principle either — an engine holds live state (a wasm
18
+ // instance, a binding to the node's state manager) that belongs to the thread
19
+ // that built it.
20
+ //
21
+ // The supported shape is to build the engine INSIDE the worker, in your own
22
+ // worker module, and expose the node from there:
23
+ //
24
+ // // my-worker.ts
25
+ // import {exposeNode} from 'webevm/worker-host';
26
+ // import {createRevmEngine} from 'webevm/revm';
27
+ // import wasm from 'revm-wasm/revm.wasm';
28
+ // exposeNode({createEngine: () => createRevmEngine({wasm})});
29
+ //
30
+ // `exposeNode` supplies the node and the proxy; the ENGINE is yours, built on
31
+ // the thread that will use it. This package deliberately does not build it for
32
+ // you, because that would mean the core naming engines by string and importing them,
33
+ // which is precisely what ADR 0006 refuses (a JS-only consumer would pay for
34
+ // revm).
35
+ if (nodeOptions.engine !== undefined) {
36
+ throw new Error("webevm/worker-client: `engine` is not supported by createWorkerNode(). The node's options are structured-cloned into the Worker and an Engine is a function-bearing object, so it cannot be cloned across the thread boundary (comlink would report only a DataCloneError). " +
37
+ 'Build the engine INSIDE the Worker instead: write your own worker module that calls exposeNode({createEngine: () => createRevmEngine({wasm})}) from webevm/worker-host, which exposes the node for you, then drive it with the same client code. ' +
38
+ 'Or run the engine on the main thread with createNode().');
39
+ }
40
+ const api = wrap(worker);
41
+ const remote = await api.createNode(nodeOptions);
42
+ // stateMode/senderMode/engine are plain values on the node; over comlink
43
+ // they read as promises.
44
+ //
45
+ // NO `as any` HERE, and that is load-bearing. The remote is a `SlimNode` (the
46
+ // one proxy in ./worker-host.ts is typed as one), so these three reads are
47
+ // CHECKED: `senderMode` was silently absent from that proxy for a month, and
48
+ // what hid it from the compiler was the cast that used to be on this line.
49
+ const stateMode = await remote.stateMode;
50
+ const senderMode = await remote.senderMode;
51
+ const engineInfo = await remote.engine;
52
+ return {
53
+ request: (args) => remote.request(args),
54
+ mine: () => remote.mine(),
55
+ dumpState: () => remote.dumpState(),
56
+ loadState: (s) => remote.loadState(s),
57
+ stateMode,
58
+ senderMode,
59
+ engine: engineInfo,
60
+ getStateRoot: () => remote.getStateRoot(),
61
+ onNewHead(cb) {
62
+ // The callback must cross the thread boundary as a comlink proxy.
63
+ let unsub;
64
+ void remote.onNewHead(proxy(cb)).then((u) => {
65
+ unsub = u;
66
+ });
67
+ return () => {
68
+ void unsub?.();
69
+ };
70
+ },
71
+ async dispose() {
72
+ await remote.dispose();
73
+ worker.terminate();
74
+ },
75
+ };
76
+ }
77
+ //# sourceMappingURL=worker-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-client.js","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAC,IAAI,EAAE,KAAK,EAAC,MAAM,SAAS,CAAC;AAgCpC,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,IAAuB;IAEvB,MAAM,EAAC,MAAM,EAAE,GAAG,WAAW,EAAC,GAAG,IAAI,CAAC;IACtC,yEAAyE;IACzE,8EAA8E;IAC9E,qEAAqE;IACrE,+EAA+E;IAC/E,0EAA0E;IAC1E,2EAA2E;IAC3E,0EAA0E;IAC1E,8EAA8E;IAC9E,iBAAiB;IACjB,EAAE;IACF,4EAA4E;IAC5E,iDAAiD;IACjD,EAAE;IACF,o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C,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC3C,KAAK,GAAG,CAAC,CAAC;YACX,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,EAAE;gBACX,KAAK,KAAK,EAAE,EAAE,CAAC;YAChB,CAAC,CAAC;QACH,CAAC;QACD,KAAK,CAAC,OAAO;YACZ,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,MAAM,CAAC,SAAS,EAAE,CAAC;QACpB,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * worker-entry.ts: the OPTIONAL Worker side, AS A WORKER ENTRY POINT. The
3
+ * package's node api, exposed the moment this module is imported. That import-time
4
+ * `expose()` is the whole of what this file adds, and it is what makes the common
5
+ * case a one-liner:
6
+ *
7
+ * new Worker(new URL('webevm/worker-entry', import.meta.url),
8
+ * {type: 'module'});
9
+ *
10
+ * Pair it with `createWorkerNode()` (see ./worker-client.ts) on the main thread.
11
+ *
12
+ * THE NODE API ITSELF LIVES IN ./worker-host.ts, with no side effect, because a
13
+ * side effect cannot be imported: a consumer whose worker must build something
14
+ * first (an ENGINE, which cannot cross the boundary) used to hand-copy the
15
+ * `SlimNode` proxy, since importing THIS module would have exposed the default api
16
+ * on their thread. They call `exposeNode()` from `webevm/worker-host`
17
+ * instead, and the proxy exists in exactly one place.
18
+ *
19
+ * Why the split exists at all: heavy pure-JS EVM compute can hang the browser main
20
+ * thread. Moving the node into a Worker fixes that, but it's the consumer's
21
+ * CHOICE. The same `createNode()` runs fine on the main thread too.
22
+ */
23
+ import { type NodeWorkerApi } from './worker-host.js';
24
+ /**
25
+ * The exposed api. Kept exported (and exposed at import time) because consumers
26
+ * import this module for exactly that: nothing here changed when the proxy moved.
27
+ */
28
+ export declare const workerApi: {
29
+ createNode(options: import("./types.js").NodeOptions): Promise<import("./types.js").SlimNode & import("comlink").ProxyMarked>;
30
+ };
31
+ export type WorkerApi = NodeWorkerApi;
32
+ //# sourceMappingURL=worker-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-entry.d.ts","sourceRoot":"","sources":["../src/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAa,KAAK,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,SAAS;;CAAe,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * worker-entry.ts: the OPTIONAL Worker side, AS A WORKER ENTRY POINT. The
3
+ * package's node api, exposed the moment this module is imported. That import-time
4
+ * `expose()` is the whole of what this file adds, and it is what makes the common
5
+ * case a one-liner:
6
+ *
7
+ * new Worker(new URL('webevm/worker-entry', import.meta.url),
8
+ * {type: 'module'});
9
+ *
10
+ * Pair it with `createWorkerNode()` (see ./worker-client.ts) on the main thread.
11
+ *
12
+ * THE NODE API ITSELF LIVES IN ./worker-host.ts, with no side effect, because a
13
+ * side effect cannot be imported: a consumer whose worker must build something
14
+ * first (an ENGINE, which cannot cross the boundary) used to hand-copy the
15
+ * `SlimNode` proxy, since importing THIS module would have exposed the default api
16
+ * on their thread. They call `exposeNode()` from `webevm/worker-host`
17
+ * instead, and the proxy exists in exactly one place.
18
+ *
19
+ * Why the split exists at all: heavy pure-JS EVM compute can hang the browser main
20
+ * thread. Moving the node into a Worker fixes that, but it's the consumer's
21
+ * CHOICE. The same `createNode()` runs fine on the main thread too.
22
+ */
23
+ import { exposeNode } from './worker-host.js';
24
+ /**
25
+ * The exposed api. Kept exported (and exposed at import time) because consumers
26
+ * import this module for exactly that: nothing here changed when the proxy moved.
27
+ */
28
+ export const workerApi = exposeNode();
29
+ //# sourceMappingURL=worker-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-entry.js","sourceRoot":"","sources":["../src/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAC,UAAU,EAAqB,MAAM,kBAAkB,CAAC;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,EAAE,CAAC"}
@@ -0,0 +1,75 @@
1
+ import type { Engine, NodeOptions, SlimNode } from './types.js';
2
+ /**
3
+ * Builds the {@link Engine} for ONE node, on the thread that will run it.
4
+ *
5
+ * A FUNCTION, not a built engine, for two reasons that are both structural.
6
+ * Building an engine is ASYNC (`createRevmEngine()` compiles wasm), and this way
7
+ * the await belongs to `createNode()`'s own await instead of to the consumer's
8
+ * module top level. And one engine instance serves ONE node (`connect()` binds it
9
+ * to that node's state manager, and handing a connected engine to a second
10
+ * `createNode()` throws), so an engine VALUE here would work once and then fail
11
+ * the second time this worker was asked for a node.
12
+ */
13
+ export type EngineSupplier = () => Engine | Promise<Engine>;
14
+ /** What the WORKER thread decides. Everything else is the main thread's. */
15
+ export interface WorkerHostOptions {
16
+ /**
17
+ * Build this node's engine on THIS thread. Omit it for the default
18
+ * `@ethereumjs/evm` engine (what `worker-entry` does).
19
+ *
20
+ * Called ONCE PER `createNode()`, so each node gets its own engine instance:
21
+ *
22
+ * exposeNode({createEngine: () => createRevmEngine({wasm})});
23
+ *
24
+ * `createEngine`, not `engine`, deliberately: `NodeOptions.engine` is an
25
+ * `Engine` everywhere else in this package, and one name meaning "an engine"
26
+ * in one place and "a function that makes one" in another is how the wrong
27
+ * value gets passed. The main thread's options are untouched by this: they
28
+ * still travel through `createWorkerNode()` as they always did, and an engine
29
+ * still cannot come from there (see `./worker-client.ts`'s refusal).
30
+ */
31
+ createEngine?: EngineSupplier;
32
+ }
33
+ /**
34
+ * The comlink API a Worker exposes: `createNode(options)` with the SAME options
35
+ * `createNode()` takes on the main thread, returning the node as a proxy.
36
+ *
37
+ * Use {@link exposeNode} unless you are composing this into a larger exposed API
38
+ * of your own; this is the same object `worker-entry` exposes.
39
+ */
40
+ export declare function createNodeWorkerApi(hostOptions?: WorkerHostOptions): {
41
+ createNode(options: NodeOptions): Promise<SlimNode & import("comlink").ProxyMarked>;
42
+ };
43
+ /** The api {@link exposeNode} exposes, i.e. what a client should `wrap<>()`. */
44
+ export type NodeWorkerApi = ReturnType<typeof createNodeWorkerApi>;
45
+ /**
46
+ * Expose a node factory on THIS thread. This is the whole of a consumer's worker module:
47
+ *
48
+ * // my-worker.ts
49
+ * import {exposeNode} from 'webevm/worker-host';
50
+ * import {createRevmEngine} from 'webevm/revm';
51
+ * import wasm from 'revm-wasm/revm.wasm';
52
+ *
53
+ * exposeNode({createEngine: () => createRevmEngine({wasm})});
54
+ *
55
+ * The main thread then drives it with the ordinary client, unchanged:
56
+ * `createWorkerNode({worker, chainId, ...})`. Call it ONCE per thread: comlink's
57
+ * `expose()` adds a message listener, so two of them answer the same message
58
+ * twice.
59
+ *
60
+ * DO NOT `await` ANYTHING AT THIS MODULE'S TOP LEVEL BEFORE CALLING IT. A worker
61
+ * module that awaits something slower than a microtask (fetching wasm, opening a
62
+ * database) before `exposeNode()` can LOSE the main thread's first message, and
63
+ * then `createWorkerNode()` never settles. Measured on Chromium and WebKit
64
+ * (`work/notes/observations/a-top-level-await-in-a-worker-module-loses-the-first-message.md`).
65
+ * Nothing here can fix it: there is no listener to register until this call runs.
66
+ * The recipe above is safe because `() => createRevmEngine({wasm})` is
67
+ * SYNCHRONOUS at module scope: the factory defers the await into `createNode()`,
68
+ * which is one of the reasons `createEngine` is a function. If you must await
69
+ * something first, do it INSIDE `createEngine` (or inside a wrapper it calls),
70
+ * not above this line.
71
+ *
72
+ * Returns the exposed api, so `export const myApi = exposeNode(...)` is one line.
73
+ */
74
+ export declare function exposeNode(hostOptions?: WorkerHostOptions): NodeWorkerApi;
75
+ //# sourceMappingURL=worker-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-host.d.ts","sourceRoot":"","sources":["../src/worker-host.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE5D,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IACjC;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,EAAE,cAAc,CAAC;CAC9B;AAkCD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,GAAE,iBAAsB;wBAiB3C,WAAW;EAatC;AA2CD,gFAAgF;AAChF,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,CAAC,WAAW,GAAE,iBAAsB,GAAG,aAAa,CAI7E"}
@@ -0,0 +1,188 @@
1
+ /**
2
+ * worker-host.ts: THE WORKER SIDE OF THE NODE, minus the side effect: the ONE
3
+ * `SlimNode` proxy that crosses a comlink boundary, and the two ways to put it on
4
+ * a thread. `./worker-entry.ts` is this module plus an import-time `expose()`;
5
+ * a consumer whose Worker must build something first (an ENGINE) calls
6
+ * {@link exposeNode} from their own worker module instead.
7
+ *
8
+ * WHY IT IS A SEPARATE MODULE. `worker-entry` calls `expose()` at MODULE SCOPE,
9
+ * which is what makes `new Worker(new URL('webevm/worker-entry', ...))`
10
+ * a one-liner, and also what makes it unusable as a library: importing it to
11
+ * reuse the proxy would expose the DEFAULT api on the importing thread, so
12
+ * consumers hand-copied the proxy block instead. There were three copies of it
13
+ * (this package's, this repo's example, and every consumer's), each able to drop a
14
+ * field independently. That is not hypothetical: `senderMode` was missing from
15
+ * one of them for a month, reading as `undefined` on a property typed
16
+ * `'recover' | 'trusted'`. Now there is one copy, here.
17
+ *
18
+ * AND IT IS THE COMPILER THAT KEEPS IT COMPLETE. {@link nodeProxy}'s literal is
19
+ * typed `Required<SlimNode>`, so a field ADDED to `SlimNode` later fails to build
20
+ * here rather than reading as `undefined` on the far side of a thread boundary;
21
+ * the client (`./worker-client.ts`) reads those fields off the remote with no
22
+ * `as any` in the way, so the type is load-bearing on both ends. That covers a
23
+ * future field structurally, which is the property enumerating today's fields
24
+ * cannot have. `Required<>` is what extends it to an OPTIONAL member: a bare
25
+ * `SlimNode` annotation does not DEMAND one, so an optional field added later
26
+ * would compile while missing here. The runtime parity check that backs this up
27
+ * (`test/helpers/worker-roundtrip.ts`) cannot be widened the same way and says so
28
+ * itself: it enumerates the keys of a reference node INSTANCE, and an optional
29
+ * field that instance does not carry is invisible to it.
30
+ *
31
+ * A MISUSE OF {@link WorkerHostOptions.createEngine} IS A VALUE, NEVER A THROW,
32
+ * and that ordering is the whole of why: `expose()` registers comlink's message
33
+ * listener, so a module that throws BEFORE reaching it answers the main thread
34
+ * nothing at all and `createWorkerNode()` stays pending forever. The refusal is
35
+ * therefore recorded here, reported on this thread immediately, and re-thrown
36
+ * from `createNode()` where it crosses the boundary as a rejection the caller can
37
+ * read. Both threads say something; neither is left guessing.
38
+ * `docs/spikes/a-bad-createengine-hangs-the-main-thread-instead-of-rejecting/decisions.md`.
39
+ *
40
+ * WHAT THIS MODULE DOES NOT DO: name an engine. The core imports no engine and
41
+ * resolves no engine name (`docs/adr/0006-the-engine-is-an-injected-object-not-a-named-string.md`),
42
+ * so an engine reaches a node here exactly as it does on the main thread, as an
43
+ * object the CONSUMER built, on the thread that will use it. This module never
44
+ * mentions `webevm/revm`, and a JS-only consumer's bundle is unmoved by
45
+ * its existence.
46
+ */
47
+ import { expose, proxy } from 'comlink';
48
+ import { createNode } from './node.js';
49
+ /**
50
+ * THE ONE `SlimNode` PROXY. Comlink cannot pass the node itself (its methods are
51
+ * functions and its subscription hands back another one), so this is the node's
52
+ * public surface rendered for the boundary.
53
+ *
54
+ * TYPED `Required<SlimNode>` ON PURPOSE, and that annotation is the mechanism
55
+ * rather than documentation: every member of `SlimNode` must be here or this does
56
+ * not compile, today and for every field added later, INCLUDING an optional one
57
+ * (which a bare `SlimNode` annotation would let through, since it demands only
58
+ * the required members). `SlimNode` has no optional members today, so this costs
59
+ * nothing now and stops the one thing the guarantee otherwise missed. The plain
60
+ * values (`stateMode`, `senderMode`, `engine`) clone across as-is; the client
61
+ * reads them off the remote as promises.
62
+ */
63
+ function nodeProxy(node) {
64
+ const forwarded = {
65
+ request: (args) => node.request(args),
66
+ mine: () => node.mine(),
67
+ dumpState: () => node.dumpState(),
68
+ loadState: (state) => node.loadState(state),
69
+ getStateRoot: () => node.getStateRoot(),
70
+ stateMode: node.stateMode,
71
+ senderMode: node.senderMode,
72
+ engine: node.engine,
73
+ // newHeads over comlink: the callback arrives as a comlink proxy, and the
74
+ // unsubscribe going back must be marked as one too, or it clones as `{}`.
75
+ onNewHead: (cb) => proxy(node.onNewHead(cb)),
76
+ dispose: () => node.dispose(),
77
+ };
78
+ return forwarded;
79
+ }
80
+ /**
81
+ * The comlink API a Worker exposes: `createNode(options)` with the SAME options
82
+ * `createNode()` takes on the main thread, returning the node as a proxy.
83
+ *
84
+ * Use {@link exposeNode} unless you are composing this into a larger exposed API
85
+ * of your own; this is the same object `worker-entry` exposes.
86
+ */
87
+ export function createNodeWorkerApi(hostOptions = {}) {
88
+ const { createEngine } = hostOptions;
89
+ // THE REFUSAL IS A VALUE. Passing the ENGINE (or the promise of one) where its
90
+ // FACTORY belongs is the one plausible mistake at this seam, and it is refused
91
+ // with a real message rather than left to become a `TypeError` from inside
92
+ // `createNode`. What it must NOT do is throw from here: this function runs while
93
+ // the worker module is still evaluating, so a throw means `expose()` never runs,
94
+ // the worker registers no message listener, and an awaited `createWorkerNode()`
95
+ // on the main thread never settles at all. Recorded here, said out loud here,
96
+ // and thrown where a caller can catch it.
97
+ const refusal = engineSupplierRefusal(createEngine);
98
+ // THE EARLY SIGNAL, on the thread the mistake was written on and at the moment
99
+ // it was made: a developer with the worker console open reads it before anybody
100
+ // asks for a node. It is not the only one, precisely because a bundled app's
101
+ // worker console is easy to miss.
102
+ if (refusal !== undefined)
103
+ console.error(refusal);
104
+ return {
105
+ async createNode(options) {
106
+ // THE LATE SIGNAL, and the one the CALLER gets: comlink carries a thrown
107
+ // error back as a rejection, so the main thread's `await createWorkerNode()`
108
+ // fails with this text instead of hanging.
109
+ if (refusal !== undefined)
110
+ throw new Error(refusal);
111
+ // The main thread's options pass through UNCHANGED; the engine, and only
112
+ // the engine, is this thread's.
113
+ const node = await createNode(createEngine ? { ...options, engine: await createEngine() } : options);
114
+ return proxy(nodeProxy(node));
115
+ },
116
+ };
117
+ }
118
+ /**
119
+ * The message for a `createEngine` that is not a factory, or `undefined` when it
120
+ * is one (`undefined` itself being the default engine, not a mistake).
121
+ *
122
+ * TWO MESSAGES, because there are two mistakes and only one of them is "you
123
+ * passed the wrong kind of thing". A THENABLE means the consumer CALLED the
124
+ * factory here (`createEngine: createRevmEngine({wasm})`, one arrow away from
125
+ * right), and telling them that value "must be a function" describes a value they
126
+ * can see is nearly correct. So the promise case names itself and shows both
127
+ * forms; the other case is a consumer holding a built engine, who needs to know
128
+ * this thread builds one PER NODE.
129
+ */
130
+ function engineSupplierRefusal(createEngine) {
131
+ if (createEngine === undefined || typeof createEngine === 'function') {
132
+ return undefined;
133
+ }
134
+ const why = 'It is called ONCE PER createNode(), because one engine instance serves one node (connect() binds it to the state of the node it is given to).';
135
+ if (typeof createEngine?.then === 'function') {
136
+ return ('webevm/worker-host: `createEngine` must be a FUNCTION that builds an engine on this thread, and it was given a PROMISE of one: the factory was CALLED here instead of being passed. ' +
137
+ 'Write `{createEngine: () => createRevmEngine({wasm})}`, not `{createEngine: createRevmEngine({wasm})}`. ' +
138
+ "Do not reach for `{createEngine: await createRevmEngine({wasm})}` either: a top-level `await` in a worker module can lose the main thread's first message, which hangs it for a different reason this package cannot fix. " +
139
+ why);
140
+ }
141
+ return (`webevm/worker-host: \`createEngine\` must be a FUNCTION that builds an engine on this thread, not an engine (received ${describe(createEngine)}). ` +
142
+ 'Pass `{createEngine: () => createRevmEngine({wasm})}`, i.e. a function that returns the engine, rather than an engine you built already. ' +
143
+ why);
144
+ }
145
+ /** What was passed, in one word a reader can match against their own code. */
146
+ function describe(value) {
147
+ if (value === null)
148
+ return 'null';
149
+ if (Array.isArray(value))
150
+ return 'an array';
151
+ const kind = typeof value;
152
+ return `${kind === 'object' ? 'an' : 'a'} ${kind}`;
153
+ }
154
+ /**
155
+ * Expose a node factory on THIS thread. This is the whole of a consumer's worker module:
156
+ *
157
+ * // my-worker.ts
158
+ * import {exposeNode} from 'webevm/worker-host';
159
+ * import {createRevmEngine} from 'webevm/revm';
160
+ * import wasm from 'revm-wasm/revm.wasm';
161
+ *
162
+ * exposeNode({createEngine: () => createRevmEngine({wasm})});
163
+ *
164
+ * The main thread then drives it with the ordinary client, unchanged:
165
+ * `createWorkerNode({worker, chainId, ...})`. Call it ONCE per thread: comlink's
166
+ * `expose()` adds a message listener, so two of them answer the same message
167
+ * twice.
168
+ *
169
+ * DO NOT `await` ANYTHING AT THIS MODULE'S TOP LEVEL BEFORE CALLING IT. A worker
170
+ * module that awaits something slower than a microtask (fetching wasm, opening a
171
+ * database) before `exposeNode()` can LOSE the main thread's first message, and
172
+ * then `createWorkerNode()` never settles. Measured on Chromium and WebKit
173
+ * (`work/notes/observations/a-top-level-await-in-a-worker-module-loses-the-first-message.md`).
174
+ * Nothing here can fix it: there is no listener to register until this call runs.
175
+ * The recipe above is safe because `() => createRevmEngine({wasm})` is
176
+ * SYNCHRONOUS at module scope: the factory defers the await into `createNode()`,
177
+ * which is one of the reasons `createEngine` is a function. If you must await
178
+ * something first, do it INSIDE `createEngine` (or inside a wrapper it calls),
179
+ * not above this line.
180
+ *
181
+ * Returns the exposed api, so `export const myApi = exposeNode(...)` is one line.
182
+ */
183
+ export function exposeNode(hostOptions = {}) {
184
+ const api = createNodeWorkerApi(hostOptions);
185
+ expose(api);
186
+ return api;
187
+ }
188
+ //# sourceMappingURL=worker-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-host.js","s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K,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC;IAC1B,OAAO,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACpD,CAAC;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,UAAU,CAAC,cAAiC,EAAE;IAC7D,MAAM,GAAG,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC;AACZ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,95 @@
1
1
  {
2
2
  "name": "webevm",
3
- "version": "0.0.0",
3
+ "version": "0.6.0",
4
+ "description": "Slim, execution-only in-browser EIP-1193 Ethereum node on @ethereumjs/vm. Transport-agnostic core + optional comlink Worker helpers + IndexedDB persistence.",
5
+ "keywords": [
6
+ "ethereum",
7
+ "eip-1193",
8
+ "ethereumjs",
9
+ "evm",
10
+ "in-browser",
11
+ "node",
12
+ "local-chain",
13
+ "viem"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "wighawag",
17
+ "homepage": "https://github.com/wighawag/webevm#readme",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/wighawag/webevm.git",
21
+ "directory": "packages/webevm"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/wighawag/webevm/issues"
25
+ },
4
26
  "publishConfig": {
5
27
  "access": "public"
28
+ },
29
+ "type": "module",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./revm": {
36
+ "types": "./dist/revm.d.ts",
37
+ "default": "./dist/revm.js"
38
+ },
39
+ "./worker-entry": {
40
+ "types": "./dist/worker-entry.d.ts",
41
+ "default": "./dist/worker-entry.js"
42
+ },
43
+ "./worker-host": {
44
+ "types": "./dist/worker-host.d.ts",
45
+ "default": "./dist/worker-host.js"
46
+ },
47
+ "./worker-client": {
48
+ "types": "./dist/worker-client.d.ts",
49
+ "default": "./dist/worker-client.js"
50
+ }
51
+ },
52
+ "files": [
53
+ "dist",
54
+ "src"
55
+ ],
56
+ "dependencies": {
57
+ "@ethereumjs/block": "^10.1.2",
58
+ "@ethereumjs/common": "^10.1.2",
59
+ "@ethereumjs/evm": "^10.1.2",
60
+ "@ethereumjs/statemanager": "^10.1.2",
61
+ "@ethereumjs/tx": "^10.1.2",
62
+ "@ethereumjs/util": "^10.1.2",
63
+ "@ethereumjs/vm": "^10.1.2",
64
+ "@noble/hashes": "^2.2.0",
65
+ "revm-wasm": "^0.3.1"
66
+ },
67
+ "peerDependencies": {
68
+ "comlink": "^4.4.2"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "comlink": {
72
+ "optional": true
73
+ }
74
+ },
75
+ "devDependencies": {
76
+ "@playwright/test": "^1.60.0",
77
+ "@types/node": "^25.2.0",
78
+ "as-soon": "^0.1.5",
79
+ "buffer": "^6.0.3",
80
+ "comlink": "^4.4.2",
81
+ "esbuild": "^0.28.0",
82
+ "playwright-browser-harness": "^0.3.0",
83
+ "prettier": "^3.8.0",
84
+ "tsx": "^4.21.0",
85
+ "typescript": "^5.3.3",
86
+ "viem": "^2.45.0"
87
+ },
88
+ "scripts": {
89
+ "format": "prettier --write .",
90
+ "format:check": "prettier --check .",
91
+ "build": "tsc -p tsconfig.build.json",
92
+ "dev": "as-soon -w src pnpm build",
93
+ "test": "playwright test"
6
94
  }
7
- }
95
+ }