@secure-exec/wasmvm 0.2.0-rc.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.
Files changed (70) hide show
  1. package/LICENSE +191 -0
  2. package/dist/browser-driver.d.ts +68 -0
  3. package/dist/browser-driver.d.ts.map +1 -0
  4. package/dist/browser-driver.js +293 -0
  5. package/dist/browser-driver.js.map +1 -0
  6. package/dist/driver.d.ts +43 -0
  7. package/dist/driver.d.ts.map +1 -0
  8. package/dist/driver.js +1420 -0
  9. package/dist/driver.js.map +1 -0
  10. package/dist/fd-table.d.ts +67 -0
  11. package/dist/fd-table.d.ts.map +1 -0
  12. package/dist/fd-table.js +171 -0
  13. package/dist/fd-table.js.map +1 -0
  14. package/dist/index.d.ts +26 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +19 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/kernel-worker.d.ts +14 -0
  19. package/dist/kernel-worker.d.ts.map +1 -0
  20. package/dist/kernel-worker.js +1205 -0
  21. package/dist/kernel-worker.js.map +1 -0
  22. package/dist/module-cache.d.ts +21 -0
  23. package/dist/module-cache.d.ts.map +1 -0
  24. package/dist/module-cache.js +51 -0
  25. package/dist/module-cache.js.map +1 -0
  26. package/dist/permission-check.d.ts +36 -0
  27. package/dist/permission-check.d.ts.map +1 -0
  28. package/dist/permission-check.js +84 -0
  29. package/dist/permission-check.js.map +1 -0
  30. package/dist/ring-buffer.d.ts +64 -0
  31. package/dist/ring-buffer.d.ts.map +1 -0
  32. package/dist/ring-buffer.js +160 -0
  33. package/dist/ring-buffer.js.map +1 -0
  34. package/dist/syscall-rpc.d.ts +95 -0
  35. package/dist/syscall-rpc.d.ts.map +1 -0
  36. package/dist/syscall-rpc.js +48 -0
  37. package/dist/syscall-rpc.js.map +1 -0
  38. package/dist/user.d.ts +58 -0
  39. package/dist/user.d.ts.map +1 -0
  40. package/dist/user.js +143 -0
  41. package/dist/user.js.map +1 -0
  42. package/dist/wasi-constants.d.ts +77 -0
  43. package/dist/wasi-constants.d.ts.map +1 -0
  44. package/dist/wasi-constants.js +122 -0
  45. package/dist/wasi-constants.js.map +1 -0
  46. package/dist/wasi-file-io.d.ts +50 -0
  47. package/dist/wasi-file-io.d.ts.map +1 -0
  48. package/dist/wasi-file-io.js +10 -0
  49. package/dist/wasi-file-io.js.map +1 -0
  50. package/dist/wasi-polyfill.d.ts +368 -0
  51. package/dist/wasi-polyfill.d.ts.map +1 -0
  52. package/dist/wasi-polyfill.js +1438 -0
  53. package/dist/wasi-polyfill.js.map +1 -0
  54. package/dist/wasi-process-io.d.ts +35 -0
  55. package/dist/wasi-process-io.d.ts.map +1 -0
  56. package/dist/wasi-process-io.js +11 -0
  57. package/dist/wasi-process-io.js.map +1 -0
  58. package/dist/wasi-types.d.ts +175 -0
  59. package/dist/wasi-types.d.ts.map +1 -0
  60. package/dist/wasi-types.js +68 -0
  61. package/dist/wasi-types.js.map +1 -0
  62. package/dist/wasm-magic.d.ts +12 -0
  63. package/dist/wasm-magic.d.ts.map +1 -0
  64. package/dist/wasm-magic.js +53 -0
  65. package/dist/wasm-magic.js.map +1 -0
  66. package/dist/worker-adapter.d.ts +32 -0
  67. package/dist/worker-adapter.d.ts.map +1 -0
  68. package/dist/worker-adapter.js +147 -0
  69. package/dist/worker-adapter.js.map +1 -0
  70. package/package.json +35 -0
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2025 Rivet Gaming, Inc.
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Browser-compatible WasmVM runtime driver.
3
+ *
4
+ * Discovers commands from a JSON manifest fetched over the network.
5
+ * WASM binaries are fetched on demand and compiled via
6
+ * WebAssembly.compileStreaming() for streaming compilation.
7
+ * Compiled modules are cached in memory for fast re-instantiation.
8
+ * Persistent caching via Cache API (or IndexedDB fallback) stores
9
+ * binaries across page loads. SHA-256 integrity is verified from the
10
+ * manifest before any cached or fetched binary is used.
11
+ */
12
+ import type { KernelRuntimeDriver as RuntimeDriver } from '@secure-exec/core';
13
+ /** Metadata for a single command in the manifest. */
14
+ export interface CommandManifestEntry {
15
+ /** Binary size in bytes. */
16
+ size: number;
17
+ /** SHA-256 hex digest of the binary. */
18
+ sha256: string;
19
+ }
20
+ /** JSON manifest mapping command names to binary metadata. */
21
+ export interface CommandManifest {
22
+ /** Manifest schema version. */
23
+ version: number;
24
+ /** Base URL for fetching command binaries (trailing slash included). */
25
+ baseUrl: string;
26
+ /** Map of command name to metadata. */
27
+ commands: Record<string, CommandManifestEntry>;
28
+ }
29
+ /** Persistent storage for WASM binary bytes across page loads. */
30
+ export interface BinaryStorage {
31
+ get(key: string): Promise<Uint8Array | null>;
32
+ put(key: string, bytes: Uint8Array): Promise<void>;
33
+ delete(key: string): Promise<void>;
34
+ }
35
+ /** Cache API-backed storage. */
36
+ export declare class CacheApiBinaryStorage implements BinaryStorage {
37
+ private _cacheName;
38
+ constructor(cacheName?: string);
39
+ get(key: string): Promise<Uint8Array | null>;
40
+ put(key: string, bytes: Uint8Array): Promise<void>;
41
+ delete(key: string): Promise<void>;
42
+ }
43
+ /** IndexedDB-backed storage (fallback when Cache API is unavailable). */
44
+ export declare class IndexedDbBinaryStorage implements BinaryStorage {
45
+ private _dbName;
46
+ private _storeName;
47
+ constructor(dbName?: string);
48
+ private _open;
49
+ get(key: string): Promise<Uint8Array | null>;
50
+ put(key: string, bytes: Uint8Array): Promise<void>;
51
+ delete(key: string): Promise<void>;
52
+ }
53
+ /** Compute SHA-256 hex digest of binary data using Web Crypto API. */
54
+ export declare function sha256Hex(data: Uint8Array): Promise<string>;
55
+ export interface BrowserWasmVmRuntimeOptions {
56
+ /** URL to the command manifest JSON. */
57
+ registryUrl: string;
58
+ /** Optional custom fetch function (for testing). */
59
+ fetch?: typeof globalThis.fetch;
60
+ /** Optional persistent binary storage (auto-detected if omitted). */
61
+ binaryStorage?: BinaryStorage | null;
62
+ }
63
+ /**
64
+ * Create a browser-compatible WasmVM RuntimeDriver that fetches commands
65
+ * from a CDN using a JSON manifest.
66
+ */
67
+ export declare function createBrowserWasmVmRuntime(options: BrowserWasmVmRuntimeOptions): RuntimeDriver;
68
+ //# sourceMappingURL=browser-driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-driver.d.ts","sourceRoot":"","sources":["../src/browser-driver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oB;IAItC,OAAO,CAAC,KAAK;IAcP,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAiB5C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBzC;AAMD,sEAAsE;AACtE,wBAAsB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAMjE;AAMD,MAAM,WAAW,2BAA2B;IAC1C,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,qEAAqE;IACrE,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;CACtC;AAMD;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,2BAA2B,GACnC,aAAa,CAEf"}
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Browser-compatible WasmVM runtime driver.
3
+ *
4
+ * Discovers commands from a JSON manifest fetched over the network.
5
+ * WASM binaries are fetched on demand and compiled via
6
+ * WebAssembly.compileStreaming() for streaming compilation.
7
+ * Compiled modules are cached in memory for fast re-instantiation.
8
+ * Persistent caching via Cache API (or IndexedDB fallback) stores
9
+ * binaries across page loads. SHA-256 integrity is verified from the
10
+ * manifest before any cached or fetched binary is used.
11
+ */
12
+ /** Cache API-backed storage. */
13
+ export class CacheApiBinaryStorage {
14
+ _cacheName;
15
+ constructor(cacheName = 'wasmvm-binaries') {
16
+ this._cacheName = cacheName;
17
+ }
18
+ async get(key) {
19
+ const cache = await caches.open(this._cacheName);
20
+ const resp = await cache.match(key);
21
+ if (!resp)
22
+ return null;
23
+ return new Uint8Array(await resp.arrayBuffer());
24
+ }
25
+ async put(key, bytes) {
26
+ const cache = await caches.open(this._cacheName);
27
+ await cache.put(key, new Response(bytes));
28
+ }
29
+ async delete(key) {
30
+ const cache = await caches.open(this._cacheName);
31
+ await cache.delete(key);
32
+ }
33
+ }
34
+ /** IndexedDB-backed storage (fallback when Cache API is unavailable). */
35
+ export class IndexedDbBinaryStorage {
36
+ _dbName;
37
+ _storeName = 'binaries';
38
+ constructor(dbName = 'wasmvm-binaries') {
39
+ this._dbName = dbName;
40
+ }
41
+ _open() {
42
+ return new Promise((resolve, reject) => {
43
+ const req = indexedDB.open(this._dbName, 1);
44
+ req.onupgradeneeded = () => {
45
+ const db = req.result;
46
+ if (!db.objectStoreNames.contains(this._storeName)) {
47
+ db.createObjectStore(this._storeName);
48
+ }
49
+ };
50
+ req.onsuccess = () => resolve(req.result);
51
+ req.onerror = () => reject(req.error);
52
+ });
53
+ }
54
+ async get(key) {
55
+ const db = await this._open();
56
+ return new Promise((resolve, reject) => {
57
+ const tx = db.transaction(this._storeName, 'readonly');
58
+ const store = tx.objectStore(this._storeName);
59
+ const req = store.get(key);
60
+ req.onsuccess = () => {
61
+ db.close();
62
+ resolve(req.result ? new Uint8Array(req.result) : null);
63
+ };
64
+ req.onerror = () => {
65
+ db.close();
66
+ reject(req.error);
67
+ };
68
+ });
69
+ }
70
+ async put(key, bytes) {
71
+ const db = await this._open();
72
+ return new Promise((resolve, reject) => {
73
+ const tx = db.transaction(this._storeName, 'readwrite');
74
+ const store = tx.objectStore(this._storeName);
75
+ const req = store.put(bytes.buffer.slice(0), key);
76
+ req.onsuccess = () => {
77
+ db.close();
78
+ resolve();
79
+ };
80
+ req.onerror = () => {
81
+ db.close();
82
+ reject(req.error);
83
+ };
84
+ });
85
+ }
86
+ async delete(key) {
87
+ const db = await this._open();
88
+ return new Promise((resolve, reject) => {
89
+ const tx = db.transaction(this._storeName, 'readwrite');
90
+ const store = tx.objectStore(this._storeName);
91
+ const req = store.delete(key);
92
+ req.onsuccess = () => {
93
+ db.close();
94
+ resolve();
95
+ };
96
+ req.onerror = () => {
97
+ db.close();
98
+ reject(req.error);
99
+ };
100
+ });
101
+ }
102
+ }
103
+ // ---------------------------------------------------------------------------
104
+ // SHA-256 utility
105
+ // ---------------------------------------------------------------------------
106
+ /** Compute SHA-256 hex digest of binary data using Web Crypto API. */
107
+ export async function sha256Hex(data) {
108
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data);
109
+ const hashArray = new Uint8Array(hashBuffer);
110
+ return Array.from(hashArray)
111
+ .map((b) => b.toString(16).padStart(2, '0'))
112
+ .join('');
113
+ }
114
+ // ---------------------------------------------------------------------------
115
+ // Driver
116
+ // ---------------------------------------------------------------------------
117
+ /**
118
+ * Create a browser-compatible WasmVM RuntimeDriver that fetches commands
119
+ * from a CDN using a JSON manifest.
120
+ */
121
+ export function createBrowserWasmVmRuntime(options) {
122
+ return new BrowserWasmVmRuntimeDriver(options);
123
+ }
124
+ class BrowserWasmVmRuntimeDriver {
125
+ name = 'wasmvm';
126
+ _commands = [];
127
+ _manifest = null;
128
+ _kernel = null;
129
+ // Module cache: command name -> compiled WebAssembly.Module
130
+ _moduleCache = new Map();
131
+ // Dedup concurrent fetches/compilations
132
+ _pending = new Map();
133
+ _registryUrl;
134
+ _fetch;
135
+ _binaryStorage;
136
+ get commands() {
137
+ return this._commands;
138
+ }
139
+ constructor(options) {
140
+ this._registryUrl = options.registryUrl;
141
+ this._fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
142
+ // Explicit null = no storage; undefined = auto-detect
143
+ this._binaryStorage =
144
+ options.binaryStorage !== undefined ? options.binaryStorage : null;
145
+ }
146
+ async init(kernel) {
147
+ this._kernel = kernel;
148
+ // Auto-detect persistent storage if not explicitly provided
149
+ if (this._binaryStorage === null && typeof caches !== 'undefined') {
150
+ this._binaryStorage = new CacheApiBinaryStorage();
151
+ }
152
+ else if (this._binaryStorage === null && typeof indexedDB !== 'undefined') {
153
+ this._binaryStorage = new IndexedDbBinaryStorage();
154
+ }
155
+ // Fetch manifest to discover available commands
156
+ const resp = await this._fetch(this._registryUrl);
157
+ if (!resp.ok) {
158
+ throw new Error(`Failed to fetch command manifest from ${this._registryUrl}: ${resp.status} ${resp.statusText}`);
159
+ }
160
+ this._manifest = (await resp.json());
161
+ this._commands = Object.keys(this._manifest.commands);
162
+ }
163
+ spawn(command, _args, _ctx) {
164
+ if (!this._kernel)
165
+ throw new Error('Browser WasmVM driver not initialized');
166
+ if (!this._manifest)
167
+ throw new Error('Manifest not loaded');
168
+ const entry = this._manifest.commands[command];
169
+ if (!entry) {
170
+ throw new Error(`command not found: ${command}`);
171
+ }
172
+ // Exit plumbing
173
+ let resolveExit;
174
+ let exitResolved = false;
175
+ const exitPromise = new Promise((resolve) => {
176
+ resolveExit = (code) => {
177
+ if (exitResolved)
178
+ return;
179
+ exitResolved = true;
180
+ resolve(code);
181
+ };
182
+ });
183
+ const proc = {
184
+ onStdout: null,
185
+ onStderr: null,
186
+ onExit: null,
187
+ writeStdin: () => {
188
+ // Browser worker stdin not wired in this story
189
+ },
190
+ closeStdin: () => { },
191
+ kill: () => {
192
+ // Terminate would go here when workers are wired
193
+ resolveExit(137);
194
+ },
195
+ wait: () => exitPromise,
196
+ };
197
+ // Fetch, compile, and eventually launch worker (async)
198
+ this._resolveModule(command).then((_module) => {
199
+ // Module compiled successfully — actual worker launch is
200
+ // environment-specific and deferred to future integration.
201
+ // For now, signal successful compilation.
202
+ resolveExit(0);
203
+ proc.onExit?.(0);
204
+ }, (err) => {
205
+ const errMsg = err instanceof Error ? err.message : String(err);
206
+ const errBytes = new TextEncoder().encode(`wasmvm: ${errMsg}\n`);
207
+ proc.onStderr?.(errBytes);
208
+ resolveExit(127);
209
+ proc.onExit?.(127);
210
+ });
211
+ return proc;
212
+ }
213
+ /**
214
+ * Preload multiple commands concurrently during idle time.
215
+ * Fetches, verifies, caches, and compiles each command.
216
+ */
217
+ async preload(commands) {
218
+ if (!this._manifest)
219
+ throw new Error('Manifest not loaded');
220
+ const valid = commands.filter((cmd) => this._manifest.commands[cmd]);
221
+ await Promise.all(valid.map((cmd) => this._resolveModule(cmd)));
222
+ }
223
+ async dispose() {
224
+ this._moduleCache.clear();
225
+ this._pending.clear();
226
+ this._manifest = null;
227
+ this._kernel = null;
228
+ this._commands = [];
229
+ }
230
+ // -------------------------------------------------------------------------
231
+ // Module resolution with concurrent-compile deduplication
232
+ // -------------------------------------------------------------------------
233
+ /**
234
+ * Resolve a command to a compiled WebAssembly.Module.
235
+ * Uses in-memory cache and deduplicates concurrent fetches.
236
+ */
237
+ async resolveModule(command) {
238
+ return this._resolveModule(command);
239
+ }
240
+ async _resolveModule(command) {
241
+ // In-memory cache hit
242
+ const cached = this._moduleCache.get(command);
243
+ if (cached)
244
+ return cached;
245
+ // Dedup concurrent fetches
246
+ const inflight = this._pending.get(command);
247
+ if (inflight)
248
+ return inflight;
249
+ const promise = this._fetchAndCompile(command);
250
+ this._pending.set(command, promise);
251
+ try {
252
+ const module = await promise;
253
+ this._moduleCache.set(command, module);
254
+ return module;
255
+ }
256
+ finally {
257
+ this._pending.delete(command);
258
+ }
259
+ }
260
+ async _fetchAndCompile(command) {
261
+ if (!this._manifest)
262
+ throw new Error('Manifest not loaded');
263
+ const entry = this._manifest.commands[command];
264
+ const url = this._manifest.baseUrl + command;
265
+ // Check persistent cache
266
+ if (this._binaryStorage) {
267
+ const cachedBytes = await this._binaryStorage.get(command);
268
+ if (cachedBytes) {
269
+ const hash = await sha256Hex(cachedBytes);
270
+ if (hash === entry.sha256) {
271
+ return WebAssembly.compile(cachedBytes);
272
+ }
273
+ // Hash mismatch — evict stale entry and re-fetch
274
+ await this._binaryStorage.delete(command);
275
+ }
276
+ }
277
+ // Fetch from network
278
+ const resp = await this._fetch(url);
279
+ const bytes = new Uint8Array(await resp.arrayBuffer());
280
+ // SHA-256 integrity check
281
+ const hash = await sha256Hex(bytes);
282
+ if (hash !== entry.sha256) {
283
+ throw new Error(`SHA-256 mismatch for ${command}: expected ${entry.sha256}, got ${hash}`);
284
+ }
285
+ // Store in persistent cache
286
+ if (this._binaryStorage) {
287
+ await this._binaryStorage.put(command, bytes);
288
+ }
289
+ // Compile module
290
+ return WebAssembly.compile(bytes);
291
+ }
292
+ }
293
+ //# sourceMappingURL=browser-driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-driver.js","sourceRoot":"","sources":["../src/browser-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA0CH,gCAAgC;AAChC,MAAM,OAAO,qBAAqB;IACxB,UAAU,CAAS;IAE3B,YAAY,SAAS,GAAG,iBAAiB;QACvC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAiB;QACtC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,QAAQ,CAAC,KAA4B,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF;AAED,yEAAyE;AACzE,MAAM,OAAO,sBAAsB;IACzB,OAAO,CAAS;IAChB,UAAU,GAAG,UAAU,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,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;QAED,iBAAiB;QACjB,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WasmVM runtime driver for kernel integration.
3
+ *
4
+ * Discovers WASM command binaries from filesystem directories (commandDirs),
5
+ * validates them by WASM magic bytes, and loads them on demand. Each spawn()
6
+ * creates a Worker thread that loads the per-command binary and communicates
7
+ * with the main thread via SharedArrayBuffer-based RPC for synchronous
8
+ * WASI syscalls.
9
+ *
10
+ * proc_spawn from brush-shell routes through KernelInterface.spawn()
11
+ * so pipeline stages can dispatch to any runtime (WasmVM, Node, Python).
12
+ */
13
+ import type { KernelRuntimeDriver as RuntimeDriver } from '@secure-exec/core';
14
+ import { type PermissionTier } from './syscall-rpc.js';
15
+ /**
16
+ * All commands available in the WasmVM runtime.
17
+ * Used as fallback when no commandDirs are configured (legacy mode).
18
+ * @deprecated Use commandDirs option instead — commands are discovered from filesystem.
19
+ */
20
+ export declare const WASMVM_COMMANDS: readonly string[];
21
+ /**
22
+ * Default permission tiers for known first-party commands.
23
+ * User-provided permissions override these defaults.
24
+ */
25
+ export declare const DEFAULT_FIRST_PARTY_TIERS: Readonly<Record<string, PermissionTier>>;
26
+ export interface WasmVmRuntimeOptions {
27
+ /**
28
+ * Path to a compiled WASM binary (legacy single-binary mode).
29
+ * @deprecated Use commandDirs instead. Triggers legacy mode.
30
+ */
31
+ wasmBinaryPath?: string;
32
+ /** Directories to scan for WASM command binaries, searched in order (PATH semantics). */
33
+ commandDirs?: string[];
34
+ /** Per-command permission tiers. Keys are command names, '*' sets the default. */
35
+ permissions?: Record<string, PermissionTier>;
36
+ }
37
+ /**
38
+ * Create a WasmVM RuntimeDriver that can be mounted into the kernel.
39
+ */
40
+ export declare function createWasmVmRuntime(options?: WasmVmRuntimeOptions): RuntimeDriver;
41
+ /** Map errors to WASI errno codes. Prefers structured .code, falls back to string matching. */
42
+ export declare function mapErrorToErrno(err: unknown): number;
43
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,mBAAmB,IAAI,aAAa,EAIrC,MAAM,mBAAmB,CAAC;AAW3B,OAAO,EAcL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AA4F1B;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EA4DnC,CAAC;AAGX;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CA0F9E,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,aAAa,CAEjF;AAqtCD,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAapD"}