wao 0.21.2 → 0.22.0

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/test.js CHANGED
@@ -34,6 +34,7 @@ Object.defineProperty(exports, "GQL", {
34
34
  return _tgql["default"];
35
35
  }
36
36
  });
37
+ exports.HyperBEAM = void 0;
37
38
  Object.defineProperty(exports, "Server", {
38
39
  enumerable: true,
39
40
  get: function get() {
@@ -142,4 +143,5 @@ var blueprint = exports.blueprint = /*#__PURE__*/function () {
142
143
  return _ref.apply(this, arguments);
143
144
  };
144
145
  }();
145
- var scheduler = exports.scheduler = "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA";
146
+ var scheduler = exports.scheduler = "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA";
147
+ var HyperBEAM = exports.HyperBEAM = "./hyperbeam.js";
package/cjs/utils.js CHANGED
@@ -9,9 +9,12 @@ exports.optServer = exports.optAO = exports.mergeOut = exports.mergeChecks = exp
9
9
  exports.parseSignatureInput = parseSignatureInput;
10
10
  exports.tags = exports.tagEq = exports.tag = exports.srcs = exports.searchTag = void 0;
11
11
  exports.toANS104Request = toANS104Request;
12
+ exports.toAddr = toAddr;
12
13
  exports.wait = exports.validAddress = exports.udl = exports.toGraphObj = void 0;
13
14
  var _graphql = require("graphql");
15
+ var _fastSha = _interopRequireDefault(require("fast-sha256"));
14
16
  var _ramda = require("ramda");
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
18
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
16
19
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
20
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
@@ -134,12 +137,14 @@ var wait = exports.wait = function wait(ms) {
134
137
  }, ms);
135
138
  });
136
139
  };
137
- var tags = exports.tags = function tags(_tags2) {
140
+ var tags = exports.tags = function tags() {
141
+ var tags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
138
142
  return (0, _ramda.fromPairs)((0, _ramda.map)(function (v) {
139
143
  return [v.name, v.value];
140
- })(_tags2));
144
+ })(tags));
141
145
  };
142
- var ltags = exports.ltags = function ltags(tags) {
146
+ var ltags = exports.ltags = function ltags() {
147
+ var tags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
143
148
  return (0, _ramda.fromPairs)((0, _ramda.map)(function (v) {
144
149
  return [v.name.toLowerCase(), v.value];
145
150
  })(tags));
@@ -793,4 +798,35 @@ function parseSignatureInput(input) {
793
798
  alg: alg,
794
799
  keyid: keyid
795
800
  };
801
+ }
802
+ function base64urlDecode(str) {
803
+ str = str.replace(/-/g, "+").replace(/_/g, "/");
804
+ var pad = str.length % 4;
805
+ if (pad === 2) str += "==";else if (pad === 3) str += "=";else if (pad !== 0) throw new Error("Invalid base64url string");
806
+ var bin = atob(str);
807
+ var bytes = new Uint8Array(bin.length);
808
+ for (var i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
809
+ return bytes;
810
+ }
811
+ function base64urlEncode(bytes) {
812
+ var bin = "";
813
+ var _iterator13 = _createForOfIteratorHelper(bytes),
814
+ _step13;
815
+ try {
816
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
817
+ var b = _step13.value;
818
+ bin += String.fromCharCode(b);
819
+ }
820
+ } catch (err) {
821
+ _iterator13.e(err);
822
+ } finally {
823
+ _iterator13.f();
824
+ }
825
+ var b64 = btoa(bin);
826
+ return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
827
+ }
828
+ function toAddr(n) {
829
+ var pubBytes = base64urlDecode(n);
830
+ var hash = (0, _fastSha["default"])(pubBytes);
831
+ return base64urlEncode(hash);
796
832
  }
@@ -338,7 +338,9 @@ class Adaptor {
338
338
  const res2 = await this.result({ message, process })
339
339
  return { json: res2 }
340
340
  }
341
-
341
+ async cu_post_result(...args) {
342
+ return await this.cu_get_result(...args)
343
+ }
342
344
  async su_get_root({ query, params, body, headers, method }) {
343
345
  return {
344
346
  json: {
@@ -477,7 +479,7 @@ class Adaptor {
477
479
  const edges = map(v => ({ node: v, cursor: v.cursor }), res2)
478
480
  return {
479
481
  json: {
480
- data: { transactions: { pageInfo: { hasNextPage: true }, edges } },
482
+ data: { [tar]: { pageInfo: { hasNextPage: true }, edges } },
481
483
  },
482
484
  }
483
485
  } catch (e) {
package/esm/ao.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  dryrun,
15
15
  monitor,
16
16
  unmonitor,
17
- } from "@permaweb/aoconnect"
17
+ } from "@permaweb/aoconnect-69"
18
18
 
19
19
  import {
20
20
  dissoc,
@@ -341,8 +341,8 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
341
341
  module: p.module,
342
342
  })
343
343
  if (!p.handle) {
344
- const { format, mod, wasm } = await mem.getWasm(p.modulea)
345
- const wdrive = extensions[p.extention]
344
+ const { format, mod, wasm } = await mem.getWasm(p.module)
345
+ const wdrive = extensions[p.extension]
346
346
  p.handle = await AoLoader(wasm, {
347
347
  format,
348
348
  WeaveDrive: wdrive,
@@ -405,18 +405,18 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
405
405
  scheduler: info.address,
406
406
  }
407
407
  ;({ slot } = await request(_tags))
408
- const {
409
- results: {
410
- json: { body },
411
- },
412
- } = await fetchHB(`/${v.Target}~process@1.0/compute`, {
408
+ const res = await fetchHB(`/${v.Target}~process@1.0/compute`, {
413
409
  params: `slot=${slot}`,
414
410
  })
415
- result = JSON.parse(body).Output.data
411
+ const {
412
+ results: { data },
413
+ } = res
414
+ result = data
416
415
  } catch (e) {
417
416
  console.log(e)
418
417
  }
419
418
  if (result) {
419
+ /*
420
420
  await message({
421
421
  for: slot,
422
422
  process: opt.process,
@@ -427,7 +427,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
427
427
  signer: mu.signer,
428
428
  from: v.Target,
429
429
  target: opt.process,
430
- })
430
+ })*/
431
431
  }
432
432
  } else if (t.__Scheduler__) {
433
433
  const sch = t.__Scheduler__
@@ -570,8 +570,8 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
570
570
  module: p.module,
571
571
  })
572
572
  if (!p.handle) {
573
- const { format, mod, wasm } = await mem.getWasm(p.modulea)
574
- const wdrive = extensions[p.extention]
573
+ const { format, mod, wasm } = await mem.getWasm(p.module)
574
+ const wdrive = extensions[p.extension]
575
575
  p.handle = await AoLoader(wasm, {
576
576
  format,
577
577
  WeaveDrive: wdrive,
@@ -793,7 +793,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
793
793
  }
794
794
  if (!p.handle) {
795
795
  const { format, mod, wasm } = await mem.getWasm(p.module)
796
- const wdrive = extensions[p.extention]
796
+ const wdrive = extensions[p.extension]
797
797
  p.handle = await AoLoader(wasm, {
798
798
  format,
799
799
  WeaveDrive: wdrive,
package/esm/ar.js CHANGED
@@ -41,7 +41,7 @@ class AR {
41
41
  data = resData
42
42
  } catch (error) {
43
43
  console.error(
44
- `Error while trying to download contiguous data from gateway cache for ${id}`,
44
+ `Error while trying to download contiguous data from gateway cache for ${id}`
45
45
  )
46
46
  console.error(error)
47
47
  }
package/esm/bao.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import MAO from "./ao.js"
2
- import { createDataItemSigner } from "@permaweb/aoconnect"
2
+ import { createDataItemSigner } from "@permaweb/aoconnect-69"
3
3
  import { srcs, buildTags } from "./utils.js"
4
4
  import { mergeLeft, is, map } from "ramda"
5
5
  import HB from "./hb.js"
package/esm/bar.js CHANGED
@@ -35,6 +35,7 @@ class AR extends MAR {
35
35
  }
36
36
  return false
37
37
  }
38
+
38
39
  async httpmsg(msg) {
39
40
  const tags = t(msg.tags)
40
41
  let owner = null
@@ -47,11 +48,13 @@ class AR extends MAR {
47
48
  await this.mem.set(msg, "txs", msg.id)
48
49
  return { item: msg, id: tags.id, tags, owner }
49
50
  }
51
+
50
52
  async owner(di) {
51
53
  return base64url.encode(
52
54
  Buffer.from(await crypto.subtle.digest("SHA-256", di.rawOwner))
53
55
  )
54
56
  }
57
+
55
58
  async dataitem({ target = "", data = "1984", tags = {}, signer, item }) {
56
59
  let di = item
57
60
  if (!di) {
package/esm/gql.js CHANGED
@@ -13,6 +13,7 @@ const subs = {
13
13
  parent: ["id"],
14
14
  bundledIn: ["id"],
15
15
  }
16
+
16
17
  const field = (key, val = true) => {
17
18
  if (includes(key, ["id", "anchor", "signature", "recipient"])) {
18
19
  return key
@@ -57,7 +58,7 @@ const query = (opt = {}) => {
57
58
  tags.push(`{ name: "${k}", values: ["${opt.tags[k]}"] }`)
58
59
  } else if (is(Array, opt.tags[k])) {
59
60
  tags.push(
60
- `{ name: "${k}", values: [${map(v => `"${v}"`, opt.tags[k]).join(", ")}] }`,
61
+ `{ name: "${k}", values: [${map(v => `"${v}"`, opt.tags[k]).join(", ")}] }`
61
62
  )
62
63
  }
63
64
  }
package/esm/hb.js CHANGED
@@ -1,21 +1,229 @@
1
1
  import { connect, createSigner } from "@permaweb/aoconnect"
2
- import { last, isNotNil, mergeLeft } from "ramda"
3
- import { buildTags } from "./utils.js"
2
+ import { isEmpty, last, isNotNil, mergeLeft } from "ramda"
3
+ import { toAddr, buildTags } from "./utils.js"
4
+ import { send as _send, verify, createRequest } from "./signer.js"
4
5
 
5
- const randomBytes = num => {
6
+ const seed = num => {
6
7
  const array = new Uint8Array(num)
7
- return crypto.getRandomValues(array)
8
+ return crypto.getRandomValues(array).toString()
8
9
  }
9
10
 
10
11
  class HB {
11
- constructor({ url = "http://localhost:10001" } = {}) {
12
+ constructor({ url = "http://localhost:10001", jwk } = {}) {
12
13
  this.url = url
14
+ this.hyperbuddy = {
15
+ metrics: async (args = {}) => {
16
+ return this.parseMetrics(
17
+ await this.fetch(this.path("hyperbuddy", "metrics", false), false)
18
+ )
19
+ },
20
+ }
21
+
22
+ this.json = {
23
+ commit: async args => {
24
+ return await this.send({ path: "/~json@1.0/commit", ...args })
25
+ },
26
+ verify: async args => {
27
+ return await this.send({ path: "/~json@1.0/verify", ...args })
28
+ },
29
+ deserialize: async args => {
30
+ return await this.send({ path: "/~json@1.0/deserialize", ...args })
31
+ },
32
+ serialize: async args => {
33
+ return await this.send({ path: "/~json@1.0/serialize", ...args })
34
+ },
35
+ }
36
+ this.meta = {
37
+ info: async (args = {}) => {
38
+ let { method = "GET", json = true, key } = args
39
+ if (method.toLowerCase() === "post") {
40
+ return await this.send({ path: "/~meta@1.0/info", ...args })
41
+ } else {
42
+ return key
43
+ ? await this.fetch(
44
+ this.path("meta", `info/${key}`, args.json ?? false),
45
+ args.json ?? false
46
+ )
47
+ : await this.fetch(this.path("meta", "info", json))
48
+ }
49
+ },
50
+ build: async () => {
51
+ return await this.fetch(this.path("meta", "build"))
52
+ },
53
+ }
54
+ if (jwk) this._init(jwk)
55
+ }
56
+
57
+ _init(jwk) {
58
+ this.signer = createSigner(jwk, this.url)
59
+ this.addr = toAddr(jwk.n)
60
+ this._request2 = createRequest({ signer: this.signer, url: this.url })
61
+
62
+ const { request } = connect({
63
+ MODE: "mainnet",
64
+ URL: this.url,
65
+ device: "",
66
+ signer: this.signer,
67
+ })
68
+
69
+ this._request = request
70
+ }
71
+
72
+ async init(jwk) {
73
+ this._init(jwk)
74
+ this._info = await this.meta.info({})
75
+ return this
76
+ }
77
+
78
+ async send(args) {
79
+ return await _send(await this._request2(args))
80
+ }
81
+
82
+ async getImage() {
83
+ const result = await this.send({
84
+ path: "/~wao@1.0/cache_wasm_image",
85
+ method: "POST",
86
+ filename: "test/aos-2-pure-xs.wasm",
87
+ })
88
+ return result.headers.get("image")
89
+ }
90
+
91
+ async messageAOS({ pid, action = "Eval", tags = {}, data }) {
92
+ pid ??= this.pid
93
+ let _tags = mergeLeft(tags, {
94
+ device: "process@1.0",
95
+ method: "POST",
96
+ path: `/${pid}/schedule`,
97
+ scheduler: this.scheduler,
98
+ Type: "Message",
99
+ Action: action,
100
+ Target: pid,
101
+ })
102
+ if (data) _tags.data = data
103
+ let res = await this.send(_tags)
104
+ const slot = res.headers.get("slot")
105
+ return { slot, outbox: await this.computeAOS({ pid, slot }) }
106
+ }
107
+
108
+ path(dev = "meta", path = "info", json = true, params = {}) {
109
+ if (!/@/.test(dev)) dev += "@1.0"
110
+ let _params = ""
111
+ if (!isEmpty(params)) {
112
+ let i = 0
113
+ for (const k in params) {
114
+ _params += `${i === 0 ? "?" : "&"}${k}=${params[k]}`
115
+ i++
116
+ }
117
+ }
118
+ return `${this.url}/~${dev}/${path}${json ? "/serialize~json@1.0" : ""}${_params}`
119
+ }
120
+
121
+ async text(dev, path) {
122
+ return await this.fetch(this.path(dev, path, false), false)
123
+ }
124
+
125
+ async json(dev, path) {
126
+ return await this.fetch(this.path(dev, path))
127
+ }
128
+
129
+ async fetch(url, json = true) {
130
+ return await fetch(url).then(r => (json ? r.json() : r.text()))
131
+ }
132
+
133
+ async computeAOS({ pid, slot }) {
134
+ return await fetch(
135
+ `${this.url}/${pid}/compute/results/outbox/serialize~json@1.0?slot=${slot}`
136
+ ).then(r => r.json())
13
137
  }
14
138
 
15
- async metrics() {
16
- const txt = await fetch(`${this.url}/~hyperbuddy@1.0/metrics`).then(r =>
17
- r.text()
139
+ async compute(pid, slot) {
140
+ return await fetch(
141
+ `${this.url}/${pid}/compute/serialize~json@1.0?slot=${slot}`
142
+ ).then(r => r.json())
143
+ }
144
+
145
+ async computeLegacy(pid, slot) {
146
+ const json = await this.compute(pid, slot)
147
+ return JSON.parse(json.results.json.body)
148
+ }
149
+
150
+ async spawn(tags = {}) {
151
+ const addr = await this.meta.info({ key: "address" })
152
+ this.scheduler ??= addr
153
+ const spawned = await this.send(
154
+ mergeLeft(tags, {
155
+ device: "process@1.0",
156
+ path: "/schedule",
157
+ scheduler: this.scheduler,
158
+ "random-seed": seed(16),
159
+ Type: "Process",
160
+ "scheduler-device": "scheduler@1.0",
161
+ "execution-device": "wao@1.0",
162
+ })
18
163
  )
164
+ const pid = spawned.headers.get("process")
165
+ this.pid ??= pid
166
+ const res = await this.compute(pid, 0)
167
+ return { spawned: res, pid, res }
168
+ }
169
+
170
+ async message(...args) {
171
+ const { pid, slot, res: scheduled } = await this.schedule(...args)
172
+ const res = await this.compute(pid, slot)
173
+ return { slot, pid, res, scheduled }
174
+ }
175
+
176
+ async schedule({ pid, tags = {}, data, scheduler } = {}) {
177
+ pid ??= this.pid
178
+ scheduler ??= this.scheduler
179
+ let _tags = mergeLeft(tags, {
180
+ device: "process@1.0",
181
+ method: "POST",
182
+ path: `/${pid}/schedule`,
183
+ scheduler,
184
+ Type: "Message",
185
+ Target: pid,
186
+ })
187
+ if (data) _tags.data = data
188
+ let res = await this.send(_tags)
189
+ const slot = res.headers.get("slot")
190
+ return { slot, res, pid }
191
+ }
192
+
193
+ async spawnAOS(image) {
194
+ const addr = await this.meta.info({ key: "address" })
195
+ this.scheduler ??= addr
196
+ image ??= this.image ?? (await this.getImage())
197
+ const res = await this.send({
198
+ device: "process@1.0",
199
+ path: "/schedule",
200
+ scheduler: this.scheduler,
201
+ "Data-Protocol": "ao",
202
+ Variant: "ao.N.1",
203
+ "scheduler-location": this.scheduler,
204
+ Authority: this.scheduler,
205
+ "random-seed": seed(16),
206
+ Type: "Process",
207
+ image,
208
+ "scheduler-device": "scheduler@1.0",
209
+ "execution-device": "stack@1.0",
210
+ "device-stack": [
211
+ "wasi@1.0",
212
+ "json-iface@1.0",
213
+ "wasm-64@1.0",
214
+ "multipass@1.0",
215
+ ],
216
+ "output-prefix": "wasm",
217
+ "patch-from": "/results/outbox",
218
+ "stack-keys": ["init", "compute", "snapshot", "normalize"],
219
+ passes: 2,
220
+ })
221
+ const pid = res.headers.get("process")
222
+ this.pid ??= pid
223
+ return pid
224
+ }
225
+
226
+ parseMetrics(txt) {
19
227
  const parts = txt.split(/\r?\n/)
20
228
  let index = 0
21
229
  let _metrics = {}
@@ -47,25 +255,6 @@ class HB {
47
255
  return _metrics
48
256
  }
49
257
 
50
- async info() {
51
- const txt = await fetch(
52
- `${this.url}/~meta@1.0/info/serialize~json@1.0`
53
- ).then(r => r.json())
54
- return txt
55
- }
56
-
57
- async init(jwk) {
58
- this._info = await this.info()
59
- const { request } = connect({
60
- MODE: "mainnet",
61
- URL: this.url,
62
- device: "",
63
- signer: createSigner(jwk),
64
- })
65
- this._request = request
66
- return this
67
- }
68
-
69
258
  async messages({ target, from, to, limit } = {}) {
70
259
  let params = `target=${target}`
71
260
  if (isNotNil(from)) params += `&from=${from}`
@@ -88,21 +277,22 @@ class HB {
88
277
  data,
89
278
  Type: "Process",
90
279
  "Data-Protocol": "ao",
91
- Variant: "ao.N.1",
280
+ Variant: "ao.TN.1",
92
281
  scheduler: this._info.address,
93
- authority: this._info.address,
94
- "scheduler-location": this.info.address,
95
- "random-seed": randomBytes(16).toString("hex"),
282
+ Authority: this._info.address,
283
+ "scheduler-location": this._info.address,
284
+ "random-seed": seed(16),
96
285
  module: "JArYBF-D8q2OmZ4Mok00sD2Y_6SYEQ7Hjx-6VZ_jl3g",
97
286
  device: "process@1.0",
98
287
  "scheduler-device": "scheduler@1.0",
99
288
  "execution-device": "genesis-wasm@1.0",
100
289
  })
101
290
  const res = await this.post({ tags })
102
- return await res.process.text()
291
+ return res.process
103
292
  }
104
293
 
105
- async schedule({ tags = {}, data, process, action = "Eval" } = {}) {
294
+ /*
295
+ async scheduleLegacy({ tags = {}, data, process, action = "Eval" } = {}) {
106
296
  tags = mergeLeft(tags, {
107
297
  path: `${process}/schedule`,
108
298
  type: "Message",
@@ -113,21 +303,20 @@ class HB {
113
303
  })
114
304
  return (await this.post({ tags })).slot.text()
115
305
  }
116
-
117
- async compute({ tags = {}, process, slot } = {}) {
118
- return await this.request({
119
- method: "GET",
120
- path: `/${process}/compute&slot+integer=${slot}/results/json`,
121
- })
122
- }
306
+ */
123
307
 
124
308
  async dryrun({ tags = {}, process, action, data } = {}) {
125
309
  if (typeof action === "string") tags.Action = action
126
310
  let json = { Tags: buildTags(tags) }
127
311
  if (data) json.Data = data
128
- return await fetch(
129
- `${this.url}/~relay@1.0/call?relay-method=POST&relay-path=/dry-run?process-id=${process}/&content-type=application/json&body=${JSON.stringify(json)}`
130
- ).then(r => r.json())
312
+ const res = await this.send({
313
+ path: "/~relay@1.0/call",
314
+ "relay-method": "POST",
315
+ "relay-path": `/dry-run?process-id=${process}`,
316
+ "content-type": "application/json",
317
+ body: JSON.stringify(json),
318
+ })
319
+ return JSON.parse(res.body)
131
320
  }
132
321
 
133
322
  async get({ device, path = "~meta@1.0/info" }) {
package/esm/helpers.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AR, AO } from "./index.js"
2
2
  import assert from "assert"
3
- import { createDataItemSigner, connect } from "@permaweb/aoconnect"
3
+ import { connect } from "@permaweb/aoconnect"
4
4
  //import { connect } from "aoconnect-wao"
5
5
  import { dirname as _dirname, resolve } from "path"
6
6
  import { mkdirSync, existsSync, writeFileSync, readFileSync } from "fs"
@@ -0,0 +1,21 @@
1
+ import express from "express"
2
+ import cors from "cors"
3
+ import bodyParser from "body-parser"
4
+
5
+ const run = (port = 4000) => {
6
+ const app = express()
7
+ app.use(cors())
8
+ app.use(
9
+ express.raw({
10
+ type: "application/octet-stream",
11
+ limit: "10mb",
12
+ })
13
+ )
14
+ app.use(express.json())
15
+ app.post("/relay", async (req, res) => {
16
+ res.json({ success: true, body: req.body.toString() })
17
+ })
18
+ return app.listen(port, () => console.log(`Hyper WAO on port ${port}`))
19
+ }
20
+
21
+ export { run }
@@ -0,0 +1,57 @@
1
+ import { spawn } from "child_process"
2
+ import { resolve } from "path"
3
+
4
+ export default class HyperBEAM {
5
+ constructor({
6
+ port = 10001,
7
+ gateway,
8
+ wallet,
9
+ cwd = "../HyperBEAM",
10
+ c,
11
+ cmake,
12
+ legacy = false,
13
+ } = {}) {
14
+ this.c = c
15
+ this.cmake = cmake
16
+ this.port = port
17
+ this.hbeam = spawn(
18
+ "rebar3",
19
+ ["shell", "--eval", this.genEval({ gateway, wallet, legacy })],
20
+ {
21
+ env: { ...process.env, ...this.genEnv() },
22
+ cwd: resolve(import.meta.dirname, cwd),
23
+ }
24
+ )
25
+ this.hbeam.stdout.on("data", chunk => console.log(`stdout: ${chunk}`))
26
+ this.hbeam.stderr.on("data", err => console.error(`stderr: ${err}`))
27
+ this.hbeam.on("error", err =>
28
+ console.error(`failed to start process: ${err}`)
29
+ )
30
+ this.hbeam.on("close", code =>
31
+ console.log(`child process exited with code ${code}`)
32
+ )
33
+ return this.hbeam
34
+ }
35
+ genEnv() {
36
+ let _env = {}
37
+ if (this.c) {
38
+ _env.CC = `gcc-${this.c}`
39
+ _env.CXX = `g++-${this.c}`
40
+ }
41
+ if (this.cmake) _env.CMAKE_POLICY_VERSION_MINIMUM = this.cmake
42
+ return _env
43
+ }
44
+ genEval({ gateway, wallet = ".wallet.json", legacy = false }) {
45
+ const _wallet = `, priv_key_location => <<"${wallet}">>`
46
+ const _gateway = gateway
47
+ ? `, gateway => <<"http://localhost:${gateway}">>`
48
+ : ""
49
+ return !legacy
50
+ ? `hb:start_mainnet(#{ port => ${this.port}${_gateway}${_wallet} }).`
51
+ : `hb:start_mainnet(#{ port => ${this.port}${_gateway}${_wallet}, bundler_httpsig => <<\"http://localhost:4001\">>, routes => [ #{ <<\"template\">> => <<\"/result/.*\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4004\">> } }, #{ <<\"template\">> => <<\"/dry-run\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4004\">> } }, #{ <<\"template\">> => <<\"/graphql\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4000\">>, <<\"opts\">> => #{ http_client => gun } } }, #{ <<\"template\">> => <<\"/raw\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4000\">>, <<\"opts\">> => #{ http_client => gun } } } ] }).`
52
+ }
53
+
54
+ kill() {
55
+ this.hbeam.kill("SIGKILL")
56
+ }
57
+ }
package/esm/server.js CHANGED
@@ -74,16 +74,18 @@ class Server {
74
74
  delete: ["/monitor/:pid"],
75
75
  })
76
76
  }
77
+
77
78
  su() {
78
79
  const app = express()
79
80
  app.use(bodyParser.json())
80
81
  this.launch("SU", app, { get: ["/", "/timestamp", "/:pid"] })
81
82
  }
83
+
82
84
  cu() {
83
85
  const app = express()
84
86
  app.use(bodyParser.json())
85
87
  this.launch("CU", app, {
86
- get: ["/", "/result/:mid", "/state/:pid", "/results/:pid"],
88
+ get: ["/", "/result/:mid", "/state/:pid", "/results/:pid", "/dry-run"],
87
89
  post: ["/result/:mid", "/dry-run"],
88
90
  })
89
91
  }
@@ -100,6 +102,7 @@ class Server {
100
102
  }
101
103
  }
102
104
  }
105
+
103
106
  req(req, device, path) {
104
107
  return {
105
108
  path,