wao 0.29.1 → 0.29.3
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/devs.js +122 -110
- package/cjs/encode.js +4 -24
- package/cjs/hb.js +1 -3
- package/cjs/httpsig.js +51 -17
- package/cjs/hyperbeam.js +1 -0
- package/cjs/send.js +1 -7
- package/cjs/signer.js +148 -116
- package/cjs/workspace/package.json +1 -1
- package/esm/devs.js +56 -33
- package/esm/encode.js +2 -5
- package/esm/hb.js +1 -1
- package/esm/httpsig.js +39 -17
- package/esm/hyperbeam.js +1 -1
- package/esm/send.js +1 -7
- package/esm/signer.js +72 -76
- package/esm/workspace/package.json +1 -1
- package/package.json +1 -1
package/cjs/signer.js
CHANGED
|
@@ -4,22 +4,20 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
exports.sign = sign;
|
|
7
8
|
exports.signer = signer;
|
|
8
9
|
var _send = require("./send.js");
|
|
9
10
|
var _encode = require("./encode.js");
|
|
10
|
-
var
|
|
11
|
-
|
|
11
|
+
var _aoconnect = require("@permaweb/aoconnect");
|
|
12
|
+
var _excluded = ["path", "method"],
|
|
13
|
+
_excluded2 = ["body"];
|
|
12
14
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
15
|
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."); }
|
|
14
16
|
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; } }
|
|
15
17
|
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; }
|
|
16
18
|
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; } }
|
|
17
19
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
18
|
-
function
|
|
19
|
-
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; }
|
|
20
|
-
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; }
|
|
21
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
22
|
-
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); }
|
|
20
|
+
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; }
|
|
23
21
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
24
22
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
25
23
|
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); }
|
|
@@ -27,140 +25,174 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
27
25
|
var joinUrl = function joinUrl(_ref) {
|
|
28
26
|
var url = _ref.url,
|
|
29
27
|
path = _ref.path;
|
|
30
|
-
if (path.startsWith("http://") || path.startsWith("https://"))
|
|
31
|
-
return path;
|
|
32
|
-
}
|
|
33
|
-
// Ensure path starts with /
|
|
28
|
+
if (path.startsWith("http://") || path.startsWith("https://")) return path;
|
|
34
29
|
var normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
35
30
|
return url.endsWith("/") ? url.slice(0, -1) + normalizedPath : url + normalizedPath;
|
|
36
31
|
};
|
|
32
|
+
function sign(_x) {
|
|
33
|
+
return _sign2.apply(this, arguments);
|
|
34
|
+
}
|
|
35
|
+
function _sign2() {
|
|
36
|
+
_sign2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
37
|
+
var url, path, encoded, jwk, _ref2$signPath, signPath, signer, _encoded$body, body, headers, _enc;
|
|
38
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
39
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
url = _ref2.url, path = _ref2.path, encoded = _ref2.msg, jwk = _ref2.jwk, _ref2$signPath = _ref2.signPath, signPath = _ref2$signPath === void 0 ? false : _ref2$signPath;
|
|
42
|
+
signer = (0, _aoconnect.createSigner)(jwk, url);
|
|
43
|
+
_encoded$body = encoded.body, body = _encoded$body === void 0 ? null : _encoded$body, headers = _objectWithoutProperties(encoded, _excluded2);
|
|
44
|
+
_enc = {
|
|
45
|
+
headers: headers
|
|
46
|
+
};
|
|
47
|
+
if (body) _enc.body = new Blob([body]);
|
|
48
|
+
_context2.next = 7;
|
|
49
|
+
return _sign({
|
|
50
|
+
signer: signer,
|
|
51
|
+
encoded: _enc,
|
|
52
|
+
url: url,
|
|
53
|
+
path: path,
|
|
54
|
+
_path: signPath
|
|
55
|
+
});
|
|
56
|
+
case 7:
|
|
57
|
+
return _context2.abrupt("return", _context2.sent);
|
|
58
|
+
case 8:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context2.stop();
|
|
61
|
+
}
|
|
62
|
+
}, _callee2);
|
|
63
|
+
}));
|
|
64
|
+
return _sign2.apply(this, arguments);
|
|
65
|
+
}
|
|
66
|
+
function _sign(_x2) {
|
|
67
|
+
return _sign3.apply(this, arguments);
|
|
68
|
+
}
|
|
69
|
+
function _sign3() {
|
|
70
|
+
_sign3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
|
|
71
|
+
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;
|
|
72
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
73
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
74
|
+
case 0:
|
|
75
|
+
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;
|
|
76
|
+
headersObj = encoded ? encoded.headers : {};
|
|
77
|
+
body = encoded ? encoded.body : undefined;
|
|
78
|
+
_url = joinUrl({
|
|
79
|
+
url: url,
|
|
80
|
+
path: path
|
|
81
|
+
});
|
|
82
|
+
headersObj["path"] = path;
|
|
83
|
+
if (body && !headersObj["content-length"]) {
|
|
84
|
+
bodySize = body.size || body.byteLength || 0;
|
|
85
|
+
if (bodySize > 0) headersObj["content-length"] = String(bodySize);
|
|
86
|
+
}
|
|
87
|
+
lowercaseHeaders = {};
|
|
88
|
+
for (_i = 0, _Object$entries = Object.entries(headersObj); _i < _Object$entries.length; _i++) {
|
|
89
|
+
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
90
|
+
lowercaseHeaders[key.toLowerCase()] = value;
|
|
91
|
+
}
|
|
92
|
+
bodyKeys = headersObj["body-keys"] ? headersObj["body-keys"].replace(/"/g, "").split(",").map(function (k) {
|
|
93
|
+
return k.trim();
|
|
94
|
+
}) : [];
|
|
95
|
+
signingFields = Object.keys(lowercaseHeaders).filter(function (key) {
|
|
96
|
+
return key !== "body-keys" && key !== "path" && !bodyKeys.includes(key);
|
|
97
|
+
});
|
|
98
|
+
if (_path) signingFields.push("path");
|
|
99
|
+
if (signingFields.length === 0 && !body) {
|
|
100
|
+
lowercaseHeaders["content-length"] = "0";
|
|
101
|
+
signingFields.push("content-length");
|
|
102
|
+
}
|
|
103
|
+
_context3.next = 14;
|
|
104
|
+
return (0, _send.toHttpSigner)(signer)({
|
|
105
|
+
request: {
|
|
106
|
+
url: _url,
|
|
107
|
+
method: method,
|
|
108
|
+
headers: lowercaseHeaders
|
|
109
|
+
},
|
|
110
|
+
fields: signingFields
|
|
111
|
+
});
|
|
112
|
+
case 14:
|
|
113
|
+
signedRequest = _context3.sent;
|
|
114
|
+
finalHeaders = {};
|
|
115
|
+
for (_i2 = 0, _Object$entries2 = Object.entries(headersObj); _i2 < _Object$entries2.length; _i2++) {
|
|
116
|
+
_Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), _key = _Object$entries2$_i[0], _value = _Object$entries2$_i[1];
|
|
117
|
+
finalHeaders[_key] = _value;
|
|
118
|
+
}
|
|
119
|
+
finalHeaders["signature"] = signedRequest.headers["signature"];
|
|
120
|
+
finalHeaders["signature-input"] = signedRequest.headers["signature-input"];
|
|
121
|
+
if (headersObj["body-keys"]) {
|
|
122
|
+
finalHeaders["body-keys"] = headersObj["body-keys"];
|
|
123
|
+
}
|
|
124
|
+
result = {
|
|
125
|
+
url: _url,
|
|
126
|
+
method: method,
|
|
127
|
+
headers: finalHeaders
|
|
128
|
+
};
|
|
129
|
+
if (body) result.body = body;
|
|
130
|
+
return _context3.abrupt("return", result);
|
|
131
|
+
case 23:
|
|
132
|
+
case "end":
|
|
133
|
+
return _context3.stop();
|
|
134
|
+
}
|
|
135
|
+
}, _callee3);
|
|
136
|
+
}));
|
|
137
|
+
return _sign3.apply(this, arguments);
|
|
138
|
+
}
|
|
37
139
|
function signer(config) {
|
|
38
140
|
var signer = config.signer,
|
|
39
141
|
_config$url = config.url,
|
|
40
142
|
url = _config$url === void 0 ? "http://localhost:10001" : _config$url;
|
|
41
|
-
if (!signer)
|
|
42
|
-
throw new Error("Signer is required for mainnet mode");
|
|
43
|
-
}
|
|
143
|
+
if (!signer) throw new Error("Signer is required for mainnet mode");
|
|
44
144
|
return /*#__PURE__*/function () {
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
|
|
145
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(fields) {
|
|
146
|
+
var _ref5,
|
|
147
|
+
_ref5$encoded,
|
|
148
|
+
_encoded,
|
|
149
|
+
_ref5$path,
|
|
48
150
|
_path,
|
|
49
151
|
_fields$path,
|
|
50
152
|
path,
|
|
51
153
|
_fields$method,
|
|
52
154
|
method,
|
|
53
|
-
restFields,
|
|
54
155
|
aoFields,
|
|
55
156
|
encoded,
|
|
56
|
-
headersObj,
|
|
57
|
-
body,
|
|
58
|
-
_url,
|
|
59
|
-
bodySize,
|
|
60
|
-
lowercaseHeaders,
|
|
61
|
-
_i,
|
|
62
|
-
_Object$entries,
|
|
63
|
-
_Object$entries$_i,
|
|
64
|
-
key,
|
|
65
|
-
value,
|
|
66
|
-
bodyKeys,
|
|
67
|
-
signingFields,
|
|
68
|
-
signedRequest,
|
|
69
|
-
finalHeaders,
|
|
70
|
-
_i2,
|
|
71
|
-
_Object$entries2,
|
|
72
|
-
_Object$entries2$_i,
|
|
73
|
-
_key,
|
|
74
|
-
_value,
|
|
75
|
-
result,
|
|
76
157
|
_args = arguments;
|
|
77
158
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
78
159
|
while (1) switch (_context.prev = _context.next) {
|
|
79
160
|
case 0:
|
|
80
|
-
|
|
81
|
-
_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,
|
|
82
|
-
|
|
83
|
-
|
|
161
|
+
_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;
|
|
162
|
+
_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);
|
|
163
|
+
if (!_encoded) {
|
|
164
|
+
_context.next = 6;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
_context.t0 = aoFields;
|
|
168
|
+
_context.next = 9;
|
|
169
|
+
break;
|
|
170
|
+
case 6:
|
|
171
|
+
_context.next = 8;
|
|
84
172
|
return (0, _encode.enc)(aoFields);
|
|
85
|
-
case
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
173
|
+
case 8:
|
|
174
|
+
_context.t0 = _context.sent;
|
|
175
|
+
case 9:
|
|
176
|
+
encoded = _context.t0;
|
|
177
|
+
_context.next = 12;
|
|
178
|
+
return _sign({
|
|
90
179
|
url: url,
|
|
91
|
-
path: path
|
|
92
|
-
});
|
|
93
|
-
headersObj["path"] = path;
|
|
94
|
-
if (body && !headersObj["content-length"]) {
|
|
95
|
-
bodySize = body.size || body.byteLength || 0;
|
|
96
|
-
if (bodySize > 0) {
|
|
97
|
-
headersObj["content-length"] = String(bodySize);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
lowercaseHeaders = {};
|
|
101
|
-
for (_i = 0, _Object$entries = Object.entries(headersObj); _i < _Object$entries.length; _i++) {
|
|
102
|
-
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
103
|
-
lowercaseHeaders[key.toLowerCase()] = value;
|
|
104
|
-
}
|
|
105
|
-
if (lowercaseHeaders.path && /^\//.test(lowercaseHeaders.path)) {
|
|
106
|
-
//const sp = lowercaseHeaders.path.split("/")
|
|
107
|
-
//lowercaseHeaders.path = sp.slice(sp.length - 1).join("/")
|
|
108
|
-
}
|
|
109
|
-
// Parse body-keys if present
|
|
110
|
-
bodyKeys = headersObj["body-keys"] ? headersObj["body-keys"].replace(/"/g, "").split(",").map(function (k) {
|
|
111
|
-
return k.trim();
|
|
112
|
-
}) : []; // Collect fields to sign from headers
|
|
113
|
-
signingFields = Object.keys(lowercaseHeaders).filter(function (key) {
|
|
114
|
-
return key !== "body-keys" && key !== "path" && !bodyKeys.includes(key);
|
|
115
|
-
} // Also exclude fields that are in body-keys
|
|
116
|
-
); // Always include @path in the signature
|
|
117
|
-
//if (!signingFields.includes("path")) signingFields.push("path")
|
|
118
|
-
|
|
119
|
-
if (_path) signingFields.push("path");
|
|
120
|
-
// Ensure we have at least one field to sign
|
|
121
|
-
if (signingFields.length === 0 && !body) {
|
|
122
|
-
lowercaseHeaders["content-length"] = "0";
|
|
123
|
-
signingFields.push("content-length");
|
|
124
|
-
}
|
|
125
|
-
_context.next = 20;
|
|
126
|
-
return (0, _send.toHttpSigner)(signer)({
|
|
127
|
-
request: {
|
|
128
|
-
url: _url,
|
|
129
|
-
method: method,
|
|
130
|
-
headers: lowercaseHeaders
|
|
131
|
-
},
|
|
132
|
-
fields: signingFields
|
|
133
|
-
});
|
|
134
|
-
case 20:
|
|
135
|
-
signedRequest = _context.sent;
|
|
136
|
-
finalHeaders = {};
|
|
137
|
-
for (_i2 = 0, _Object$entries2 = Object.entries(headersObj); _i2 < _Object$entries2.length; _i2++) {
|
|
138
|
-
_Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), _key = _Object$entries2$_i[0], _value = _Object$entries2$_i[1];
|
|
139
|
-
finalHeaders[_key] = _value;
|
|
140
|
-
}
|
|
141
|
-
finalHeaders["signature"] = signedRequest.headers["signature"];
|
|
142
|
-
finalHeaders["signature-input"] = signedRequest.headers["signature-input"];
|
|
143
|
-
if (headersObj["body-keys"]) {
|
|
144
|
-
finalHeaders["body-keys"] = headersObj["body-keys"];
|
|
145
|
-
}
|
|
146
|
-
result = {
|
|
147
|
-
url: _url,
|
|
148
180
|
method: method,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
181
|
+
path: path,
|
|
182
|
+
_path: _path,
|
|
183
|
+
encoded: encoded,
|
|
184
|
+
signer: signer
|
|
185
|
+
});
|
|
186
|
+
case 12:
|
|
187
|
+
return _context.abrupt("return", _context.sent);
|
|
188
|
+
case 13:
|
|
154
189
|
case "end":
|
|
155
190
|
return _context.stop();
|
|
156
191
|
}
|
|
157
192
|
}, _callee);
|
|
158
193
|
}));
|
|
159
|
-
function
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
return sign;
|
|
194
|
+
return function (_x3) {
|
|
195
|
+
return _ref4.apply(this, arguments);
|
|
196
|
+
};
|
|
163
197
|
}();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// stack / simple-pay / patch / hyperbeam / hyperbeam-aos / scheduler / cron
|
|
198
|
+
}
|
package/esm/devs.js
CHANGED
|
@@ -1,47 +1,70 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
// fundamental
|
|
3
|
+
meta: { name: "meta@1.0", module: "dev_meta" },
|
|
4
|
+
json: { name: "json@1.0", module: "dev_codec_json" },
|
|
5
|
+
flat: { name: "flat@1.0", module: "dev_codec_flat" },
|
|
6
|
+
httpsig: { name: "httpsig@1.0", module: "dev_codec_httpsig" },
|
|
7
|
+
structured: { name: "structured@1.0", module: "dev_codec_structured" },
|
|
8
|
+
wao: { name: "wao@1.0", module: "dev_wao" },
|
|
9
|
+
|
|
10
|
+
// process
|
|
11
|
+
process: { name: "process@1.0", module: "dev_process" },
|
|
12
|
+
message: { name: "message@1.0", module: "dev_message" },
|
|
13
|
+
scheduler: { name: "scheduler@1.0", module: "dev_scheduler" },
|
|
14
|
+
|
|
15
|
+
// legacynet aos
|
|
8
16
|
"delegated-compute": {
|
|
9
17
|
name: "delegated-compute@1.0",
|
|
10
18
|
module: "dev_delegated_compute",
|
|
11
19
|
},
|
|
12
|
-
faff: { name: "faff@1.0", module: "dev_faff" },
|
|
13
|
-
flat: { name: "flat@1.0", module: "dev_codec_flat" },
|
|
14
20
|
"genesis-wasm": { name: "genesis-wasm@1.0", module: "dev_genesis_wasm" },
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
hyperbuddy: { name: "hyperbuddy@1.0", module: "dev_hyperbuddy" },
|
|
18
|
-
json: { name: "json@1.0", module: "dev_codec_json" },
|
|
19
|
-
"json-iface": { name: "json-iface@1.0", module: "dev_json_iface" },
|
|
20
|
-
"local-name": { name: "local-name@1.0", module: "dev_local_name" },
|
|
21
|
-
lookup: { name: "lookup@1.0", module: "dev_lookup" },
|
|
21
|
+
|
|
22
|
+
// hyper aos
|
|
22
23
|
lua: { name: "lua@5.3a", module: "dev_lua" },
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
|
|
25
|
+
// mainnet aos
|
|
26
|
+
wasi: { name: "wasi@1.0", module: "dev_wasi" },
|
|
27
|
+
"wasm-64": { name: "wasm-64@1.0", module: "dev_wasm" },
|
|
28
|
+
"json-iface": { name: "json-iface@1.0", module: "dev_json_iface" },
|
|
29
|
+
|
|
30
|
+
// process utils
|
|
31
|
+
"test-device": { name: "test-device@1.0", module: "dev_test" },
|
|
31
32
|
patch: { name: "patch@1.0", module: "dev_patch" },
|
|
32
|
-
poda: { name: "poda@1.0", module: "dev_poda" },
|
|
33
|
-
process: { name: "process@1.0", module: "dev_process" },
|
|
34
33
|
push: { name: "push@1.0", module: "dev_push" },
|
|
34
|
+
stack: { name: "stack@1.0", module: "dev_stack" },
|
|
35
|
+
multipass: { name: "multipass@1.0", module: "dev_multipass" },
|
|
36
|
+
|
|
37
|
+
// payment
|
|
38
|
+
faff: { name: "faff@1.0", module: "dev_faff" },
|
|
39
|
+
p4: { name: "p4@1.0", module: "dev_p4" },
|
|
40
|
+
"node-process": { name: "node-process@1.0", module: "dev_node_process" },
|
|
41
|
+
"simple-pay": { name: "simple-pay@1.0", module: "dev_simple_pay" },
|
|
42
|
+
|
|
43
|
+
// tested
|
|
44
|
+
cron: { name: "cron@1.0", module: "dev_cron" },
|
|
35
45
|
relay: { name: "relay@1.0", module: "dev_relay" },
|
|
36
46
|
router: { name: "router@1.0", module: "dev_router" },
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
|
|
48
|
+
// storage
|
|
49
|
+
cache: { name: "cache@1.0", module: "dev_cache" },
|
|
50
|
+
"local-name": { name: "local-name@1.0", module: "dev_local_name" },
|
|
51
|
+
lookup: { name: "lookup@1.0", module: "dev_lookup" },
|
|
52
|
+
name: { name: "name@1.0", module: "dev_name" },
|
|
53
|
+
|
|
54
|
+
// others
|
|
55
|
+
compute: { name: "compute@1.0", module: "dev_cu" },
|
|
56
|
+
dedup: { name: "dedup@1.0", module: "dev_dedup" },
|
|
57
|
+
manifest: { name: "manifest@1.0", module: "dev_manifest" },
|
|
58
|
+
monitor: { name: "monitor@1.0", module: "dev_monitor" },
|
|
59
|
+
|
|
60
|
+
// advanced
|
|
39
61
|
snp: { name: "snp@1.0", module: "dev_snp" },
|
|
40
|
-
stack: { name: "stack@1.0", module: "dev_stack" },
|
|
41
|
-
structured: { name: "structured@1.0", module: "dev_codec_structured" },
|
|
42
|
-
"test-device": { name: "test-device@1.0", module: "dev_test" },
|
|
43
62
|
volume: { name: "volume@1.0", module: "dev_volume" },
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
poda: { name: "poda@1.0", module: "dev_poda" },
|
|
64
|
+
greenzone: { name: "greenzone@1.0", module: "dev_green_zone" },
|
|
65
|
+
|
|
66
|
+
// misc
|
|
67
|
+
hyperbuddy: { name: "hyperbuddy@1.0", module: "dev_hyperbuddy" },
|
|
68
|
+
ans104: { name: "ans104@1.0", module: "dev_codec_ans104" },
|
|
69
|
+
cacheviz: { name: "cacheviz@1.0", module: "dev_cacheviz" },
|
|
47
70
|
}
|
package/esm/encode.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
isBytes,
|
|
15
15
|
isPojo,
|
|
16
16
|
} from "./encode-utils.js"
|
|
17
|
+
|
|
17
18
|
import encodeArrayItem from "./encode-array-item.js"
|
|
18
19
|
import collectBodyKeys from "./collect-body-keys.js"
|
|
19
20
|
const MAX_HEADER_LENGTH = 4096
|
|
@@ -1100,7 +1101,7 @@ function setFinalHeaders(headers, boundary, contentDigest, byteLength) {
|
|
|
1100
1101
|
headers["content-length"] = String(byteLength)
|
|
1101
1102
|
}
|
|
1102
1103
|
|
|
1103
|
-
async function
|
|
1104
|
+
export async function enc(obj = {}) {
|
|
1104
1105
|
// Step 1: Process and normalize input values
|
|
1105
1106
|
const processedObj = processInputValues(obj)
|
|
1106
1107
|
|
|
@@ -1213,7 +1214,3 @@ async function encode(obj = {}) {
|
|
|
1213
1214
|
// Step 18: Return result
|
|
1214
1215
|
return { headers, body }
|
|
1215
1216
|
}
|
|
1216
|
-
|
|
1217
|
-
export async function enc(fields) {
|
|
1218
|
-
return await encode(fields)
|
|
1219
|
-
}
|
package/esm/hb.js
CHANGED
package/esm/httpsig.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { trim } from "ramda"
|
|
2
2
|
import { decodeSigInput } from "./signer-utils.js"
|
|
3
3
|
import base64url from "base64url"
|
|
4
|
-
|
|
4
|
+
import { toAddr } from "./utils.js"
|
|
5
5
|
/**
|
|
6
6
|
* Get multipart boundary from content-type header
|
|
7
7
|
*/
|
|
@@ -319,7 +319,10 @@ const toJSON = msg => {
|
|
|
319
319
|
for (const [key, value] of Object.entries(result)) {
|
|
320
320
|
// Skip internal keys and headers we don't want in the final result
|
|
321
321
|
if (key.startsWith("__")) continue
|
|
322
|
-
|
|
322
|
+
|
|
323
|
+
// Skip @ fields EXCEPT @path which we want to include
|
|
324
|
+
if (key.startsWith("@") && key !== "@path") continue
|
|
325
|
+
|
|
323
326
|
if (key === "ao-types") continue
|
|
324
327
|
if (key === "content-type") continue
|
|
325
328
|
if (key === "content-digest") continue
|
|
@@ -853,11 +856,6 @@ const stringToBuffer = str => {
|
|
|
853
856
|
return buffer
|
|
854
857
|
}
|
|
855
858
|
|
|
856
|
-
/**
|
|
857
|
-
* Original from function - extracts and converts only signed components
|
|
858
|
-
* @param {Object} http - HTTP message object with headers, body, and status
|
|
859
|
-
* @returns {Object|null} Converted signed components or null if not signed
|
|
860
|
-
*/
|
|
861
859
|
export const from = http => {
|
|
862
860
|
const input =
|
|
863
861
|
http.headers["signature-input"] || http.headers["Signature-Input"]
|
|
@@ -867,36 +865,60 @@ export const from = http => {
|
|
|
867
865
|
|
|
868
866
|
// Decode signature inputs
|
|
869
867
|
const inputs = decodeSigInput(input)
|
|
870
|
-
|
|
871
868
|
// Process the first signature (following the original logic)
|
|
872
869
|
for (const k in inputs) {
|
|
873
870
|
const sigData = inputs[k]
|
|
874
|
-
|
|
875
871
|
// Extract only the signed components
|
|
876
872
|
const extractedComponents = extract(http, sigData.components)
|
|
873
|
+
let ret = { hashpath: sigData?.params?.tag ?? null }
|
|
874
|
+
try {
|
|
875
|
+
ret.signer = toAddr(sigData.params.keyid)
|
|
876
|
+
} catch (e) {}
|
|
877
|
+
|
|
878
|
+
// Check if @path was in the signed components
|
|
879
|
+
const hasPathComponent = sigData.components.some(
|
|
880
|
+
c => c.replace(/"/g, "") === "@path"
|
|
881
|
+
)
|
|
882
|
+
|
|
883
|
+
// If @path is signed, add the path header to extracted components
|
|
884
|
+
if (hasPathComponent) {
|
|
885
|
+
extractedComponents["path"] = http.headers.path
|
|
886
|
+
}
|
|
877
887
|
|
|
878
|
-
// Check if ao-result header is present
|
|
888
|
+
// Check if ao-result header is present
|
|
879
889
|
const aoResult = http.headers["ao-result"] || http.headers["Ao-Result"]
|
|
880
|
-
|
|
890
|
+
|
|
891
|
+
// Handle ao-result pointing to body
|
|
892
|
+
if (aoResult === "body") {
|
|
893
|
+
// Handle empty body case
|
|
894
|
+
if (!extractedComponents.body) {
|
|
895
|
+
return { out: "", ...ret } // Return empty string for empty body
|
|
896
|
+
}
|
|
881
897
|
// Check if body is binary data
|
|
882
898
|
if (isBinaryString(extractedComponents.body)) {
|
|
883
|
-
return stringToBuffer(extractedComponents.body)
|
|
899
|
+
return { out: stringToBuffer(extractedComponents.body), ...ret }
|
|
884
900
|
}
|
|
901
|
+
// Return body as-is if it's not binary
|
|
902
|
+
return { out: extractedComponents.body, ...ret }
|
|
885
903
|
}
|
|
886
904
|
|
|
887
905
|
// Convert the extracted components to JSON format
|
|
888
906
|
const result = toJSON(extractedComponents)
|
|
889
907
|
|
|
890
|
-
// Handle ao-result if present
|
|
891
|
-
if (aoResult &&
|
|
908
|
+
// Handle ao-result if present and pointing to other fields
|
|
909
|
+
if (aoResult && aoResult !== "body") {
|
|
892
910
|
// Return the value of the key specified by ao-result
|
|
893
|
-
return
|
|
911
|
+
// If the key doesn't exist, return undefined (or could return null/empty string)
|
|
912
|
+
return {
|
|
913
|
+
out: result[aoResult] !== undefined ? result[aoResult] : "",
|
|
914
|
+
...ret,
|
|
915
|
+
}
|
|
894
916
|
}
|
|
895
917
|
|
|
896
|
-
return result
|
|
918
|
+
return { out: result, ...ret }
|
|
897
919
|
}
|
|
898
920
|
|
|
899
|
-
return null
|
|
921
|
+
return { out: null, hashpath: null }
|
|
900
922
|
}
|
|
901
923
|
|
|
902
924
|
/**
|
package/esm/hyperbeam.js
CHANGED
|
@@ -182,7 +182,6 @@ export default class HyperBEAM {
|
|
|
182
182
|
}
|
|
183
183
|
_devices = `, preloaded_devices => [${_devs.join(", ")}]`
|
|
184
184
|
}
|
|
185
|
-
|
|
186
185
|
const _wallet = `, priv_key_location => <<"${wallet}">>`
|
|
187
186
|
const _gateway = gateway
|
|
188
187
|
? `, gateway => <<"http://localhost:${gateway}">>`
|
|
@@ -227,6 +226,7 @@ export default class HyperBEAM {
|
|
|
227
226
|
? `, on => #{ <<"request">> => #{ <<"device">> => <<"p4@1.0">>, <<"pricing-device">> => <<"faff@1.0">>, <<"ledger-device">> => <<"faff@1.0">> }, <<"response">> => #{ <<"device">> => <<"p4@1.0">>, <<"pricing-device">> => <<"faff@1.0">>, <<"ledger-device">> => <<"faff@1.0">> } }`
|
|
228
227
|
: ""
|
|
229
228
|
const start = `hb:start_mainnet(#{ ${_port}${_gateway}${_wallet}${_faff}${_bundler}${_on}${_p4_non_chargable}${_operator}${_spp}${_devices}${_node_processes}}).`
|
|
229
|
+
console.log(start)
|
|
230
230
|
return start
|
|
231
231
|
}
|
|
232
232
|
|