@hazae41/bobine 0.0.18 → 0.0.19
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/out/mods/helper/bin.js +1 -1
- package/out/mods/server/mod.js +14 -13
- package/out/mods/worker/bin.js +56 -30
- package/package.json +1 -1
package/out/mods/helper/bin.js
CHANGED
|
@@ -50,7 +50,7 @@ self.addEventListener("message", async (event) => {
|
|
|
50
50
|
}
|
|
51
51
|
if (request.method === "ed25519_verify") {
|
|
52
52
|
const [pubkeyAsBytes, signatureAsBytes, payloadAsBytes] = request.params;
|
|
53
|
-
const pubkeyAsKey = await crypto.subtle.importKey("
|
|
53
|
+
const pubkeyAsKey = await crypto.subtle.importKey("spki", pubkeyAsBytes, "Ed25519", true, ["verify"]);
|
|
54
54
|
const verified = await crypto.subtle.verify("Ed25519", pubkeyAsKey, signatureAsBytes, payloadAsBytes);
|
|
55
55
|
request.result[0] = 1;
|
|
56
56
|
request.result[1] = verified ? 1 : 0;
|
package/out/mods/server/mod.js
CHANGED
|
@@ -51,7 +51,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
51
51
|
var e = new Error(message);
|
|
52
52
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
53
53
|
});
|
|
54
|
-
import { Writable } from "@hazae41/binary";
|
|
54
|
+
import { Readable, Writable } from "@hazae41/binary";
|
|
55
55
|
import { RpcRequest, RpcResponse } from "@hazae41/jsonrpc";
|
|
56
56
|
import { Mutex } from "@hazae41/mutex";
|
|
57
57
|
import { connect } from "@tursodatabase/database";
|
|
@@ -92,7 +92,7 @@ export async function serve(config) {
|
|
|
92
92
|
|
|
93
93
|
module TEXT NOT NULL,
|
|
94
94
|
|
|
95
|
-
key
|
|
95
|
+
key BLOB NOT NULL,
|
|
96
96
|
|
|
97
97
|
value BLOB NOT NULL
|
|
98
98
|
);`);
|
|
@@ -117,12 +117,12 @@ export async function serve(config) {
|
|
|
117
117
|
if (match = new URLPattern("/api/create", request.url).exec(request.url)) {
|
|
118
118
|
if (request.method === "POST") {
|
|
119
119
|
const form = await request.formData();
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
120
|
+
const codeAsEntry = form.get("code");
|
|
121
|
+
if (codeAsEntry == null)
|
|
122
122
|
return Response.json(null, { status: 400 });
|
|
123
|
-
if (typeof
|
|
123
|
+
if (typeof codeAsEntry === "string")
|
|
124
124
|
return Response.json(null, { status: 400 });
|
|
125
|
-
const
|
|
125
|
+
const codeAsBytes = await codeAsEntry.bytes();
|
|
126
126
|
const saltAsEntry = form.get("salt");
|
|
127
127
|
if (saltAsEntry == null)
|
|
128
128
|
return Response.json(null, { status: 400 });
|
|
@@ -142,17 +142,18 @@ export async function serve(config) {
|
|
|
142
142
|
return Response.json(null, { status: 402 });
|
|
143
143
|
setOfEffortsAsHex.add(effortAsHex);
|
|
144
144
|
const sparksAsBigInt = (2n ** 256n) / BigInt("0x" + new Uint8Array(await crypto.subtle.digest("SHA-256", effortAsBytes)).toHex());
|
|
145
|
-
if (sparksAsBigInt < (
|
|
145
|
+
if (sparksAsBigInt < (codeAsBytes.length + saltAsBytes.length))
|
|
146
146
|
return Response.json(null, { status: 402 });
|
|
147
|
-
const
|
|
148
|
-
const
|
|
147
|
+
const saltAsValue = Readable.readFromBytesOrThrow(Packed, saltAsBytes);
|
|
148
|
+
const packAsBytes = Writable.writeToBytesOrThrow(new Packed([codeAsBytes, saltAsValue]));
|
|
149
|
+
const digestOfCodeAsBytes = new Uint8Array(await crypto.subtle.digest("SHA-256", codeAsBytes));
|
|
149
150
|
const digestOfPackAsBytes = new Uint8Array(await crypto.subtle.digest("SHA-256", packAsBytes));
|
|
150
|
-
const
|
|
151
|
+
const digestOfCodeAsHex = digestOfCodeAsBytes.toHex();
|
|
151
152
|
const digestOfPackAsHex = digestOfPackAsBytes.toHex();
|
|
152
|
-
if (!existsSync(`${config.scripts.path}/${
|
|
153
|
-
writeFileSync(`${config.scripts.path}/${
|
|
153
|
+
if (!existsSync(`${config.scripts.path}/${digestOfCodeAsHex}.wasm`))
|
|
154
|
+
writeFileSync(`${config.scripts.path}/${digestOfCodeAsHex}.wasm`, codeAsBytes);
|
|
154
155
|
if (!existsSync(`${config.scripts.path}/${digestOfPackAsHex}.wasm`))
|
|
155
|
-
symlinkSync(`./${
|
|
156
|
+
symlinkSync(`./${digestOfCodeAsHex}.wasm`, `${config.scripts.path}/${digestOfPackAsHex}.wasm`);
|
|
156
157
|
return Response.json(digestOfPackAsHex);
|
|
157
158
|
}
|
|
158
159
|
return Response.json(null, { status: 405, headers: { "Allow": "POST" } });
|
package/out/mods/worker/bin.js
CHANGED
|
@@ -225,6 +225,9 @@ function run(module, method, params, mode, maxsparks) {
|
|
|
225
225
|
dec: (value) => {
|
|
226
226
|
return value - 1n;
|
|
227
227
|
},
|
|
228
|
+
neg: (value) => {
|
|
229
|
+
return -value;
|
|
230
|
+
},
|
|
228
231
|
add: (left, right) => {
|
|
229
232
|
return left + right;
|
|
230
233
|
},
|
|
@@ -240,6 +243,27 @@ function run(module, method, params, mode, maxsparks) {
|
|
|
240
243
|
pow: (left, right) => {
|
|
241
244
|
return left ** right;
|
|
242
245
|
},
|
|
246
|
+
mod: (left, right) => {
|
|
247
|
+
return left % right;
|
|
248
|
+
},
|
|
249
|
+
lt: (left, right) => {
|
|
250
|
+
return left < right;
|
|
251
|
+
},
|
|
252
|
+
lte: (left, right) => {
|
|
253
|
+
return left <= right;
|
|
254
|
+
},
|
|
255
|
+
gt: (left, right) => {
|
|
256
|
+
return left > right;
|
|
257
|
+
},
|
|
258
|
+
gte: (left, right) => {
|
|
259
|
+
return left >= right;
|
|
260
|
+
},
|
|
261
|
+
eq: (left, right) => {
|
|
262
|
+
return left === right;
|
|
263
|
+
},
|
|
264
|
+
neq: (left, right) => {
|
|
265
|
+
return left !== right;
|
|
266
|
+
},
|
|
243
267
|
from_base16: (text) => {
|
|
244
268
|
return BigInt("0x" + text);
|
|
245
269
|
},
|
|
@@ -265,18 +289,18 @@ function run(module, method, params, mode, maxsparks) {
|
|
|
265
289
|
load(module);
|
|
266
290
|
if (typeof exports[module][method] !== "function")
|
|
267
291
|
throw new Error("Not found");
|
|
268
|
-
return exports[module][method](...params);
|
|
292
|
+
return [exports[module][method](...params)];
|
|
269
293
|
},
|
|
270
|
-
create: (
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
const digestOfPackAsBytes = sha256_digest(
|
|
274
|
-
const
|
|
294
|
+
create: (code, salt) => {
|
|
295
|
+
const pack = pack_encode([code, salt]);
|
|
296
|
+
const digestOfCodeAsBytes = sha256_digest(code);
|
|
297
|
+
const digestOfPackAsBytes = sha256_digest(pack);
|
|
298
|
+
const digestOfCodeAsHex = digestOfCodeAsBytes.toHex();
|
|
275
299
|
const digestOfPackAsHex = digestOfPackAsBytes.toHex();
|
|
276
|
-
if (!existsSync(`${config.scripts.path}/${
|
|
277
|
-
writeFileSync(`${config.scripts.path}/${
|
|
300
|
+
if (!existsSync(`${config.scripts.path}/${digestOfCodeAsHex}.wasm`))
|
|
301
|
+
writeFileSync(`${config.scripts.path}/${digestOfCodeAsHex}.wasm`, code);
|
|
278
302
|
if (!existsSync(`${config.scripts.path}/${digestOfPackAsHex}.wasm`))
|
|
279
|
-
symlinkSync(`./${
|
|
303
|
+
symlinkSync(`./${digestOfCodeAsHex}.wasm`, `${config.scripts.path}/${digestOfPackAsHex}.wasm`, "file");
|
|
280
304
|
return digestOfPackAsHex;
|
|
281
305
|
}
|
|
282
306
|
};
|
|
@@ -284,28 +308,30 @@ function run(module, method, params, mode, maxsparks) {
|
|
|
284
308
|
set: (key, fresh) => {
|
|
285
309
|
const cache = caches.get(module);
|
|
286
310
|
cache.set(key, fresh);
|
|
287
|
-
const
|
|
288
|
-
|
|
311
|
+
const keyAsBytes = pack_encode(key);
|
|
312
|
+
const valueAsBytes = pack_encode(fresh);
|
|
313
|
+
writes.push([module, keyAsBytes, valueAsBytes]);
|
|
289
314
|
return;
|
|
290
315
|
},
|
|
291
316
|
get: (key) => {
|
|
292
317
|
const cache = caches.get(module);
|
|
293
318
|
const stale = cache.get(key);
|
|
294
319
|
if (stale != null)
|
|
295
|
-
return stale;
|
|
320
|
+
return [stale];
|
|
321
|
+
const keyAsBytes = pack_encode(key);
|
|
296
322
|
const result = new Int32Array(new SharedArrayBuffer(4 + 4 + 4, { maxByteLength: ((4 + 4 + 4) + (1024 * 1024)) }));
|
|
297
|
-
helper.postMessage({ method: "storage_get", params: [module,
|
|
323
|
+
helper.postMessage({ method: "storage_get", params: [module, keyAsBytes], result });
|
|
298
324
|
if (Atomics.wait(result, 0, 0) !== "ok")
|
|
299
325
|
throw new Error("Failed to wait");
|
|
300
326
|
if (result[0] === 2)
|
|
301
327
|
throw new Error("Internal error");
|
|
302
328
|
if (result[1] === 2)
|
|
303
329
|
return null;
|
|
304
|
-
const
|
|
305
|
-
|
|
330
|
+
const valueAsBytes = new Uint8Array(result.buffer, 4 + 4 + 4, result[2]).slice();
|
|
331
|
+
reads.push([module, keyAsBytes, valueAsBytes]);
|
|
332
|
+
const fresh = pack_decode(valueAsBytes);
|
|
306
333
|
cache.set(key, fresh);
|
|
307
|
-
|
|
308
|
-
return fresh;
|
|
334
|
+
return [fresh];
|
|
309
335
|
}
|
|
310
336
|
};
|
|
311
337
|
imports["symbols"] = {
|
|
@@ -344,19 +370,19 @@ function run(module, method, params, mode, maxsparks) {
|
|
|
344
370
|
return ed25519_sign(payload);
|
|
345
371
|
}
|
|
346
372
|
};
|
|
347
|
-
let
|
|
373
|
+
let meteredCodeAsBytes;
|
|
348
374
|
if (!existsSync(`${config.scripts.path}/${module}.metered.wasm`)) {
|
|
349
|
-
const
|
|
350
|
-
const
|
|
351
|
-
meter(
|
|
352
|
-
|
|
353
|
-
writeFileSync(`${config.scripts.path}/${module}.metered.wasm`,
|
|
375
|
+
const codeAsBytes = readFileSync(`${config.scripts.path}/${module}.wasm`);
|
|
376
|
+
const codeAsWasm = Readable.readFromBytesOrThrow(Wasm.Module, codeAsBytes);
|
|
377
|
+
meter(codeAsWasm, "sparks", "consume");
|
|
378
|
+
meteredCodeAsBytes = Writable.writeToBytesOrThrow(codeAsWasm);
|
|
379
|
+
writeFileSync(`${config.scripts.path}/${module}.metered.wasm`, meteredCodeAsBytes);
|
|
354
380
|
}
|
|
355
381
|
else {
|
|
356
|
-
|
|
382
|
+
meteredCodeAsBytes = readFileSync(`${config.scripts.path}/${module}.metered.wasm`);
|
|
357
383
|
}
|
|
358
|
-
const
|
|
359
|
-
for (const descriptor of WebAssembly.Module.imports(
|
|
384
|
+
const meteredCodeAsModule = new WebAssembly.Module(meteredCodeAsBytes);
|
|
385
|
+
for (const descriptor of WebAssembly.Module.imports(meteredCodeAsModule)) {
|
|
360
386
|
if (imports[descriptor.module] != null) {
|
|
361
387
|
// NOOP
|
|
362
388
|
continue;
|
|
@@ -369,10 +395,10 @@ function run(module, method, params, mode, maxsparks) {
|
|
|
369
395
|
imports[descriptor.module] = instance.exports;
|
|
370
396
|
continue;
|
|
371
397
|
}
|
|
372
|
-
const
|
|
373
|
-
current.instance =
|
|
374
|
-
current.module =
|
|
375
|
-
exports[module] =
|
|
398
|
+
const meteredCodeAsInstance = new WebAssembly.Instance(meteredCodeAsModule, imports);
|
|
399
|
+
current.instance = meteredCodeAsInstance;
|
|
400
|
+
current.module = meteredCodeAsModule;
|
|
401
|
+
exports[module] = meteredCodeAsInstance.exports;
|
|
376
402
|
return current;
|
|
377
403
|
};
|
|
378
404
|
const { instance } = load(module);
|