@hazae41/turbine 0.1.5 → 0.1.7
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.
|
@@ -32,7 +32,6 @@ export async function main(args) {
|
|
|
32
32
|
console.log("Starting...");
|
|
33
33
|
const worker = await RpcWorkerClient.spawn(uuid, path);
|
|
34
34
|
const server = new Server(worker);
|
|
35
|
-
await server.setup();
|
|
36
35
|
Deno.serve({ hostname: "0.0.0.0", port }, (request) => server.respond(request));
|
|
37
36
|
}
|
|
38
37
|
if (import.meta.main) {
|
|
@@ -9,7 +9,6 @@ export declare class Server {
|
|
|
9
9
|
readonly worker: RpcWorkerClient;
|
|
10
10
|
readonly subserver: RpcServer;
|
|
11
11
|
constructor(worker: RpcWorkerClient);
|
|
12
|
-
setup(): Promise<void>;
|
|
13
12
|
respond(request: Request): Promise<any>;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
@@ -21,6 +20,5 @@ export declare class RpcServer {
|
|
|
21
20
|
readonly seens: Set<string>;
|
|
22
21
|
readonly mutex: Mutex<undefined>;
|
|
23
22
|
constructor(worker: RpcWorkerClient);
|
|
24
|
-
setup(): Promise<void>;
|
|
25
23
|
respond(request: RpcRequestInit): Promise<RpcErr | RpcOk<string>>;
|
|
26
24
|
}
|
|
@@ -64,9 +64,6 @@ export class Server {
|
|
|
64
64
|
this.worker = worker;
|
|
65
65
|
this.subserver = new RpcServer(worker);
|
|
66
66
|
}
|
|
67
|
-
async setup() {
|
|
68
|
-
await this.subserver.setup();
|
|
69
|
-
}
|
|
70
67
|
async respond(request) {
|
|
71
68
|
const response = await this.#route(request);
|
|
72
69
|
response.headers.set("Access-Control-Allow-Origin", "*");
|
|
@@ -103,9 +100,6 @@ export class RpcServer {
|
|
|
103
100
|
constructor(worker) {
|
|
104
101
|
this.worker = worker;
|
|
105
102
|
}
|
|
106
|
-
async setup() {
|
|
107
|
-
await this.worker.setup();
|
|
108
|
-
}
|
|
109
103
|
async respond(request) {
|
|
110
104
|
try {
|
|
111
105
|
return new RpcOk(request.id, await this.#route(request));
|
|
@@ -158,19 +152,20 @@ export class RpcServer {
|
|
|
158
152
|
throw new RpcInvalidParamsError();
|
|
159
153
|
if (typeof paramsAsHex !== "string")
|
|
160
154
|
throw new RpcInvalidParamsError();
|
|
161
|
-
const
|
|
155
|
+
const paramsAsRaw = Uint8Array.fromHex(paramsAsHex);
|
|
156
|
+
const paramsAsRef = Packed.decode(paramsAsRaw);
|
|
162
157
|
if (typeof effortAsHex !== "string")
|
|
163
158
|
throw new RpcInvalidParamsError();
|
|
164
159
|
if (effortAsHex.length !== 64)
|
|
165
160
|
throw new RpcInvalidParamsError();
|
|
166
161
|
if (this.seens.has(effortAsHex))
|
|
167
162
|
throw new RpcInvalidParamsError();
|
|
168
|
-
const
|
|
163
|
+
const effortAsRaw = Uint8Array.fromHex(effortAsHex);
|
|
169
164
|
const _ = __addDisposableResource(env_2, await this.mutex.lockOrWait(), false);
|
|
170
165
|
this.seens.add(effortAsHex);
|
|
171
|
-
const proven = new Uint8Array(await crypto.subtle.digest("SHA-256",
|
|
166
|
+
const proven = new Uint8Array(await crypto.subtle.digest("SHA-256", effortAsRaw));
|
|
172
167
|
const target = (2n ** 256n) / BigInt("0x" + proven.toHex());
|
|
173
|
-
const result = await this.worker.execute(module, method,
|
|
168
|
+
const result = await this.worker.execute(module, method, paramsAsRef, target);
|
|
174
169
|
return Packed.encode(result).toHex();
|
|
175
170
|
}
|
|
176
171
|
catch (e_2) {
|
|
@@ -191,19 +186,20 @@ export class RpcServer {
|
|
|
191
186
|
throw new RpcInvalidParamsError();
|
|
192
187
|
if (typeof paramsAsHex !== "string")
|
|
193
188
|
throw new RpcInvalidParamsError();
|
|
194
|
-
const
|
|
189
|
+
const paramsAsRaw = Uint8Array.fromHex(paramsAsHex);
|
|
190
|
+
const paramsAsRef = Packed.decode(paramsAsRaw);
|
|
195
191
|
if (typeof effortAsHex !== "string")
|
|
196
192
|
throw new RpcInvalidParamsError();
|
|
197
193
|
if (effortAsHex.length !== 64)
|
|
198
194
|
throw new RpcInvalidParamsError();
|
|
199
195
|
if (this.seens.has(effortAsHex))
|
|
200
196
|
throw new RpcInvalidParamsError();
|
|
201
|
-
const
|
|
197
|
+
const effortAsRaw = Uint8Array.fromHex(effortAsHex);
|
|
202
198
|
const _ = __addDisposableResource(env_3, await this.mutex.lockOrWait(), false);
|
|
203
199
|
this.seens.add(effortAsHex);
|
|
204
|
-
const proven = new Uint8Array(await crypto.subtle.digest("SHA-256",
|
|
200
|
+
const proven = new Uint8Array(await crypto.subtle.digest("SHA-256", effortAsRaw));
|
|
205
201
|
const target = (2n ** 256n) / BigInt("0x" + proven.toHex());
|
|
206
|
-
const result = await this.worker.simulate(module, method,
|
|
202
|
+
const result = await this.worker.simulate(module, method, paramsAsRef, target);
|
|
207
203
|
return Packed.encode(result).toHex();
|
|
208
204
|
}
|
|
209
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.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"description": "Bobine over HTTP and WebSocket",
|
|
6
6
|
"repository": "github:hazae41/turbine",
|
|
7
7
|
"author": "hazae41",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@hazae41/binary": "^2.1.1",
|
|
26
|
-
"@hazae41/bobine": "^0.1.
|
|
26
|
+
"@hazae41/bobine": "^0.1.8",
|
|
27
27
|
"@hazae41/jsonrpc": "^1.2.1",
|
|
28
28
|
"@hazae41/mutex": "^3.0.1",
|
|
29
|
-
"@hazae41/webpack": "^1.0.
|
|
29
|
+
"@hazae41/webpack": "^1.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@hazae41/phobos": "^2.0.16",
|