@hazae41/bobine 0.0.23 → 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 +5 -197
- package/out/libs/packed/mod.d.ts +5 -5
- package/out/libs/packed/mod.js +42 -42
- package/out/libs/sql/mod.d.ts +2 -2
- package/out/libs/sql/mod.js +2 -2
- package/out/mod.d.ts +0 -2
- package/out/mod.js +0 -24
- package/out/mods/bobine/errors/mod.d.ts +8 -0
- package/out/mods/bobine/errors/mod.js +12 -0
- package/out/mods/bobine/mod.d.ts +3 -0
- package/out/mods/bobine/mod.js +3 -0
- package/out/mods/bobine/runner/mod.d.ts +12 -0
- package/out/mods/bobine/runner/mod.js +447 -0
- package/out/mods/bobine/worker/bin.d.ts +12 -0
- package/out/mods/bobine/worker/bin.js +67 -0
- package/out/mods/bobine/worker/mod.d.ts +10 -0
- package/out/mods/bobine/worker/mod.js +105 -0
- package/out/mods/mod.d.ts +1 -1
- package/out/mods/mod.js +1 -1
- package/package.json +11 -17
- package/out/libs/database/mod.d.ts +0 -1
- package/out/libs/database/mod.js +0 -1
- package/out/mods/config/mod.d.ts +0 -12
- package/out/mods/config/mod.js +0 -1
- package/out/mods/helper/bin.d.ts +0 -1
- package/out/mods/helper/bin.js +0 -78
- package/out/mods/server/bin.d.ts +0 -1
- package/out/mods/server/bin.js +0 -72
- package/out/mods/server/mod.d.ts +0 -9
- package/out/mods/server/mod.js +0 -314
- package/out/mods/worker/bin.d.ts +0 -1
- package/out/mods/worker/bin.js +0 -464
package/out/mods/worker/bin.js
DELETED
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
/// <reference lib="webworker" />
|
|
2
|
-
import { meter } from "../../libs/metering/mod.js";
|
|
3
|
-
import { Packed } from "../../libs/packed/mod.js";
|
|
4
|
-
import { Readable, Writable } from "@hazae41/binary";
|
|
5
|
-
import { RpcErr, RpcError, RpcMethodNotFoundError, RpcOk } from "@hazae41/jsonrpc";
|
|
6
|
-
import * as Wasm from "@hazae41/wasm";
|
|
7
|
-
import { Buffer } from "node:buffer";
|
|
8
|
-
import { existsSync, readFileSync, symlinkSync, writeFileSync } from "node:fs";
|
|
9
|
-
import process from "node:process";
|
|
10
|
-
const config = await fetch(self.name).then(res => res.json());
|
|
11
|
-
const helper = new Worker(import.meta.resolve("../helper/bin.js"), { name: self.name, type: "module" });
|
|
12
|
-
function run(module, method, params, mode, maxsparks) {
|
|
13
|
-
let sparks = 0n;
|
|
14
|
-
const exports = {};
|
|
15
|
-
const logs = new Array();
|
|
16
|
-
const caches = new Map();
|
|
17
|
-
const reads = new Array();
|
|
18
|
-
const writes = new Array();
|
|
19
|
-
const pack_encode = (value) => {
|
|
20
|
-
return Writable.writeToBytesOrThrow(new Packed(value));
|
|
21
|
-
};
|
|
22
|
-
const pack_decode = (bytes) => {
|
|
23
|
-
return Readable.readFromBytesOrThrow(Packed, bytes);
|
|
24
|
-
};
|
|
25
|
-
const sparks_consume = (amount) => {
|
|
26
|
-
sparks += amount;
|
|
27
|
-
if (process.env.NODE_ENV !== "production")
|
|
28
|
-
return;
|
|
29
|
-
if (maxsparks == null)
|
|
30
|
-
return;
|
|
31
|
-
if (sparks < maxsparks)
|
|
32
|
-
return;
|
|
33
|
-
throw new Error("Out of sparks");
|
|
34
|
-
};
|
|
35
|
-
const sha256_digest = (payload) => {
|
|
36
|
-
sparks_consume(BigInt(payload.length) * 256n);
|
|
37
|
-
const result = new Int32Array(new SharedArrayBuffer(4 + 32));
|
|
38
|
-
helper.postMessage({ method: "sha256_digest", params: [payload], result });
|
|
39
|
-
if (Atomics.wait(result, 0, 0) !== "ok")
|
|
40
|
-
throw new Error("Failed to wait");
|
|
41
|
-
if (result[0] === 2)
|
|
42
|
-
throw new Error("Internal error");
|
|
43
|
-
return new Uint8Array(result.buffer, 4, 32).slice();
|
|
44
|
-
};
|
|
45
|
-
const ed25519_verify = (pubkey, signature, payload) => {
|
|
46
|
-
sparks_consume(BigInt(payload.length) * 256n);
|
|
47
|
-
const result = new Int32Array(new SharedArrayBuffer(4 + 4));
|
|
48
|
-
helper.postMessage({ method: "ed25519_verify", params: [pubkey, signature, payload], result });
|
|
49
|
-
if (Atomics.wait(result, 0, 0) !== "ok")
|
|
50
|
-
throw new Error("Failed to wait");
|
|
51
|
-
if (result[0] === 2)
|
|
52
|
-
throw new Error("Internal error");
|
|
53
|
-
return result[1] === 1;
|
|
54
|
-
};
|
|
55
|
-
const ed25519_sign = (subpayload) => {
|
|
56
|
-
sparks_consume(BigInt(subpayload.length) * 256n);
|
|
57
|
-
const payload = pack_encode([Uint8Array.fromHex(module), subpayload]);
|
|
58
|
-
const result = new Int32Array(new SharedArrayBuffer(4 + 64));
|
|
59
|
-
helper.postMessage({ method: "ed25519_sign", params: [payload], result });
|
|
60
|
-
if (Atomics.wait(result, 0, 0) !== "ok")
|
|
61
|
-
throw new Error("Failed to wait");
|
|
62
|
-
if (result[0] === 2)
|
|
63
|
-
throw new Error("Internal error");
|
|
64
|
-
return new Uint8Array(result.buffer, 4, 64).slice();
|
|
65
|
-
};
|
|
66
|
-
const load = (module) => {
|
|
67
|
-
const current = {};
|
|
68
|
-
caches.set(module, new Map());
|
|
69
|
-
const imports = {};
|
|
70
|
-
imports["env"] = {
|
|
71
|
-
mode: mode,
|
|
72
|
-
abort: (...args) => {
|
|
73
|
-
return;
|
|
74
|
-
},
|
|
75
|
-
uuid: () => {
|
|
76
|
-
return "17fa1cb5-c5af-4cfd-9bea-1a36590b890d";
|
|
77
|
-
},
|
|
78
|
-
panic: (message) => {
|
|
79
|
-
throw new Error(message);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
imports["sparks"] = {
|
|
83
|
-
remaining: () => {
|
|
84
|
-
return sparks;
|
|
85
|
-
},
|
|
86
|
-
consume: (amount) => {
|
|
87
|
-
sparks_consume(BigInt(amount >>> 0));
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
imports["console"] = {
|
|
91
|
-
log: (text) => {
|
|
92
|
-
logs.push(text);
|
|
93
|
-
console.log(text);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
imports["blobs"] = {
|
|
98
|
-
save: (offset, length) => {
|
|
99
|
-
const { memory } = current.instance.exports;
|
|
100
|
-
const view = new Uint8Array(memory.buffer, offset >>> 0, length >>> 0);
|
|
101
|
-
return view.slice();
|
|
102
|
-
},
|
|
103
|
-
load: (blob, offset) => {
|
|
104
|
-
const { memory } = current.instance.exports;
|
|
105
|
-
const view = new Uint8Array(memory.buffer, offset >>> 0, blob.length);
|
|
106
|
-
view.set(blob);
|
|
107
|
-
},
|
|
108
|
-
length: (blob) => {
|
|
109
|
-
return blob.length;
|
|
110
|
-
},
|
|
111
|
-
concat: (left, right) => {
|
|
112
|
-
const concat = new Uint8Array(left.length + right.length);
|
|
113
|
-
concat.set(left, 0);
|
|
114
|
-
concat.set(right, left.length);
|
|
115
|
-
return concat;
|
|
116
|
-
},
|
|
117
|
-
equals: (left, right) => {
|
|
118
|
-
return !Buffer.compare(left, right);
|
|
119
|
-
},
|
|
120
|
-
includes: (haystack, needle) => {
|
|
121
|
-
return haystack.toHex().includes(needle.toHex());
|
|
122
|
-
},
|
|
123
|
-
slice: (blob, start, end) => {
|
|
124
|
-
return blob.slice(start >>> 0, end >>> 0);
|
|
125
|
-
},
|
|
126
|
-
from_base16: (text) => {
|
|
127
|
-
return Uint8Array.fromHex(text);
|
|
128
|
-
},
|
|
129
|
-
to_base16: (blob) => {
|
|
130
|
-
return blob.toHex();
|
|
131
|
-
},
|
|
132
|
-
from_base64: (text) => {
|
|
133
|
-
return Uint8Array.fromBase64(text);
|
|
134
|
-
},
|
|
135
|
-
to_base64: (blob) => {
|
|
136
|
-
return blob.toBase64();
|
|
137
|
-
},
|
|
138
|
-
encode: (value) => {
|
|
139
|
-
return pack_encode(value);
|
|
140
|
-
},
|
|
141
|
-
decode: (blob) => {
|
|
142
|
-
return pack_decode(blob);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
imports["texts"] = {
|
|
146
|
-
length: (text) => {
|
|
147
|
-
return new TextEncoder().encode(text).length;
|
|
148
|
-
},
|
|
149
|
-
concat: (left, right) => {
|
|
150
|
-
return left + right;
|
|
151
|
-
},
|
|
152
|
-
equals: (left, right) => {
|
|
153
|
-
return left === right;
|
|
154
|
-
},
|
|
155
|
-
includes: (haystack, needle) => {
|
|
156
|
-
return haystack.includes(needle);
|
|
157
|
-
},
|
|
158
|
-
slice: (text, start, end) => {
|
|
159
|
-
return text.slice(start >>> 0, end >>> 0);
|
|
160
|
-
},
|
|
161
|
-
from_utf8: (bytes) => {
|
|
162
|
-
return new TextDecoder().decode(bytes);
|
|
163
|
-
},
|
|
164
|
-
to_utf8: (text) => {
|
|
165
|
-
return new TextEncoder().encode(text);
|
|
166
|
-
},
|
|
167
|
-
to_uppercase: (text) => {
|
|
168
|
-
return text.toUpperCase();
|
|
169
|
-
},
|
|
170
|
-
to_lowercase: (text) => {
|
|
171
|
-
return text.toLowerCase();
|
|
172
|
-
},
|
|
173
|
-
trim: (text) => {
|
|
174
|
-
return text.trim();
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
imports["packs"] = {
|
|
178
|
-
create: (...values) => {
|
|
179
|
-
return values;
|
|
180
|
-
},
|
|
181
|
-
concat: (left, right) => {
|
|
182
|
-
return [...left, ...right];
|
|
183
|
-
},
|
|
184
|
-
length: (pack) => {
|
|
185
|
-
return pack.length;
|
|
186
|
-
},
|
|
187
|
-
get(pack, index) {
|
|
188
|
-
const value = pack[index >>> 0];
|
|
189
|
-
if (value === undefined)
|
|
190
|
-
throw new Error("Not found");
|
|
191
|
-
return value;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
imports["bigints"] = {
|
|
195
|
-
identity: (value) => {
|
|
196
|
-
return value;
|
|
197
|
-
},
|
|
198
|
-
zero: () => {
|
|
199
|
-
return 0n;
|
|
200
|
-
},
|
|
201
|
-
one: () => {
|
|
202
|
-
return 1n;
|
|
203
|
-
},
|
|
204
|
-
two: () => {
|
|
205
|
-
return 2n;
|
|
206
|
-
},
|
|
207
|
-
three: () => {
|
|
208
|
-
return 3n;
|
|
209
|
-
},
|
|
210
|
-
four: () => {
|
|
211
|
-
return 4n;
|
|
212
|
-
},
|
|
213
|
-
five: () => {
|
|
214
|
-
return 5n;
|
|
215
|
-
},
|
|
216
|
-
six: () => {
|
|
217
|
-
return 6n;
|
|
218
|
-
},
|
|
219
|
-
seven: () => {
|
|
220
|
-
return 7n;
|
|
221
|
-
},
|
|
222
|
-
eight: () => {
|
|
223
|
-
return 8n;
|
|
224
|
-
},
|
|
225
|
-
nine: () => {
|
|
226
|
-
return 9n;
|
|
227
|
-
},
|
|
228
|
-
ten: () => {
|
|
229
|
-
return 10n;
|
|
230
|
-
},
|
|
231
|
-
inc: (value) => {
|
|
232
|
-
return value + 1n;
|
|
233
|
-
},
|
|
234
|
-
dec: (value) => {
|
|
235
|
-
return value - 1n;
|
|
236
|
-
},
|
|
237
|
-
neg: (value) => {
|
|
238
|
-
return -value;
|
|
239
|
-
},
|
|
240
|
-
add: (left, right) => {
|
|
241
|
-
return left + right;
|
|
242
|
-
},
|
|
243
|
-
sub: (left, right) => {
|
|
244
|
-
return left - right;
|
|
245
|
-
},
|
|
246
|
-
mul: (left, right) => {
|
|
247
|
-
return left * right;
|
|
248
|
-
},
|
|
249
|
-
div: (left, right) => {
|
|
250
|
-
return left / right;
|
|
251
|
-
},
|
|
252
|
-
pow: (left, right) => {
|
|
253
|
-
return left ** right;
|
|
254
|
-
},
|
|
255
|
-
mod: (left, right) => {
|
|
256
|
-
return left % right;
|
|
257
|
-
},
|
|
258
|
-
lt: (left, right) => {
|
|
259
|
-
return left < right;
|
|
260
|
-
},
|
|
261
|
-
lte: (left, right) => {
|
|
262
|
-
return left <= right;
|
|
263
|
-
},
|
|
264
|
-
gt: (left, right) => {
|
|
265
|
-
return left > right;
|
|
266
|
-
},
|
|
267
|
-
gte: (left, right) => {
|
|
268
|
-
return left >= right;
|
|
269
|
-
},
|
|
270
|
-
eq: (left, right) => {
|
|
271
|
-
return left === right;
|
|
272
|
-
},
|
|
273
|
-
neq: (left, right) => {
|
|
274
|
-
return left !== right;
|
|
275
|
-
},
|
|
276
|
-
min: (left, right) => {
|
|
277
|
-
return left < right ? left : right;
|
|
278
|
-
},
|
|
279
|
-
max: (left, right) => {
|
|
280
|
-
return left > right ? left : right;
|
|
281
|
-
},
|
|
282
|
-
from_base16: (text) => {
|
|
283
|
-
return BigInt("0x" + text);
|
|
284
|
-
},
|
|
285
|
-
to_base16: (bigint) => {
|
|
286
|
-
return bigint.toString(16);
|
|
287
|
-
},
|
|
288
|
-
from_base10: (text) => {
|
|
289
|
-
return BigInt(text);
|
|
290
|
-
},
|
|
291
|
-
to_base10: (bigint) => {
|
|
292
|
-
return bigint.toString();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
imports["modules"] = {
|
|
296
|
-
self: () => {
|
|
297
|
-
return module;
|
|
298
|
-
},
|
|
299
|
-
load: (module) => {
|
|
300
|
-
return readFileSync(`${config.scripts.path}/${module}.wasm`);
|
|
301
|
-
},
|
|
302
|
-
call: (module, method, params) => {
|
|
303
|
-
if (exports[module] == null)
|
|
304
|
-
load(module);
|
|
305
|
-
if (typeof exports[module][method] !== "function")
|
|
306
|
-
throw new Error("Not found");
|
|
307
|
-
return [exports[module][method](...params)];
|
|
308
|
-
},
|
|
309
|
-
create: (code, salt) => {
|
|
310
|
-
const pack = pack_encode([code, salt]);
|
|
311
|
-
const digestOfCodeAsBytes = sha256_digest(code);
|
|
312
|
-
const digestOfPackAsBytes = sha256_digest(pack);
|
|
313
|
-
const digestOfCodeAsHex = digestOfCodeAsBytes.toHex();
|
|
314
|
-
const digestOfPackAsHex = digestOfPackAsBytes.toHex();
|
|
315
|
-
if (!existsSync(`${config.scripts.path}/${digestOfCodeAsHex}.wasm`))
|
|
316
|
-
writeFileSync(`${config.scripts.path}/${digestOfCodeAsHex}.wasm`, code);
|
|
317
|
-
if (!existsSync(`${config.scripts.path}/${digestOfPackAsHex}.wasm`))
|
|
318
|
-
symlinkSync(`./${digestOfCodeAsHex}.wasm`, `${config.scripts.path}/${digestOfPackAsHex}.wasm`, "file");
|
|
319
|
-
return digestOfPackAsHex;
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
imports["storage"] = {
|
|
323
|
-
set: (key, fresh) => {
|
|
324
|
-
const cache = caches.get(module);
|
|
325
|
-
cache.set(key, fresh);
|
|
326
|
-
const keyAsBytes = pack_encode(key);
|
|
327
|
-
const valueAsBytes = pack_encode(fresh);
|
|
328
|
-
writes.push([module, keyAsBytes, valueAsBytes]);
|
|
329
|
-
return;
|
|
330
|
-
},
|
|
331
|
-
get: (key) => {
|
|
332
|
-
const cache = caches.get(module);
|
|
333
|
-
const stale = cache.get(key);
|
|
334
|
-
if (stale != null)
|
|
335
|
-
return [stale];
|
|
336
|
-
const keyAsBytes = pack_encode(key);
|
|
337
|
-
const result = new Int32Array(new SharedArrayBuffer(4 + 4 + 4, { maxByteLength: ((4 + 4 + 4) + (1024 * 1024)) }));
|
|
338
|
-
helper.postMessage({ method: "storage_get", params: [module, keyAsBytes], result });
|
|
339
|
-
if (Atomics.wait(result, 0, 0) !== "ok")
|
|
340
|
-
throw new Error("Failed to wait");
|
|
341
|
-
if (result[0] === 2)
|
|
342
|
-
throw new Error("Internal error");
|
|
343
|
-
if (result[1] === 2)
|
|
344
|
-
return null;
|
|
345
|
-
const valueAsBytes = new Uint8Array(result.buffer, 4 + 4 + 4, result[2]).slice();
|
|
346
|
-
reads.push([module, keyAsBytes, valueAsBytes]);
|
|
347
|
-
const fresh = pack_decode(valueAsBytes);
|
|
348
|
-
cache.set(key, fresh);
|
|
349
|
-
return [fresh];
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
imports["symbols"] = {
|
|
353
|
-
create: () => {
|
|
354
|
-
return Symbol();
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
const refs = new Array();
|
|
358
|
-
const ptrs = new Map();
|
|
359
|
-
imports["refs"] = {
|
|
360
|
-
numerize: (ref) => {
|
|
361
|
-
const stale = ptrs.get(ref);
|
|
362
|
-
if (stale != null)
|
|
363
|
-
return stale;
|
|
364
|
-
const fresh = refs.push(ref) - 1;
|
|
365
|
-
ptrs.set(ref, fresh);
|
|
366
|
-
return fresh;
|
|
367
|
-
},
|
|
368
|
-
denumerize: (ptr) => {
|
|
369
|
-
const ref = refs.at(ptr >>> 0);
|
|
370
|
-
if (ref == null)
|
|
371
|
-
throw new Error("Not found");
|
|
372
|
-
return ref;
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
imports["sha256"] = {
|
|
376
|
-
digest: (payload) => {
|
|
377
|
-
return sha256_digest(payload);
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
imports["ed25519"] = {
|
|
381
|
-
verify: (pubkey, signature, payload) => {
|
|
382
|
-
return ed25519_verify(pubkey, signature, payload);
|
|
383
|
-
},
|
|
384
|
-
sign: (payload) => {
|
|
385
|
-
return ed25519_sign(payload);
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
let meteredCodeAsBytes;
|
|
389
|
-
if (!existsSync(`${config.scripts.path}/${module}.metered.wasm`)) {
|
|
390
|
-
const codeAsBytes = readFileSync(`${config.scripts.path}/${module}.wasm`);
|
|
391
|
-
const codeAsWasm = Readable.readFromBytesOrThrow(Wasm.Module, codeAsBytes);
|
|
392
|
-
meter(codeAsWasm, "sparks", "consume");
|
|
393
|
-
meteredCodeAsBytes = Writable.writeToBytesOrThrow(codeAsWasm);
|
|
394
|
-
writeFileSync(`${config.scripts.path}/${module}.metered.wasm`, meteredCodeAsBytes);
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
meteredCodeAsBytes = readFileSync(`${config.scripts.path}/${module}.metered.wasm`);
|
|
398
|
-
}
|
|
399
|
-
const meteredCodeAsModule = new WebAssembly.Module(meteredCodeAsBytes);
|
|
400
|
-
for (const descriptor of WebAssembly.Module.imports(meteredCodeAsModule)) {
|
|
401
|
-
if (imports[descriptor.module] != null) {
|
|
402
|
-
// NOOP
|
|
403
|
-
continue;
|
|
404
|
-
}
|
|
405
|
-
if (exports[descriptor.module] != null) {
|
|
406
|
-
imports[descriptor.module] = exports[descriptor.module];
|
|
407
|
-
continue;
|
|
408
|
-
}
|
|
409
|
-
const { instance } = load(descriptor.module);
|
|
410
|
-
imports[descriptor.module] = instance.exports;
|
|
411
|
-
continue;
|
|
412
|
-
}
|
|
413
|
-
const meteredCodeAsInstance = new WebAssembly.Instance(meteredCodeAsModule, imports);
|
|
414
|
-
current.instance = meteredCodeAsInstance;
|
|
415
|
-
current.module = meteredCodeAsModule;
|
|
416
|
-
exports[module] = meteredCodeAsInstance.exports;
|
|
417
|
-
return current;
|
|
418
|
-
};
|
|
419
|
-
const { instance } = load(module);
|
|
420
|
-
if (typeof instance.exports[method] !== "function")
|
|
421
|
-
throw new Error("Not found");
|
|
422
|
-
const args = pack_decode(params);
|
|
423
|
-
if (!Array.isArray(args))
|
|
424
|
-
throw new Error("Params is not an array");
|
|
425
|
-
const returned = instance.exports[method](...args);
|
|
426
|
-
if (mode !== 1)
|
|
427
|
-
return pack_encode([logs, reads, writes, returned, sparks]);
|
|
428
|
-
if (writes.length) {
|
|
429
|
-
const result = new Int32Array(new SharedArrayBuffer(4 + 4));
|
|
430
|
-
helper.postMessage({ method: "storage_set", params: [module, method, params, writes], result });
|
|
431
|
-
if (Atomics.wait(result, 0, 0) !== "ok")
|
|
432
|
-
throw new Error("Failed to wait");
|
|
433
|
-
if (result[0] === 2)
|
|
434
|
-
throw new Error("Internal error");
|
|
435
|
-
// NOOP
|
|
436
|
-
}
|
|
437
|
-
return pack_encode([logs, reads, writes, returned, sparks]);
|
|
438
|
-
}
|
|
439
|
-
self.addEventListener("message", (event) => {
|
|
440
|
-
try {
|
|
441
|
-
const request = event.data;
|
|
442
|
-
if (request.method === "execute") {
|
|
443
|
-
const [module, method, params, maxsparks] = request.params;
|
|
444
|
-
const proof = run(module, method, params, 1, maxsparks);
|
|
445
|
-
self.postMessage(new RpcOk(request.id, proof));
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
if (request.method === "simulate") {
|
|
449
|
-
const [module, method, params, maxsparks] = request.params;
|
|
450
|
-
const proof = run(module, method, params, 2, maxsparks);
|
|
451
|
-
self.postMessage(new RpcOk(request.id, proof));
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
if (request.method === "verify") {
|
|
455
|
-
// TODO
|
|
456
|
-
}
|
|
457
|
-
throw new RpcMethodNotFoundError();
|
|
458
|
-
}
|
|
459
|
-
catch (cause) {
|
|
460
|
-
const request = event.data;
|
|
461
|
-
console.error(cause);
|
|
462
|
-
self.postMessage(new RpcErr(request.id, RpcError.rewrap(cause)));
|
|
463
|
-
}
|
|
464
|
-
});
|