wao 0.14.4 → 0.14.5
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/cjs/server.js +57 -54
- package/esm/server.js +15 -15
- package/package.json +1 -1
package/cjs/server.js
CHANGED
|
@@ -176,33 +176,28 @@ var Server = /*#__PURE__*/function () {
|
|
|
176
176
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
177
177
|
while (1) switch (_context.prev = _context.next) {
|
|
178
178
|
case 0:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
console.log("BD: Invalid body | expected raw Buffer");
|
|
184
|
-
return _context.abrupt("return", res.status(400).send("Invalid body: expected raw Buffer"));
|
|
185
|
-
case 3:
|
|
179
|
+
return _context.abrupt("return", res.status(200).send("Success"));
|
|
180
|
+
case 4:
|
|
186
181
|
lines = req.body.toString("utf8").split(/\r?\n/);
|
|
187
182
|
sigs = {};
|
|
188
183
|
currentKey = null;
|
|
189
184
|
_iterator = _createForOfIteratorHelper(lines);
|
|
190
|
-
_context.prev =
|
|
185
|
+
_context.prev = 8;
|
|
191
186
|
_iterator.s();
|
|
192
|
-
case
|
|
187
|
+
case 10:
|
|
193
188
|
if ((_step = _iterator.n()).done) {
|
|
194
|
-
_context.next =
|
|
189
|
+
_context.next = 20;
|
|
195
190
|
break;
|
|
196
191
|
}
|
|
197
192
|
line = _step.value;
|
|
198
193
|
trimmed = line.trim();
|
|
199
194
|
if (!/^--[a-zA-Z0-9_\-=]+/.test(trimmed)) {
|
|
200
|
-
_context.next =
|
|
195
|
+
_context.next = 16;
|
|
201
196
|
break;
|
|
202
197
|
}
|
|
203
198
|
currentKey = null;
|
|
204
|
-
return _context.abrupt("continue",
|
|
205
|
-
case
|
|
199
|
+
return _context.abrupt("continue", 18);
|
|
200
|
+
case 16:
|
|
206
201
|
headerMatch = trimmed.match(/^([a-zA-Z0-9_-]+):\s*(.*)$/);
|
|
207
202
|
if (headerMatch && !headerMatch[2].includes(": ")) {
|
|
208
203
|
_key = headerMatch[1];
|
|
@@ -210,21 +205,21 @@ var Server = /*#__PURE__*/function () {
|
|
|
210
205
|
sigs[_key] = value;
|
|
211
206
|
currentKey = _key;
|
|
212
207
|
} else if (currentKey) sigs[currentKey] += "\n" + line;
|
|
213
|
-
case
|
|
214
|
-
_context.next =
|
|
208
|
+
case 18:
|
|
209
|
+
_context.next = 10;
|
|
215
210
|
break;
|
|
216
|
-
case
|
|
217
|
-
_context.next =
|
|
211
|
+
case 20:
|
|
212
|
+
_context.next = 25;
|
|
218
213
|
break;
|
|
219
|
-
case
|
|
220
|
-
_context.prev =
|
|
221
|
-
_context.t0 = _context["catch"](
|
|
214
|
+
case 22:
|
|
215
|
+
_context.prev = 22;
|
|
216
|
+
_context.t0 = _context["catch"](8);
|
|
222
217
|
_iterator.e(_context.t0);
|
|
223
|
-
case
|
|
224
|
-
_context.prev =
|
|
218
|
+
case 25:
|
|
219
|
+
_context.prev = 25;
|
|
225
220
|
_iterator.f();
|
|
226
|
-
return _context.finish(
|
|
227
|
-
case
|
|
221
|
+
return _context.finish(25);
|
|
222
|
+
case 28:
|
|
228
223
|
sigs.target = req.headers.process;
|
|
229
224
|
sigs.slot = req.headers.slot;
|
|
230
225
|
input = parseSignatureInput(req.headers["signature-input"]);
|
|
@@ -238,8 +233,8 @@ var Server = /*#__PURE__*/function () {
|
|
|
238
233
|
format: "jwk"
|
|
239
234
|
}), "rsa-pss-sha512");
|
|
240
235
|
id = null;
|
|
241
|
-
_context.prev =
|
|
242
|
-
_context.next =
|
|
236
|
+
_context.prev = 34;
|
|
237
|
+
_context.next = 37;
|
|
243
238
|
return verifyMessage({
|
|
244
239
|
keyLookup: function keyLookup(params) {
|
|
245
240
|
return {
|
|
@@ -251,11 +246,11 @@ var Server = /*#__PURE__*/function () {
|
|
|
251
246
|
headers: req.headers,
|
|
252
247
|
url: "http://ao.com".concat(req.headers.path)
|
|
253
248
|
});
|
|
254
|
-
case
|
|
249
|
+
case 37:
|
|
255
250
|
isValid = _context.sent;
|
|
256
251
|
item = toANS104Request(sigs).item;
|
|
257
252
|
if (!(sigs.slot === "0" || sigs.type === "Process")) {
|
|
258
|
-
_context.next =
|
|
253
|
+
_context.next = 47;
|
|
259
254
|
break;
|
|
260
255
|
}
|
|
261
256
|
_iterator2 = _createForOfIteratorHelper(item.tags);
|
|
@@ -269,19 +264,19 @@ var Server = /*#__PURE__*/function () {
|
|
|
269
264
|
} finally {
|
|
270
265
|
_iterator2.f();
|
|
271
266
|
}
|
|
272
|
-
_context.next =
|
|
267
|
+
_context.next = 44;
|
|
273
268
|
return _this.spawn({
|
|
274
269
|
http_msg: item,
|
|
275
270
|
module: sigs.module,
|
|
276
271
|
scheduler: sigs.scheduler
|
|
277
272
|
});
|
|
278
|
-
case
|
|
273
|
+
case 44:
|
|
279
274
|
_res2 = _context.sent;
|
|
280
|
-
_context.next =
|
|
275
|
+
_context.next = 53;
|
|
281
276
|
break;
|
|
282
|
-
case
|
|
277
|
+
case 47:
|
|
283
278
|
if (!(sigs.type === "Message")) {
|
|
284
|
-
_context.next =
|
|
279
|
+
_context.next = 53;
|
|
285
280
|
break;
|
|
286
281
|
}
|
|
287
282
|
_iterator3 = _createForOfIteratorHelper(item.tags);
|
|
@@ -295,28 +290,28 @@ var Server = /*#__PURE__*/function () {
|
|
|
295
290
|
} finally {
|
|
296
291
|
_iterator3.f();
|
|
297
292
|
}
|
|
298
|
-
_context.next =
|
|
293
|
+
_context.next = 52;
|
|
299
294
|
return _this.message({
|
|
300
295
|
slot: sigs.slot,
|
|
301
296
|
http_msg: item,
|
|
302
297
|
process: sigs.target
|
|
303
298
|
});
|
|
304
|
-
case 51:
|
|
305
|
-
_res3 = _context.sent;
|
|
306
299
|
case 52:
|
|
307
|
-
|
|
300
|
+
_res3 = _context.sent;
|
|
301
|
+
case 53:
|
|
302
|
+
_context.next = 58;
|
|
308
303
|
break;
|
|
309
|
-
case
|
|
310
|
-
_context.prev =
|
|
311
|
-
_context.t1 = _context["catch"](
|
|
304
|
+
case 55:
|
|
305
|
+
_context.prev = 55;
|
|
306
|
+
_context.t1 = _context["catch"](34);
|
|
312
307
|
console.log(_context.t1, req.originalUrl);
|
|
313
|
-
case 57:
|
|
314
|
-
return _context.abrupt("return", res.status(200).send("Success"));
|
|
315
308
|
case 58:
|
|
309
|
+
return _context.abrupt("return", res.status(200).send("Success"));
|
|
310
|
+
case 59:
|
|
316
311
|
case "end":
|
|
317
312
|
return _context.stop();
|
|
318
313
|
}
|
|
319
|
-
}, _callee, null, [[
|
|
314
|
+
}, _callee, null, [[8, 22, 25, 28], [34, 55]]);
|
|
320
315
|
}));
|
|
321
316
|
return function (_x, _x2) {
|
|
322
317
|
return _ref2.apply(this, arguments);
|
|
@@ -375,7 +370,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
375
370
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
376
371
|
while (1) switch (_context3.prev = _context3.next) {
|
|
377
372
|
case 0:
|
|
378
|
-
res.send(_this2.mem.getAnchor());
|
|
373
|
+
return _context3.abrupt("return", res.send(_this2.mem.getAnchor()));
|
|
379
374
|
case 1:
|
|
380
375
|
case "end":
|
|
381
376
|
return _context3.stop();
|
|
@@ -391,7 +386,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
391
386
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
392
387
|
while (1) switch (_context4.prev = _context4.next) {
|
|
393
388
|
case 0:
|
|
394
|
-
res.json(req.params);
|
|
389
|
+
return _context4.abrupt("return", res.json(req.params));
|
|
395
390
|
case 1:
|
|
396
391
|
case "end":
|
|
397
392
|
return _context4.stop();
|
|
@@ -433,7 +428,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
433
428
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
434
429
|
while (1) switch (_context6.prev = _context6.next) {
|
|
435
430
|
case 0:
|
|
436
|
-
res.send("0");
|
|
431
|
+
return _context6.abrupt("return", res.send("0"));
|
|
437
432
|
case 1:
|
|
438
433
|
case "end":
|
|
439
434
|
return _context6.stop();
|
|
@@ -813,7 +808,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
813
808
|
});
|
|
814
809
|
var result = /*#__PURE__*/function () {
|
|
815
810
|
var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(req, res) {
|
|
816
|
-
var message, process, _yield$_this5$recover, success, _this5$mem$env$proces, res2;
|
|
811
|
+
var message, process, _yield$_this5$recover, success, slot, _this5$mem$env$proces, _this5$mem$env$proces2, res2;
|
|
817
812
|
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
818
813
|
while (1) switch (_context13.prev = _context13.next) {
|
|
819
814
|
case 0:
|
|
@@ -839,29 +834,37 @@ var Server = /*#__PURE__*/function () {
|
|
|
839
834
|
});
|
|
840
835
|
return _context13.abrupt("return");
|
|
841
836
|
case 12:
|
|
837
|
+
slot = message;
|
|
842
838
|
if (!/^--[0-9a-zA-Z_-]{43,44}$/.test(message)) {
|
|
843
|
-
message = (_this5$mem$env$proces = _this5.mem.env[process]) === null || _this5$mem$env$proces === void 0 || (_this5$mem$env$proces = _this5$mem$env$proces.results) === null || _this5$mem$env$proces === void 0 ? void 0 : _this5$mem$env$proces[
|
|
839
|
+
message = (_this5$mem$env$proces = _this5.mem.env[process]) === null || _this5$mem$env$proces === void 0 || (_this5$mem$env$proces = _this5$mem$env$proces.results) === null || _this5$mem$env$proces === void 0 ? void 0 : _this5$mem$env$proces[slot];
|
|
840
|
+
}
|
|
841
|
+
if (!(0, _ramda.isNil)(message)) {
|
|
842
|
+
_context13.next = 22;
|
|
843
|
+
break;
|
|
844
844
|
}
|
|
845
|
+
_context13.next = 17;
|
|
846
|
+
return _this5.recover(process);
|
|
847
|
+
case 17:
|
|
848
|
+
message = (_this5$mem$env$proces2 = _this5.mem.env[process]) === null || _this5$mem$env$proces2 === void 0 || (_this5$mem$env$proces2 = _this5$mem$env$proces2.results) === null || _this5$mem$env$proces2 === void 0 ? void 0 : _this5$mem$env$proces2[slot];
|
|
845
849
|
if (!(0, _ramda.isNil)(message)) {
|
|
846
|
-
_context13.next =
|
|
850
|
+
_context13.next = 22;
|
|
847
851
|
break;
|
|
848
852
|
}
|
|
849
|
-
console.log("message not found", message, req.params);
|
|
850
853
|
res.status(404);
|
|
851
854
|
res.json({
|
|
852
855
|
error: "Not Found"
|
|
853
856
|
});
|
|
854
857
|
return _context13.abrupt("return");
|
|
855
|
-
case
|
|
856
|
-
_context13.next =
|
|
858
|
+
case 22:
|
|
859
|
+
_context13.next = 24;
|
|
857
860
|
return _this5.result({
|
|
858
861
|
message: message,
|
|
859
862
|
process: process
|
|
860
863
|
});
|
|
861
|
-
case
|
|
864
|
+
case 24:
|
|
862
865
|
res2 = _context13.sent;
|
|
863
866
|
res.json(res2);
|
|
864
|
-
case
|
|
867
|
+
case 26:
|
|
865
868
|
case "end":
|
|
866
869
|
return _context13.stop();
|
|
867
870
|
}
|
package/esm/server.js
CHANGED
|
@@ -4,7 +4,7 @@ import express from "express"
|
|
|
4
4
|
import cors from "cors"
|
|
5
5
|
import base64url from "base64url"
|
|
6
6
|
import { DataItem } from "arbundles"
|
|
7
|
-
import { tags, toGraphObj, optAO } from "./utils.js"
|
|
7
|
+
import { tags, toGraphObj, optAO, wait } from "./utils.js"
|
|
8
8
|
import { connect } from "./aoconnect.js"
|
|
9
9
|
import { GQL, cu, su, mu } from "./test.js"
|
|
10
10
|
import bodyParser from "body-parser"
|
|
@@ -130,6 +130,8 @@ class Server {
|
|
|
130
130
|
app.use(cors())
|
|
131
131
|
app.use("/tx", bodyParser.raw({ type: "*/*", limit: "100mb" }))
|
|
132
132
|
app.post("/tx", async (req, res) => {
|
|
133
|
+
// todo: items from HB has wrong sigs and ids
|
|
134
|
+
return res.status(200).send("Success")
|
|
133
135
|
if (!Buffer.isBuffer(req.body)) {
|
|
134
136
|
console.log("BD: Invalid body | expected raw Buffer")
|
|
135
137
|
return res.status(400).send("Invalid body: expected raw Buffer")
|
|
@@ -218,12 +220,8 @@ class Server {
|
|
|
218
220
|
res.status(400)
|
|
219
221
|
res.send(null)
|
|
220
222
|
})
|
|
221
|
-
app.get("/tx_anchor", async (req, res) =>
|
|
222
|
-
|
|
223
|
-
})
|
|
224
|
-
app.get("/mine", async (req, res) => {
|
|
225
|
-
res.json(req.params)
|
|
226
|
-
})
|
|
223
|
+
app.get("/tx_anchor", async (req, res) => res.send(this.mem.getAnchor()))
|
|
224
|
+
app.get("/mine", async (req, res) => res.json(req.params))
|
|
227
225
|
app.get("/:id", async (req, res) => {
|
|
228
226
|
const _data = await this._ar.data(req.params.id)
|
|
229
227
|
if (!_data) {
|
|
@@ -233,9 +231,7 @@ class Server {
|
|
|
233
231
|
res.send(Buffer.from(_data, "base64"))
|
|
234
232
|
}
|
|
235
233
|
})
|
|
236
|
-
app.get("/price/:id", async (req, res) =>
|
|
237
|
-
res.send("0")
|
|
238
|
-
})
|
|
234
|
+
app.get("/price/:id", async (req, res) => res.send("0"))
|
|
239
235
|
app.post("/graphql", async (req, res) => {
|
|
240
236
|
try {
|
|
241
237
|
const { query, variables } = req.body
|
|
@@ -414,14 +410,18 @@ class Server {
|
|
|
414
410
|
return
|
|
415
411
|
}
|
|
416
412
|
}
|
|
413
|
+
const slot = message
|
|
417
414
|
if (!/^--[0-9a-zA-Z_-]{43,44}$/.test(message)) {
|
|
418
|
-
message = this.mem.env[process]?.results?.[
|
|
415
|
+
message = this.mem.env[process]?.results?.[slot]
|
|
419
416
|
}
|
|
420
417
|
if (isNil(message)) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
418
|
+
await this.recover(process)
|
|
419
|
+
message = this.mem.env[process]?.results?.[slot]
|
|
420
|
+
if (isNil(message)) {
|
|
421
|
+
res.status(404)
|
|
422
|
+
res.json({ error: `Not Found` })
|
|
423
|
+
return
|
|
424
|
+
}
|
|
425
425
|
}
|
|
426
426
|
const res2 = await this.result({
|
|
427
427
|
message,
|