@hazae41/turbine 0.1.6 → 0.1.8

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 CHANGED
@@ -11,5 +11,5 @@ deno install --global npm:@hazae41/turbine --name turbine
11
11
  ## Usage
12
12
 
13
13
  ```bash
14
- turbine serve --data=./local --port=80 --uuid=7d07d60d-cb47-4b6f-ad1d-f2650610ce67
14
+ turbine serve ./local --port=80
15
15
  ```
package/out/mod.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- export * from "./mods/mod.ts";
2
+ export * from "./mods/mod.d.ts";
3
3
  export declare function main(args: string[]): Promise<void>;
package/out/mod.js CHANGED
@@ -17,7 +17,7 @@ export async function main(args) {
17
17
  }
18
18
  break;
19
19
  }
20
- console.log("serve [--uuid=<uuid>] [--data=<data folder as path>] [--port=<port>] [--dev]");
20
+ console.log("serve [--data=<data folder as path>] [--port=<port>] [--dev]");
21
21
  return;
22
22
  }
23
23
  if (import.meta.main) {
package/out/mods/mod.d.ts CHANGED
@@ -1 +1 @@
1
- export * from "./turbine/mod.ts";
1
+ export * from "./turbine/mod.d.ts";
@@ -1 +1 @@
1
- export * from "./server/mod.ts";
1
+ export * from "./server/mod.d.ts";
@@ -6,18 +6,6 @@ export async function main(args) {
6
6
  const options = {};
7
7
  for (let i = 0; i < args.length; i++) {
8
8
  const arg = args[i];
9
- if (arg.startsWith("--env=")) {
10
- process.loadEnvFile(arg.slice("--env=".length));
11
- continue;
12
- }
13
- if (arg.startsWith("--uuid=")) {
14
- options.uuid = arg.slice("--uuid=".length);
15
- continue;
16
- }
17
- if (arg.startsWith("--data=")) {
18
- options.path = arg.slice("--data=".length);
19
- continue;
20
- }
21
9
  if (arg.startsWith("--port=")) {
22
10
  options.port = Number(arg.slice("--port=".length));
23
11
  continue;
@@ -26,11 +14,11 @@ export async function main(args) {
26
14
  process.env.NODE_ENV = "development";
27
15
  continue;
28
16
  }
29
- throw new Error(`Unknown argument: ${arg}`);
17
+ options.path = arg;
30
18
  }
31
- const { uuid = process.env.UUID || "98e31aaf-c518-430b-8863-eed26c44d91f", path = process.env.DATA || "./data", port = Number(process.env.PORT) || 8080 } = options;
19
+ const { path = "./data", port = 8080 } = options;
32
20
  console.log("Starting...");
33
- const worker = await RpcWorkerClient.spawn(uuid, path);
21
+ const worker = await RpcWorkerClient.spawn(path);
34
22
  const server = new Server(worker);
35
23
  Deno.serve({ hostname: "0.0.0.0", port }, (request) => server.respond(request));
36
24
  }
@@ -152,19 +152,20 @@ export class RpcServer {
152
152
  throw new RpcInvalidParamsError();
153
153
  if (typeof paramsAsHex !== "string")
154
154
  throw new RpcInvalidParamsError();
155
- const params = Uint8Array.fromHex(paramsAsHex);
155
+ const paramsAsRaw = Uint8Array.fromHex(paramsAsHex);
156
+ const paramsAsRef = Packed.decode(paramsAsRaw);
156
157
  if (typeof effortAsHex !== "string")
157
158
  throw new RpcInvalidParamsError();
158
159
  if (effortAsHex.length !== 64)
159
160
  throw new RpcInvalidParamsError();
160
161
  if (this.seens.has(effortAsHex))
161
162
  throw new RpcInvalidParamsError();
162
- const effort = Uint8Array.fromHex(effortAsHex);
163
+ const effortAsRaw = Uint8Array.fromHex(effortAsHex);
163
164
  const _ = __addDisposableResource(env_2, await this.mutex.lockOrWait(), false);
164
165
  this.seens.add(effortAsHex);
165
- const proven = new Uint8Array(await crypto.subtle.digest("SHA-256", effort));
166
+ const proven = new Uint8Array(await crypto.subtle.digest("SHA-256", effortAsRaw));
166
167
  const target = (2n ** 256n) / BigInt("0x" + proven.toHex());
167
- const result = await this.worker.execute(module, method, params, target);
168
+ const result = await this.worker.execute(module, method, paramsAsRef, target);
168
169
  return Packed.encode(result).toHex();
169
170
  }
170
171
  catch (e_2) {
@@ -185,19 +186,20 @@ export class RpcServer {
185
186
  throw new RpcInvalidParamsError();
186
187
  if (typeof paramsAsHex !== "string")
187
188
  throw new RpcInvalidParamsError();
188
- const params = Uint8Array.fromHex(paramsAsHex);
189
+ const paramsAsRaw = Uint8Array.fromHex(paramsAsHex);
190
+ const paramsAsRef = Packed.decode(paramsAsRaw);
189
191
  if (typeof effortAsHex !== "string")
190
192
  throw new RpcInvalidParamsError();
191
193
  if (effortAsHex.length !== 64)
192
194
  throw new RpcInvalidParamsError();
193
195
  if (this.seens.has(effortAsHex))
194
196
  throw new RpcInvalidParamsError();
195
- const effort = Uint8Array.fromHex(effortAsHex);
197
+ const effortAsRaw = Uint8Array.fromHex(effortAsHex);
196
198
  const _ = __addDisposableResource(env_3, await this.mutex.lockOrWait(), false);
197
199
  this.seens.add(effortAsHex);
198
- const proven = new Uint8Array(await crypto.subtle.digest("SHA-256", effort));
200
+ const proven = new Uint8Array(await crypto.subtle.digest("SHA-256", effortAsRaw));
199
201
  const target = (2n ** 256n) / BigInt("0x" + proven.toHex());
200
- const result = await this.worker.simulate(module, method, params, target);
202
+ const result = await this.worker.simulate(module, method, paramsAsRef, target);
201
203
  return Packed.encode(result).toHex();
202
204
  }
203
205
  catch (e_3) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/turbine",
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "description": "Bobine over HTTP and WebSocket",
6
6
  "repository": "github:hazae41/turbine",
7
7
  "author": "hazae41",
@@ -9,8 +9,8 @@
9
9
  "scripts": {
10
10
  "examine": "deno lint ./src && deno check ./src && deno test -R ./src",
11
11
  "prepack": "rm -rf ./out && tsc && tscousin",
12
- "produce": "deno run -A ./src/mod.ts serve --data=./local --uuid=7d07d60d-cb47-4b6f-ad1d-f2650610ce67",
13
- "develop": "deno run -A ./src/mod.ts serve --data=./local --uuid=7d07d60d-cb47-4b6f-ad1d-f2650610ce67 --dev"
12
+ "produce": "deno run -A ./src/mod.ts serve ./local",
13
+ "develop": "deno run -A ./src/mod.ts serve ./local --dev"
14
14
  },
15
15
  "files": [
16
16
  "./out"
@@ -23,14 +23,14 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@hazae41/binary": "^2.1.1",
26
- "@hazae41/bobine": "^0.1.7",
26
+ "@hazae41/bobine": "^0.1.11",
27
27
  "@hazae41/jsonrpc": "^1.2.1",
28
28
  "@hazae41/mutex": "^3.0.1",
29
29
  "@hazae41/webpack": "^1.0.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@hazae41/phobos": "^2.0.16",
33
- "@hazae41/tscousin": "^1.0.28",
33
+ "@hazae41/tscousin": "^1.0.33",
34
34
  "@types/node": "^26.6.11",
35
35
  "typescript": "^7.0.2"
36
36
  },