wao 0.13.0 → 0.13.2

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/esm/server.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import crypto from "crypto"
2
+ import HB from "./hb.js"
2
3
  import express from "express"
3
4
  import cors from "cors"
4
5
  import base64url from "base64url"
@@ -8,9 +9,8 @@ import { connect } from "./aoconnect.js"
8
9
  import { GQL, cu, su, mu } from "./test.js"
9
10
  import bodyParser from "body-parser"
10
11
  import { keys, map, isNil, reverse, omit } from "ramda"
11
- import { Bundle } from "arbundles"
12
12
  import { httpbis, createVerifier } from "http-message-signatures"
13
- import { createPublicKey, randomBytes } from "node:crypto"
13
+ import { createPublicKey } from "node:crypto"
14
14
  const { verifyMessage } = httpbis
15
15
 
16
16
  function toANS104Request(fields) {
@@ -77,6 +77,7 @@ class Server {
77
77
  mu = 4002,
78
78
  su = 4003,
79
79
  cu = 4004,
80
+ hb_url,
80
81
  aoconnect,
81
82
  log = false,
82
83
  db,
@@ -90,6 +91,8 @@ class Server {
90
91
  cu = port + 4
91
92
  aoconnect = optAO(5000)
92
93
  }
94
+ let hb = null
95
+ if (hb_url) hb = new HB({ url: hb_url })
93
96
  const {
94
97
  ar: _ar,
95
98
  message,
@@ -100,7 +103,9 @@ class Server {
100
103
  mem,
101
104
  monitor,
102
105
  unmonitor,
103
- } = connect(aoconnect, { log, cache: db })
106
+ recover,
107
+ } = connect(aoconnect, { log, cache: db, hb })
108
+ this.recover = recover
104
109
  this.monitor = monitor
105
110
  this.unmonitor = unmonitor
106
111
  this.spawn = spawn
@@ -156,6 +161,7 @@ class Server {
156
161
  createPublicKey({ key, format: "jwk" }),
157
162
  "rsa-pss-sha512"
158
163
  )
164
+ let id = null
159
165
  try {
160
166
  const isValid = await verifyMessage(
161
167
  { keyLookup: params => ({ verify: verifier }) },
@@ -166,15 +172,21 @@ class Server {
166
172
  }
167
173
  )
168
174
  const item = toANS104Request(sigs).item
175
+
169
176
  if (sigs.slot === "0" || sigs.type === "Process") {
170
- for (let v of item.tags) if (v.name === "Type") v.value = "Process"
177
+ for (let v of item.tags) {
178
+ if (v.name === "Type") v.value = "Process"
179
+ }
180
+
171
181
  const res = await this.spawn({
172
182
  http_msg: item,
173
183
  module: sigs.module,
174
184
  scheduler: sigs.scheduler,
175
185
  })
176
186
  } else if (sigs.type === "Message") {
187
+ for (let v of item.tags) if (v.name === "id") id = v.value
177
188
  const res = await this.message({
189
+ slot: sigs.slot,
178
190
  http_msg: item,
179
191
  process: sigs.target,
180
192
  })
@@ -182,7 +194,6 @@ class Server {
182
194
  } catch (e) {
183
195
  console.log(e, req.originalUrl)
184
196
  }
185
- console.log("bundler success [pid]", sigs.target, "[slot]", sigs.slot)
186
197
  return res.status(200).send("Success")
187
198
  })
188
199
  const server = app.listen(this.ports.bundler, () => {
@@ -396,14 +407,15 @@ class Server {
396
407
  const result = async (req, res) => {
397
408
  let message = req.params.mid
398
409
  const process = req.query["process-id"]
410
+ // check if recovery is ongoing and
399
411
  if (isNil(this.mem.env[process])) {
400
- console.log("process not found:", req.query["process-id"])
401
- res.status(404)
402
- res.json({ error: `not found` })
403
- setTimeout(() => {
404
- console.log(this.mem.env)
405
- }, 1000)
406
- return
412
+ const { success } = await this.recover(process)
413
+ if (!success) {
414
+ console.log("process not found:", req.query["process-id"])
415
+ res.status(404)
416
+ res.json({ error: `not found` })
417
+ return
418
+ }
407
419
  }
408
420
  if (!/^--[0-9a-zA-Z_-]{43,44}$/.test(message)) {
409
421
  message = this.mem.env[process]?.results?.[message]
package/esm/tao.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import BAO from "./bao.js"
2
2
  import { connect } from "./aoconnect.js"
3
3
  import AR from "./tar.js"
4
+ import HB from "./hb.js"
4
5
 
5
6
  class AO extends BAO {
6
7
  constructor(opt = {}) {
8
+ if (opt.hb_url) opt.hb = new HB({ url: opt.hb_url })
7
9
  super({ ...opt, connect, AR })
8
10
  }
9
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"