wao 0.26.1 → 0.27.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/hb.js CHANGED
@@ -8,6 +8,7 @@ var _aoconnect = require("@permaweb/aoconnect");
8
8
  var _ramda = require("ramda");
9
9
  var _utils = require("./utils.js");
10
10
  var _signer = require("./signer.js");
11
+ var _send3 = require("./send.js");
11
12
  var _hyperAos = _interopRequireDefault(require("./lua/hyper-aos.js"));
12
13
  var _aos_wamr = _interopRequireDefault(require("./lua/aos_wamr.js"));
13
14
  var _excluded = ["path"];
@@ -268,7 +269,7 @@ var HB = /*#__PURE__*/function () {
268
269
  value: function _init(jwk) {
269
270
  this.signer = (0, _aoconnect.createSigner)(jwk, this.url);
270
271
  this.addr = (0, _utils.toAddr)(jwk.n);
271
- this.sign = (0, _signer.createRequest)({
272
+ this.sign = (0, _signer.signer)({
272
273
  signer: this.signer,
273
274
  url: this.url
274
275
  });
@@ -289,16 +290,23 @@ var HB = /*#__PURE__*/function () {
289
290
  while (1) switch (_context8.prev = _context8.next) {
290
291
  case 0:
291
292
  this._init(jwk);
292
- _context8.next = 3;
293
+ _context8.prev = 1;
294
+ _context8.next = 4;
293
295
  return this.dev.meta.info({});
294
- case 3:
296
+ case 4:
295
297
  this._info = _context8.sent;
298
+ _context8.next = 9;
299
+ break;
300
+ case 7:
301
+ _context8.prev = 7;
302
+ _context8.t0 = _context8["catch"](1);
303
+ case 9:
296
304
  return _context8.abrupt("return", this);
297
- case 5:
305
+ case 10:
298
306
  case "end":
299
307
  return _context8.stop();
300
308
  }
301
- }, _callee8, this);
309
+ }, _callee8, this, [[1, 7]]);
302
310
  }));
303
311
  function init(_x6) {
304
312
  return _init2.apply(this, arguments);
@@ -313,7 +321,7 @@ var HB = /*#__PURE__*/function () {
313
321
  while (1) switch (_context9.prev = _context9.next) {
314
322
  case 0:
315
323
  _context9.next = 2;
316
- return (0, _signer.send)(msg);
324
+ return (0, _send3.send)(msg);
317
325
  case 2:
318
326
  return _context9.abrupt("return", _context9.sent);
319
327
  case 3:
package/cjs/hyperbeam.js CHANGED
@@ -25,13 +25,13 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
25
25
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
26
  var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
27
27
  function HyperBEAM() {
28
+ var _as2;
28
29
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
29
30
  _ref$port = _ref.port,
30
31
  port = _ref$port === void 0 ? 10001 : _ref$port,
31
32
  _ref$cu = _ref.cu,
32
33
  cu = _ref$cu === void 0 ? 6363 : _ref$cu,
33
- _ref$as = _ref.as,
34
- as = _ref$as === void 0 ? ["genesis_wasm"] : _ref$as,
34
+ as = _ref.as,
35
35
  bundler = _ref.bundler,
36
36
  gateway = _ref.gateway,
37
37
  wallet = _ref.wallet,
@@ -48,8 +48,11 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
48
48
  store_prefix = _ref.store_prefix,
49
49
  operator = _ref.operator,
50
50
  _ref$console = _ref.console,
51
- console = _ref$console === void 0 ? true : _ref$console;
51
+ console = _ref$console === void 0 ? true : _ref$console,
52
+ _ref$shell = _ref.shell,
53
+ shell = _ref$shell === void 0 ? true : _ref$shell;
52
54
  _classCallCheck(this, HyperBEAM);
55
+ (_as2 = as) !== null && _as2 !== void 0 ? _as2 : as = shell ? [] : ["genesis_wasm"];
53
56
  this.console = console;
54
57
  if (clearCache) {
55
58
  var dirname = (0, _path.resolve)(process.cwd(), cwd);
@@ -90,13 +93,14 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
90
93
  this.gateway = gateway;
91
94
  this.wallet = wallet;
92
95
  this.cwd = cwd;
93
- this.run();
96
+ if (shell) this.shell();
94
97
  }
95
98
  return _createClass(HyperBEAM, [{
96
- key: "run",
97
- value: function run() {
99
+ key: "shell",
100
+ value: function shell() {
101
+ var _this = this;
98
102
  var _as = this.as.length === 0 ? [] : ["as", this.as.join(", ")];
99
- this.hbeam = (0, _child_process.spawn)("rebar3", [].concat(_as, ["shell", "--eval", this.genEval({
103
+ this._shell = (0, _child_process.spawn)("rebar3", [].concat(_as, ["shell", "--eval", this.genEval({
100
104
  gateway: this.gateway,
101
105
  wallet: this.wallet
102
106
  })]), {
@@ -104,20 +108,87 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
104
108
  cwd: (0, _path.resolve)(process.cwd(), this.cwd)
105
109
  });
106
110
  if (this.console) {
107
- this.hbeam.stdout.on("data", function (chunk) {
111
+ this._shell.stdout.on("data", function (chunk) {
108
112
  return console.log(chunk.toString());
109
113
  });
110
- this.hbeam.stderr.on("data", function (err) {
114
+ this._shell.stderr.on("data", function (err) {
111
115
  return console.error(err.toString());
112
116
  });
113
- this.hbeam.on("error", function (err) {
117
+ this._shell.on("error", function (err) {
114
118
  return console.error("failed to start process: ".concat(err));
115
119
  });
116
- this.hbeam.on("close", function (code) {
117
- return console.log("child process exited with code ".concat(code));
120
+ this._shell.on("close", function (code) {
121
+ console.log("child process exited with code ".concat(code));
122
+ delete _this._shell;
118
123
  });
119
124
  }
120
125
  }
126
+ }, {
127
+ key: "eunit",
128
+ value: function eunit(module, test) {
129
+ var _this2 = this;
130
+ return new Promise(function (res) {
131
+ var isTest = !(0, _ramda.isNil)(test);
132
+ if (Array.isArray(module)) {
133
+ var _iterator2 = _createForOfIteratorHelper(module),
134
+ _step2;
135
+ try {
136
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
137
+ var v = _step2.value;
138
+ if (Array.isArray(v) || /:/.test(v)) {
139
+ isTest = true;
140
+ break;
141
+ }
142
+ }
143
+ } catch (err) {
144
+ _iterator2.e(err);
145
+ } finally {
146
+ _iterator2.f();
147
+ }
148
+ }
149
+ var _as = _this2.as.length === 0 ? [] : ["as", _this2.as.join(", ")];
150
+ var _test = Array.isArray(test) ? test.join("+") : test;
151
+ var _module = "";
152
+ if (Array.isArray(module)) {
153
+ var _iterator3 = _createForOfIteratorHelper(module),
154
+ _step3;
155
+ try {
156
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
157
+ var _v = _step3.value;
158
+ _module += _module === "" ? "" : ",";
159
+ if (Array.isArray(_v)) _module += "".concat(_v[0], ":").concat(_v[1].join("+"));else _module += _v;
160
+ }
161
+ } catch (err) {
162
+ _iterator3.e(err);
163
+ } finally {
164
+ _iterator3.f();
165
+ }
166
+ } else {
167
+ _module = test ? "".concat(module, ":").concat(_test) : module;
168
+ }
169
+ var _arg = isTest ? "--test" : "--module";
170
+ var params = [].concat(_as, ["eunit", _arg, _module]);
171
+ var _eunit = (0, _child_process.spawn)("rebar3", params, {
172
+ env: _objectSpread(_objectSpread({}, process.env), _this2.genEnv()),
173
+ cwd: (0, _path.resolve)(process.cwd(), _this2.cwd)
174
+ });
175
+ if (_this2.console) {
176
+ _eunit.stdout.on("data", function (chunk) {
177
+ return console.log(chunk.toString());
178
+ });
179
+ _eunit.stderr.on("data", function (err) {
180
+ return console.error(err.toString());
181
+ });
182
+ _eunit.on("error", function (err) {
183
+ return console.error("failed to start process: ".concat(err));
184
+ });
185
+ _eunit.on("close", function (code) {
186
+ console.log("child process exited with code ".concat(code));
187
+ res();
188
+ });
189
+ }
190
+ });
191
+ }
121
192
  }, {
122
193
  key: "ok",
123
194
  value: function () {
@@ -153,7 +224,7 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
153
224
  key: "ready",
154
225
  value: function () {
155
226
  var _ready = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
156
- var _this = this;
227
+ var _this3 = this;
157
228
  var timeout,
158
229
  start,
159
230
  _args3 = arguments;
@@ -178,14 +249,14 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
178
249
  break;
179
250
  case 6:
180
251
  _context2.next = 8;
181
- return _this.ok();
252
+ return _this3.ok();
182
253
  case 8:
183
254
  if (!_context2.sent) {
184
255
  _context2.next = 11;
185
256
  break;
186
257
  }
187
258
  clearInterval(to);
188
- res(_this);
259
+ res(_this3);
189
260
  case 11:
190
261
  _context2.next = 15;
191
262
  break;
@@ -214,6 +285,7 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
214
285
  key: "genEnv",
215
286
  value: function genEnv() {
216
287
  var _env = {};
288
+ if (this.diagnostic) _env.DIAGNOSTIC = this.diagnostic;
217
289
  if (this.c) {
218
290
  _env.CC = "gcc-".concat(this.c);
219
291
  _env.CXX = "g++-".concat(this.c);
@@ -252,7 +324,7 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
252
324
  }, {
253
325
  key: "kill",
254
326
  value: function kill() {
255
- this.hbeam.kill("SIGKILL");
327
+ this._shell.kill("SIGKILL");
256
328
  }
257
329
  }]);
258
330
  }();
package/cjs/send.js ADDED
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.send = send;
8
+ exports.toHttpSigner = void 0;
9
+ var _base64url = _interopRequireDefault(require("base64url"));
10
+ var _httpMessageSignatures = require("http-message-signatures");
11
+ var _structuredHeaders = require("structured-headers");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
14
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
18
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
20
+ 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."); }
21
+ 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; } }
22
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
23
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
24
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
26
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
27
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
28
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
30
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
31
+ var augmentHeaders = _httpMessageSignatures.httpbis.augmentHeaders,
32
+ createSignatureBase = _httpMessageSignatures.httpbis.createSignatureBase,
33
+ createSigningParameters = _httpMessageSignatures.httpbis.createSigningParameters,
34
+ formatSignatureBase = _httpMessageSignatures.httpbis.formatSignatureBase;
35
+ function send(_x) {
36
+ return _send.apply(this, arguments);
37
+ }
38
+ function _send() {
39
+ _send = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(signedMsg) {
40
+ var fetchImpl,
41
+ fetchOptions,
42
+ response,
43
+ headers,
44
+ _args2 = arguments;
45
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
46
+ while (1) switch (_context2.prev = _context2.next) {
47
+ case 0:
48
+ fetchImpl = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : fetch;
49
+ fetchOptions = {
50
+ method: signedMsg.method,
51
+ headers: signedMsg.headers,
52
+ redirect: "follow"
53
+ };
54
+ if (signedMsg.body !== undefined && signedMsg.method !== "GET" && signedMsg.method !== "HEAD") {
55
+ fetchOptions.body = signedMsg.body;
56
+ }
57
+ _context2.next = 5;
58
+ return fetchImpl(signedMsg.url, fetchOptions);
59
+ case 5:
60
+ response = _context2.sent;
61
+ if (!(response.status >= 400)) {
62
+ _context2.next = 14;
63
+ break;
64
+ }
65
+ _context2.t0 = Error;
66
+ _context2.t1 = "".concat(response.status, ": ");
67
+ _context2.next = 11;
68
+ return response.text();
69
+ case 11:
70
+ _context2.t2 = _context2.sent;
71
+ _context2.t3 = _context2.t1.concat.call(_context2.t1, _context2.t2);
72
+ throw new _context2.t0(_context2.t3);
73
+ case 14:
74
+ headers = {};
75
+ if (response.headers && typeof response.headers.forEach === "function") {
76
+ response.headers.forEach(function (v, k) {
77
+ return headers[k] = v;
78
+ });
79
+ } else headers = response.headers;
80
+ _context2.t4 = response;
81
+ _context2.t5 = headers;
82
+ _context2.next = 20;
83
+ return response.text();
84
+ case 20:
85
+ _context2.t6 = _context2.sent;
86
+ _context2.t7 = response.status;
87
+ return _context2.abrupt("return", {
88
+ response: _context2.t4,
89
+ headers: _context2.t5,
90
+ body: _context2.t6,
91
+ status: _context2.t7
92
+ });
93
+ case 23:
94
+ case "end":
95
+ return _context2.stop();
96
+ }
97
+ }, _callee2);
98
+ }));
99
+ return _send.apply(this, arguments);
100
+ }
101
+ var httpSigName = function httpSigName(address) {
102
+ var decoded = _base64url["default"].toBuffer(address);
103
+ var hexString = _toConsumableArray(decoded.subarray(1, 9)).map(function (_byte) {
104
+ return _byte.toString(16).padStart(2, "0");
105
+ }).join("");
106
+ return "http-sig-".concat(hexString);
107
+ };
108
+ var toView = function toView(value) {
109
+ if (ArrayBuffer.isView(value)) {
110
+ return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
111
+ } else if (typeof value === "string") return _base64url["default"].toBuffer(value);
112
+ throw new Error("Value must be Uint8Array, ArrayBuffer, or base64url-encoded string");
113
+ };
114
+ var toHttpSigner = exports.toHttpSigner = function toHttpSigner(signer) {
115
+ var params = ["alg", "keyid"].sort();
116
+ return /*#__PURE__*/function () {
117
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
118
+ var request, fields, signatureBase, signatureInput, createCalled, create, result, signatureBuffer, signedHeaders, finalHeaders, _i, _Object$entries, _Object$entries$_i, key, value;
119
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
120
+ while (1) switch (_context.prev = _context.next) {
121
+ case 0:
122
+ request = _ref.request, fields = _ref.fields;
123
+ createCalled = false;
124
+ create = function create(injected) {
125
+ createCalled = true;
126
+ var publicKey = injected.publicKey,
127
+ _injected$alg = injected.alg,
128
+ alg = _injected$alg === void 0 ? "rsa-pss-sha512" : _injected$alg;
129
+ var publicKeyBuffer = toView(publicKey);
130
+ var signingParameters = createSigningParameters({
131
+ params: params,
132
+ paramValues: {
133
+ keyid: _base64url["default"].encode(publicKeyBuffer),
134
+ alg: alg
135
+ }
136
+ });
137
+ var signatureBaseArray = createSignatureBase({
138
+ fields: fields
139
+ }, request);
140
+ signatureInput = (0, _structuredHeaders.serializeList)([[signatureBaseArray.map(function (_ref3) {
141
+ var _ref4 = _slicedToArray(_ref3, 1),
142
+ item = _ref4[0];
143
+ return (0, _structuredHeaders.parseItem)(item);
144
+ }), signingParameters]]);
145
+ signatureBaseArray.push(['"@signature-params"', [signatureInput]]);
146
+ signatureBase = formatSignatureBase(signatureBaseArray);
147
+ return new TextEncoder().encode(signatureBase);
148
+ };
149
+ _context.next = 5;
150
+ return signer(create, "httpsig");
151
+ case 5:
152
+ result = _context.sent;
153
+ if (createCalled) {
154
+ _context.next = 8;
155
+ break;
156
+ }
157
+ throw new Error("create() must be invoked in order to construct the data to sign");
158
+ case 8:
159
+ if (!(!result.signature || !result.address)) {
160
+ _context.next = 10;
161
+ break;
162
+ }
163
+ throw new Error("Signer must return signature and address");
164
+ case 10:
165
+ signatureBuffer = toView(result.signature);
166
+ signedHeaders = augmentHeaders(request.headers, signatureBuffer, signatureInput, httpSigName(result.address));
167
+ finalHeaders = {};
168
+ for (_i = 0, _Object$entries = Object.entries(signedHeaders); _i < _Object$entries.length; _i++) {
169
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
170
+ if (key === "Signature" || key === "Signature-Input") {
171
+ finalHeaders[key.toLowerCase()] = value;
172
+ } else finalHeaders[key] = value;
173
+ }
174
+ return _context.abrupt("return", _objectSpread(_objectSpread({}, request), {}, {
175
+ headers: finalHeaders
176
+ }));
177
+ case 15:
178
+ case "end":
179
+ return _context.stop();
180
+ }
181
+ }, _callee);
182
+ }));
183
+ return function (_x2) {
184
+ return _ref2.apply(this, arguments);
185
+ };
186
+ }();
187
+ };