wao 0.32.0 → 0.32.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.
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.List = exports.Item = exports.Dictionary = void 0;
7
+ exports.parseHeader = parseHeader;
8
+ exports.quoteString = quoteString;
9
+ var _structuredHeaders = require("structured-headers");
10
+ 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); }
11
+ function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
12
+ 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."); }
13
+ 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; } }
14
+ 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; }
15
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
16
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
17
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
18
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
19
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
21
+ 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); }
22
+ var Dictionary = exports.Dictionary = /*#__PURE__*/function () {
23
+ function Dictionary(input) {
24
+ _classCallCheck(this, Dictionary);
25
+ this.raw = input;
26
+ this.parsed = (0, _structuredHeaders.parseDictionary)(input);
27
+ }
28
+ return _createClass(Dictionary, [{
29
+ key: "toString",
30
+ value: function toString() {
31
+ return this.serialize();
32
+ }
33
+ }, {
34
+ key: "serialize",
35
+ value: function serialize() {
36
+ return (0, _structuredHeaders.serializeDictionary)(this.parsed);
37
+ }
38
+ }, {
39
+ key: "has",
40
+ value: function has(key) {
41
+ return this.parsed.has(key);
42
+ }
43
+ }, {
44
+ key: "get",
45
+ value: function get(key) {
46
+ var value = this.parsed.get(key);
47
+ if (!value) {
48
+ return value;
49
+ }
50
+ if ((0, _structuredHeaders.isInnerList)(value)) {
51
+ return (0, _structuredHeaders.serializeInnerList)(value);
52
+ }
53
+ return (0, _structuredHeaders.serializeItem)(value);
54
+ }
55
+ }]);
56
+ }();
57
+ var List = exports.List = /*#__PURE__*/function () {
58
+ function List(input) {
59
+ _classCallCheck(this, List);
60
+ this.raw = input;
61
+ this.parsed = (0, _structuredHeaders.parseList)(input);
62
+ }
63
+ return _createClass(List, [{
64
+ key: "toString",
65
+ value: function toString() {
66
+ return this.serialize();
67
+ }
68
+ }, {
69
+ key: "serialize",
70
+ value: function serialize() {
71
+ return (0, _structuredHeaders.serializeList)(this.parsed);
72
+ }
73
+ }]);
74
+ }();
75
+ var Item = exports.Item = /*#__PURE__*/function () {
76
+ function Item(input) {
77
+ _classCallCheck(this, Item);
78
+ this.raw = input;
79
+ this.parsed = (0, _structuredHeaders.parseItem)(input);
80
+ }
81
+ return _createClass(Item, [{
82
+ key: "toString",
83
+ value: function toString() {
84
+ return this.serialize();
85
+ }
86
+ }, {
87
+ key: "serialize",
88
+ value: function serialize() {
89
+ return (0, _structuredHeaders.serializeItem)(this.parsed);
90
+ }
91
+ }]);
92
+ }();
93
+ function parseHeader(header) {
94
+ var classes = [List, Dictionary, Item];
95
+ for (var i = 0; i < classes.length; i++) {
96
+ try {
97
+ return new classes[i](header);
98
+ } catch (e) {
99
+ // noop
100
+ }
101
+ }
102
+ throw new Error("Unable to parse header as structured field");
103
+ }
104
+
105
+ /**
106
+ * This allows consumers of the library to supply field specifications that aren't
107
+ * strictly "structured fields". Really a string must start with a `"` but that won't
108
+ * tend to happen in our configs.
109
+ *
110
+ * @param {string} input
111
+ * @returns {string}
112
+ */
113
+ function quoteString(input) {
114
+ // if it's not quoted, attempt to quote
115
+ if (!input.startsWith('"')) {
116
+ // try to split the structured field
117
+ var _input$split = input.split(";"),
118
+ _input$split2 = _toArray(_input$split),
119
+ name = _input$split2[0],
120
+ rest = _input$split2.slice(1);
121
+ // no params, just quote the whole thing
122
+ if (!rest.length) {
123
+ return "\"".concat(name, "\"");
124
+ }
125
+ // quote the first part and put the rest back as it was
126
+ return "\"".concat(name, "\";").concat(rest.join(";"));
127
+ }
128
+ return input;
129
+ }
package/cjs/send.js CHANGED
@@ -4,10 +4,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.httpSigName = void 0;
7
8
  exports.send = send;
8
9
  exports.toHttpSigner = void 0;
9
10
  var _base64url = _interopRequireDefault(require("base64url"));
10
- var _httpMessageSignatures = require("http-message-signatures");
11
+ var _index = require("./http-message-signatures/index.js");
11
12
  var _structuredHeaders = require("structured-headers");
12
13
  var _httpsig = require("./httpsig.js");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
@@ -29,10 +30,10 @@ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(
29
30
  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; }
30
31
  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); }
31
32
  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); }); }; }
32
- var augmentHeaders = _httpMessageSignatures.httpbis.augmentHeaders,
33
- createSignatureBase = _httpMessageSignatures.httpbis.createSignatureBase,
34
- createSigningParameters = _httpMessageSignatures.httpbis.createSigningParameters,
35
- formatSignatureBase = _httpMessageSignatures.httpbis.formatSignatureBase;
33
+ var augmentHeaders = _index.httpbis.augmentHeaders,
34
+ createSignatureBase = _index.httpbis.createSignatureBase,
35
+ createSigningParameters = _index.httpbis.createSigningParameters,
36
+ formatSignatureBase = _index.httpbis.formatSignatureBase;
36
37
  function send(_x) {
37
38
  return _send.apply(this, arguments);
38
39
  }
@@ -99,7 +100,7 @@ function _send() {
99
100
  }));
100
101
  return _send.apply(this, arguments);
101
102
  }
102
- var httpSigName = function httpSigName(address) {
103
+ var httpSigName = exports.httpSigName = function httpSigName(address) {
103
104
  var decoded = _base64url["default"].toBuffer(address);
104
105
  var hexString = _toConsumableArray(decoded.subarray(1, 9)).map(function (_byte) {
105
106
  return _byte.toString(16).padStart(2, "0");
@@ -135,8 +136,11 @@ var toHttpSigner = exports.toHttpSigner = function toHttpSigner(signer) {
135
136
  alg: alg
136
137
  }
137
138
  });
139
+
140
+ // SORT THE FIELDS HERE to match Erlang's lists:sort(maps:keys(Enc))
141
+ var sortedFields = _toConsumableArray(fields).sort();
138
142
  var signatureBaseArray = createSignatureBase({
139
- fields: fields
143
+ fields: sortedFields
140
144
  }, request);
141
145
  signatureInput = (0, _structuredHeaders.serializeList)([[signatureBaseArray.map(function (_ref3) {
142
146
  var _ref4 = _slicedToArray(_ref3, 1),
@@ -11,7 +11,7 @@ exports.toHttpSigner = void 0;
11
11
  exports.verify = verify;
12
12
  var _base64url = _interopRequireDefault(require("base64url"));
13
13
  var _crypto = _interopRequireDefault(require("crypto"));
14
- var _httpMessageSignatures = require("http-message-signatures");
14
+ var _index = require("./http-message-signatures/index.js");
15
15
  var _structuredHeaders = require("structured-headers");
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
17
17
  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; }
@@ -34,11 +34,11 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
34
34
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
35
35
  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; } }
36
36
  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; }
37
- var augmentHeaders = _httpMessageSignatures.httpbis.augmentHeaders,
38
- createSignatureBase = _httpMessageSignatures.httpbis.createSignatureBase,
39
- createSigningParameters = _httpMessageSignatures.httpbis.createSigningParameters,
40
- formatSignatureBase = _httpMessageSignatures.httpbis.formatSignatureBase;
41
- var verifyMessage = _httpMessageSignatures.httpbis.verifyMessage;
37
+ var augmentHeaders = _index.httpbis.augmentHeaders,
38
+ createSignatureBase = _index.httpbis.createSignatureBase,
39
+ createSigningParameters = _index.httpbis.createSigningParameters,
40
+ formatSignatureBase = _index.httpbis.formatSignatureBase;
41
+ var verifyMessage = _index.httpbis.verifyMessage;
42
42
 
43
43
  /**
44
44
  * Decode signature-input header to extract all components
package/cjs/signer.js CHANGED
@@ -45,7 +45,7 @@ function _sign2() {
45
45
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
46
46
  while (1) switch (_context2.prev = _context2.next) {
47
47
  case 0:
48
- url = _ref2.url, path = _ref2.path, encoded = _ref2.msg, jwk = _ref2.jwk, _ref2$signPath = _ref2.signPath, signPath = _ref2$signPath === void 0 ? false : _ref2$signPath;
48
+ url = _ref2.url, path = _ref2.path, encoded = _ref2.msg, jwk = _ref2.jwk, _ref2$signPath = _ref2.signPath, signPath = _ref2$signPath === void 0 ? true : _ref2$signPath;
49
49
  signer = (0, _aoconnect.createSigner)(jwk, url);
50
50
  _encoded$body = encoded.body, body = _encoded$body === void 0 ? null : _encoded$body, headers = _objectWithoutProperties(encoded, _excluded2);
51
51
  _enc = {
@@ -75,16 +75,17 @@ function _sign(_x2) {
75
75
  }
76
76
  function _sign3() {
77
77
  _sign3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
78
- var encoded, signer, path, url, _ref3$method, method, _ref3$_path, _path, headersObj, body, _url, bodySize, lowercaseHeaders, _i, _Object$entries, _Object$entries$_i, key, value, bodyKeys, signingFields, signedRequest, finalHeaders, _i2, _Object$entries2, _Object$entries2$_i, _key, _value, result;
78
+ var encoded, signer, path, url, _ref3$method, method, _ref3$_path, _path, headersObj, body, url_path, _url, bodySize, lowercaseHeaders, _i, _Object$entries, _Object$entries$_i, key, value, bodyKeys, isPath, signingFields, signedRequest, finalHeaders, _i2, _Object$entries2, _Object$entries2$_i, _key, _value, result;
79
79
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
80
80
  while (1) switch (_context3.prev = _context3.next) {
81
81
  case 0:
82
- encoded = _ref3.encoded, signer = _ref3.signer, path = _ref3.path, url = _ref3.url, _ref3$method = _ref3.method, method = _ref3$method === void 0 ? "POST" : _ref3$method, _ref3$_path = _ref3._path, _path = _ref3$_path === void 0 ? false : _ref3$_path;
82
+ encoded = _ref3.encoded, signer = _ref3.signer, path = _ref3.path, url = _ref3.url, _ref3$method = _ref3.method, method = _ref3$method === void 0 ? "POST" : _ref3$method, _ref3$_path = _ref3._path, _path = _ref3$_path === void 0 ? true : _ref3$_path;
83
83
  headersObj = encoded ? encoded.headers : {};
84
84
  body = encoded ? encoded.body : undefined;
85
+ url_path = typeof _path === "string" ? _path : path;
85
86
  _url = joinUrl({
86
87
  url: url,
87
- path: path
88
+ path: url_path
88
89
  });
89
90
  headersObj["path"] = path;
90
91
  if (body && !headersObj["content-length"]) {
@@ -99,17 +100,13 @@ function _sign3() {
99
100
  bodyKeys = headersObj["body-keys"] ? headersObj["body-keys"].replace(/"/g, "").split(",").map(function (k) {
100
101
  return k.trim();
101
102
  }) : [];
103
+ isPath = false;
102
104
  signingFields = Object.keys(lowercaseHeaders).filter(function (key) {
105
+ if (key === "path") isPath = true;
103
106
  return key !== "body-keys" && key !== "path" && !bodyKeys.includes(key);
104
107
  });
105
- if (_path) signingFields.push("path");
106
- /*
107
- if (signingFields.length === 0 && !body) {
108
- //lowercaseHeaders["content-length"] = "0"
109
- //signingFields.push("content-length")
110
- }
111
- */
112
- _context3.next = 13;
108
+ if (_path !== false && isPath) signingFields.push("@path");
109
+ _context3.next = 15;
113
110
  return (0, _send.toHttpSigner)(signer)({
114
111
  request: {
115
112
  url: _url,
@@ -118,7 +115,7 @@ function _sign3() {
118
115
  },
119
116
  fields: signingFields
120
117
  });
121
- case 13:
118
+ case 15:
122
119
  signedRequest = _context3.sent;
123
120
  finalHeaders = {};
124
121
  for (_i2 = 0, _Object$entries2 = Object.entries(headersObj); _i2 < _Object$entries2.length; _i2++) {
@@ -137,7 +134,7 @@ function _sign3() {
137
134
  };
138
135
  if (body) result.body = body;
139
136
  return _context3.abrupt("return", result);
140
- case 22:
137
+ case 24:
141
138
  case "end":
142
139
  return _context3.stop();
143
140
  }
@@ -167,7 +164,7 @@ function signer(config) {
167
164
  return _regeneratorRuntime().wrap(function _callee$(_context) {
168
165
  while (1) switch (_context.prev = _context.next) {
169
166
  case 0:
170
- _ref5 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref5$encoded = _ref5.encoded, _encoded = _ref5$encoded === void 0 ? false : _ref5$encoded, _ref5$path = _ref5.path, _path = _ref5$path === void 0 ? false : _ref5$path;
167
+ _ref5 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref5$encoded = _ref5.encoded, _encoded = _ref5$encoded === void 0 ? false : _ref5$encoded, _ref5$path = _ref5.path, _path = _ref5$path === void 0 ? true : _ref5$path;
171
168
  _fields$path = fields.path, path = _fields$path === void 0 ? "/relay/process" : _fields$path, _fields$method = fields.method, method = _fields$method === void 0 ? "POST" : _fields$method, aoFields = _objectWithoutProperties(fields, _excluded);
172
169
  if (!_encoded) {
173
170
  _context.next = 6;
@@ -9,6 +9,6 @@
9
9
  "deploy": "node scripts/deploy.js"
10
10
  },
11
11
  "dependencies": {
12
- "wao": "^0.32.0"
12
+ "wao": "^0.32.2"
13
13
  }
14
14
  }
package/esm/hb.js CHANGED
@@ -53,6 +53,7 @@ class HB {
53
53
  if (!this._info) {
54
54
  try {
55
55
  this._info = await this.g("/~meta@1.0/info")
56
+ this.operator = this._info.address
56
57
  } catch (e) {}
57
58
  }
58
59
  }
@@ -81,23 +82,6 @@ class HB {
81
82
  return id
82
83
  }
83
84
 
84
- async scheduleAOS({ pid, action = "Eval", tags = {}, data }) {
85
- pid ??= this.pid
86
- let _tags = mergeLeft(tags, {
87
- device: "process@1.0",
88
- method: "POST",
89
- path: `/${pid}~process@1.0/schedule`,
90
- scheduler: this.scheduler,
91
- type: "Message",
92
- Action: action,
93
- target: pid,
94
- })
95
- if (data) _tags.data = data
96
- let res = await this.post(_tags)
97
- const slot = res.headers.slot
98
- return { slot, res, pid }
99
- }
100
-
101
85
  async messageAOS(args) {
102
86
  const { slot, pid } = await this.scheduleAOS(args)
103
87
  return { slot, outbox: await this.computeAOS({ pid, slot }) }
@@ -126,30 +110,15 @@ class HB {
126
110
  return JSON.parse(json.results.json.body)
127
111
  }
128
112
 
129
- async spawn(tags = {}) {
130
- const addr = await this.g("/~meta@1.0/info/address")
131
- this.scheduler ??= addr
132
- const _tags = mergeLeft(tags, {
133
- device: "process@1.0",
134
- path: "/schedule",
135
- scheduler: this.scheduler,
136
- "random-seed": seed(16),
137
- type: "Process",
138
- "execution-device": "test-device@1.0",
139
- })
140
- const res = await this.post(_tags)
141
- return { res, pid: res.headers.process }
142
- }
143
-
144
113
  async cacheScript(data, type = "application/lua") {
145
114
  if (!this.cache) {
146
115
  const { pid } = await this.spawn({})
147
116
  this.cache = pid
148
117
  }
149
- const { slot } = await this.schedule({
118
+ const { slot } = await this.scheduleFlat({
150
119
  data,
151
120
  pid: this.cache,
152
- "content-type": type,
121
+ tags: { "content-type": type },
153
122
  })
154
123
  const msgs = await this.messages({ pid: this.cache, from: slot, limit: 1 })
155
124
  return msgs.edges[0].node.message.Id
@@ -157,7 +126,7 @@ class HB {
157
126
 
158
127
  async cacheBinary(data, type) {
159
128
  const res = await this.post({ path: "/~wao@1.0/cache_module", data, type })
160
- return res.headers.id
129
+ return res.out.id
161
130
  }
162
131
 
163
132
  async message(args) {
@@ -167,91 +136,48 @@ class HB {
167
136
  return { slot, pid, res }
168
137
  }
169
138
 
170
- async scheduleLegacy({
171
- pid,
172
- action = "Eval",
173
- tags = {},
174
- data,
175
- scheduler,
176
- } = {}) {
177
- if (action) tags.Action = action
178
- return await this.schedule({ pid, tags, data, scheduler })
139
+ async scheduleFlat({ pid, tags = {}, data } = {}) {
140
+ let _tags = mergeLeft(tags, { type: "Message", target: pid })
141
+ if (data) _tags.data = data
142
+ let res = await this.post({ path: "/~process@1.0/schedule", body: _tags })
143
+ return { slot: res.out.slot, res, pid }
179
144
  }
180
145
 
181
- async scheduleLua(...args) {
182
- return await this.scheduleLegacy(...args)
146
+ async scheduleNP({ pid, tags = {}, data } = {}) {
147
+ if (data) tags.data = data
148
+ let res = await this.post({
149
+ path: `/${pid}~node-process@1.0/schedule`,
150
+ body: await this.commit(tags),
151
+ })
152
+ return { slot: res.out.slot, res, pid }
183
153
  }
184
-
185
154
  async schedule({ pid, tags = {}, data } = {}) {
186
- pid ??= this.pid
187
- let _tags = mergeLeft(tags, {
188
- method: "POST",
155
+ let _tags = mergeLeft(tags, { type: "Message", target: pid })
156
+ if (data) _tags.data = data
157
+ let res = await this.post({
189
158
  path: `/${pid}/schedule`,
190
- type: "Message",
191
- target: pid,
159
+ body: await this.commit(_tags, { path: false }),
192
160
  })
193
- if (data) _tags.data = data
194
- let res = await this.post(_tags)
195
- return { slot: res.headers.slot, res, pid }
161
+ return { slot: res.out.slot, res, pid }
196
162
  }
197
163
 
198
- async spawnAOS(image) {
199
- const addr = await this.g("/~meta@1.0/info/address")
200
- this.scheduler ??= addr
201
- image ??= this.image ?? (await this.getImage())
202
- const res = await this.post({
203
- device: "process@1.0",
204
- path: "/schedule",
205
- scheduler: this.scheduler,
206
- "data-protocol": "ao",
207
- variant: "ao.N.1",
208
- "scheduler-location": this.scheduler,
209
- authority: this.scheduler,
210
- "random-seed": seed(16),
211
- type: "Process",
212
- image,
213
- "execution-device": "stack@1.0",
214
- "push-device": "push@1.0",
215
- "device-stack": [
216
- "wasi@1.0",
217
- "json-iface@1.0",
218
- "wasm-64@1.0",
219
- "patch@1.0",
220
- "multipass@1.0",
221
- ],
222
- "output-prefix": "wasm",
223
- "patch-from": "/results/outbox",
224
- "patch-mode": "patches",
225
- "stack-keys": ["init", "compute", "snapshot", "normalize"],
226
- passes: 2,
227
- })
228
- const pid = res.headers.process
229
- this.pid ??= pid
230
- return { pid, res }
164
+ async scheduleLua({ action = "Eval", tags = {}, ...rest }) {
165
+ if (action) tags.Action = action
166
+ return await this.schedule({ tags, ...rest })
231
167
  }
232
168
 
233
169
  async spawnLua(lua) {
234
- const addr = await this.g("/~meta@1.0/info/address")
235
- this.scheduler ??= addr
236
- lua ??= this.lua ?? (await this.getLua())
237
- const res = await this.post({
238
- device: "process@1.0",
239
- path: "/schedule",
240
- scheduler: this.scheduler,
170
+ await this.setInfo()
171
+ const tags = {
241
172
  "data-protocol": "ao",
242
173
  variant: "ao.N.1",
243
- "scheduler-location": this.scheduler,
244
- authority: this.scheduler,
245
- "random-seed": seed(16),
246
- type: "Process",
247
- module: lua,
174
+ authority: this.operator,
175
+ module: this.lua ?? (await this.getLua()),
248
176
  "execution-device": "lua@5.3a",
249
177
  "push-device": "push@1.0",
250
178
  "patch-from": "/results/outbox",
251
- })
252
- const pid = res.headers.process
253
- this.pid ??= pid
254
- return { pid, res }
179
+ }
180
+ return this.spawn(tags)
255
181
  }
256
182
 
257
183
  async now({ pid, path = "" }) {
@@ -280,29 +206,42 @@ class HB {
280
206
  }
281
207
  return res
282
208
  }
283
-
209
+ async spawn(tags = {}) {
210
+ const res = await this.post({
211
+ path: "/~process@1.0/schedule",
212
+ body: await this.commit(
213
+ mergeLeft(tags, {
214
+ "random-seed": seed(16),
215
+ type: "Process",
216
+ "execution-device": "test-device@1.0",
217
+ device: "process@1.0",
218
+ scheduler: this.addr,
219
+ }),
220
+ { path: false }
221
+ ),
222
+ scheduler: this.operator,
223
+ })
224
+ return { res, pid: res.out.process }
225
+ }
284
226
  async spawnLegacy({ module, tags = {}, data } = {}) {
285
227
  await this.setInfo()
286
- let t = {
287
- type: "Process",
228
+ let t = mergeLeft(tags, {
288
229
  "data-protocol": "ao",
289
230
  variant: "ao.TN.1",
290
- scheduler: this._info.address,
291
231
  authority: this._info.address,
292
- "scheduler-location": this._info.address,
293
- "random-seed": seed(16),
294
232
  module: module ?? "ISShJH1ij-hPPt9St5UFFr_8Ys3Kj5cyg7zrMGt7H9s",
295
233
  device: "process@1.0",
296
- "scheduler-device": "scheduler@1.0",
297
234
  "execution-device": "stack@1.0",
298
235
  "push-device": "push@1.0",
299
236
  "device-stack": ["genesis-wasm@1.0", "patch@1.0"],
300
237
  "patch-from": "/results/outbox",
301
- "stack-keys": ["init", "compute", "snapshot", "normalize"],
302
- }
238
+ })
303
239
  if (data) t.data = data
304
- tags = mergeLeft(tags, t)
305
- return await this.spawn(tags)
240
+ return await this.spawn(t)
241
+ }
242
+ async scheduleLegacy({ action = "Eval", tags = {}, ...rest } = {}) {
243
+ if (action) tags.Action = action
244
+ return await this.schedule({ tags, ...rest })
306
245
  }
307
246
 
308
247
  async results({ process, limit, sort = "DESC", from, to } = {}) {
@@ -365,10 +304,11 @@ class HB {
365
304
  return (await this.post(..._args))?.out ?? null
366
305
  }
367
306
 
368
- async post(obj, json) {
369
- const _json = json ? "/~json@1.0/serialize" : ""
307
+ async post(obj, opt = {}) {
308
+ const _json = opt.json ? "/~json@1.0/serialize" : ""
370
309
  obj.path += _json
371
- return await this.send(await this.sign(obj))
310
+ const signed = await this.sign(obj, opt)
311
+ return await this.send(signed)
372
312
  }
373
313
 
374
314
  async g(path, ...args) {
@@ -378,8 +318,8 @@ class HB {
378
318
  return (await this.get(..._args))?.out ?? null
379
319
  }
380
320
 
381
- async get({ path, ...params }, json = false) {
382
- const _json = json ? "/~json@1.0/serialize" : ""
321
+ async get({ path, ...params }, opt = {}) {
322
+ const _json = opt.json ? "/~json@1.0/serialize" : ""
383
323
  path ??= "/~message@1.0"
384
324
  if (!/^\//.test(path)) path = "/" + path
385
325
  let _params = ""
@@ -404,15 +344,44 @@ class HB {
404
344
  }
405
345
  }
406
346
 
407
- async postJSON(args) {
408
- const res = await this.post(args, true)
347
+ async postJSON(args, opt = {}) {
348
+ const res = await this.post(args, { ...opt, json: true })
409
349
  return JSON.parse(res.body)
410
350
  }
411
351
 
412
- async getJSON(args) {
413
- const res = await this.get(args, true)
352
+ async getJSON(args, opt = {}) {
353
+ const res = await this.get(args, { ...opt, json: true })
414
354
  return JSON.parse(res.body)
415
355
  }
356
+ async spawnAOS(image) {
357
+ await this.setInfo()
358
+ image ??= this.image ?? (await this.getImage())
359
+ const tags = {
360
+ "data-protocol": "ao",
361
+ variant: "ao.N.1",
362
+ authority: this.operator,
363
+ image,
364
+ "execution-device": "stack@1.0",
365
+ "push-device": "push@1.0",
366
+ "device-stack": [
367
+ "wasi@1.0",
368
+ "json-iface@1.0",
369
+ "wasm-64@1.0",
370
+ "patch@1.0",
371
+ "multipass@1.0",
372
+ ],
373
+ "output-prefix": "wasm",
374
+ "patch-from": "/results/outbox",
375
+ "patch-mode": "patches",
376
+ passes: 2,
377
+ }
378
+ return await this.spawn(tags)
379
+ }
380
+
381
+ async scheduleAOS({ action = "Eval", tags = {}, ...rest }) {
382
+ if (action) tags.Action = action
383
+ return await this.schedule({ tags, ...rest })
384
+ }
416
385
  }
417
386
 
418
387
  export default HB