wao 0.26.2 → 0.27.1
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/encode.js +1522 -0
- package/cjs/hb.js +14 -6
- package/cjs/hyperbeam.js +88 -16
- package/cjs/send.js +187 -0
- package/cjs/signer.js +36 -822
- package/cjs/workspace/test/hyperbeam.js +6 -9
- package/esm/encode.js +1199 -0
- package/esm/hb.js +6 -3
- package/esm/hyperbeam.js +58 -10
- package/esm/send.js +126 -0
- package/esm/signer.js +5 -651
- package/esm/workspace/test/hyperbeam.js +6 -9
- package/package.json +1 -1
package/cjs/signer.js
CHANGED
|
@@ -1,102 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
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); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _base64url = _interopRequireDefault(require("base64url"));
|
|
10
|
-
var _fastSha = require("fast-sha256");
|
|
11
|
-
var _httpMessageSignatures = require("http-message-signatures");
|
|
12
|
-
var _structuredHeaders = require("structured-headers");
|
|
7
|
+
exports.signer = signer;
|
|
8
|
+
var _send = require("./send.js");
|
|
9
|
+
var _encode = require("./encode.js");
|
|
13
10
|
var _excluded = ["path", "method"];
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
15
|
-
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; } } }; }
|
|
16
|
-
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; }
|
|
17
|
-
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; }
|
|
18
11
|
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; }
|
|
12
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
|
+
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
|
+
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
|
+
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
|
+
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
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
19
18
|
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; }
|
|
20
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; }
|
|
21
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; }
|
|
22
21
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
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); }
|
|
24
|
-
function
|
|
25
|
-
function
|
|
26
|
-
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; } }
|
|
27
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
23
|
+
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
|
+
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; }
|
|
28
25
|
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); }
|
|
29
26
|
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); }); }; }
|
|
30
|
-
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
31
|
-
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."); }
|
|
32
|
-
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; } }
|
|
33
|
-
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
34
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
35
|
-
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; }
|
|
36
|
-
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); }
|
|
37
|
-
var verifyMessage = _httpMessageSignatures.httpbis.verifyMessage;
|
|
38
|
-
var augmentHeaders = _httpMessageSignatures.httpbis.augmentHeaders,
|
|
39
|
-
createSignatureBase = _httpMessageSignatures.httpbis.createSignatureBase,
|
|
40
|
-
createSigningParameters = _httpMessageSignatures.httpbis.createSigningParameters,
|
|
41
|
-
formatSignatureBase = _httpMessageSignatures.httpbis.formatSignatureBase;
|
|
42
|
-
function hbEncodeValue(value) {
|
|
43
|
-
if (isBytes(value)) {
|
|
44
|
-
if (value.byteLength === 0) return hbEncodeValue("");
|
|
45
|
-
return [undefined, value];
|
|
46
|
-
}
|
|
47
|
-
if (typeof value === "string") {
|
|
48
|
-
if (value.length === 0) return ["empty-binary", undefined];
|
|
49
|
-
return [undefined, value];
|
|
50
|
-
}
|
|
51
|
-
if (Array.isArray(value)) {
|
|
52
|
-
if (value.length === 0) return ["empty-list", undefined];
|
|
53
|
-
if (value.some(isPojo)) {
|
|
54
|
-
throw new Error("Array with objects should have been lifted: ".concat(JSON.stringify(value)));
|
|
55
|
-
}
|
|
56
|
-
var encoded = value.map(function (v) {
|
|
57
|
-
if (typeof v === "string") {
|
|
58
|
-
if (v === "") return "\"(ao-type-empty-binary) \"";
|
|
59
|
-
var escaped = v.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
60
|
-
return "\"".concat(escaped, "\"");
|
|
61
|
-
} else if (typeof v === "number") return String(v);else if (typeof v === "boolean") return v ? "?1" : "?0";else if (_typeof(v) === "symbol") {
|
|
62
|
-
var desc = v.description || "symbol";
|
|
63
|
-
var _escaped = desc.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
64
|
-
return "\"(ao-type-atom) ".concat(_escaped, "\"");
|
|
65
|
-
} else if (v === null) return "\"(ao-type-atom) null\"";else if (v === undefined) return "\"(ao-type-atom) undefined\"";else if (Array.isArray(v) && v.length === 0) {
|
|
66
|
-
return "\"(ao-type-empty-list) \"";
|
|
67
|
-
}
|
|
68
|
-
return "\"".concat(String(v), "\"");
|
|
69
|
-
}).join(", ");
|
|
70
|
-
return ["list", encoded];
|
|
71
|
-
}
|
|
72
|
-
if (typeof value === "number") {
|
|
73
|
-
if (!Number.isInteger(value)) return ["float", "".concat(value)];
|
|
74
|
-
return ["integer", String(value)];
|
|
75
|
-
}
|
|
76
|
-
if (typeof value === "boolean") {
|
|
77
|
-
return ["atom", "\"".concat(value ? "true" : "false", "\"")];
|
|
78
|
-
}
|
|
79
|
-
if (_typeof(value) === "symbol") {
|
|
80
|
-
var desc = value.description || "symbol";
|
|
81
|
-
return ["atom", "\"".concat(desc, "\"")];
|
|
82
|
-
}
|
|
83
|
-
if (value === null) return ["atom", "\"null\""];
|
|
84
|
-
if (value === undefined) return ["atom", "\"undefined\""];
|
|
85
|
-
throw new Error("Cannot encode value: ".concat(String(value)));
|
|
86
|
-
}
|
|
87
|
-
var toView = function toView(value) {
|
|
88
|
-
if (ArrayBuffer.isView(value)) {
|
|
89
|
-
return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
|
90
|
-
} else if (typeof value === "string") return _base64url["default"].toBuffer(value);
|
|
91
|
-
throw new Error("Value must be Uint8Array, ArrayBuffer, or base64url-encoded string");
|
|
92
|
-
};
|
|
93
|
-
var httpSigName = function httpSigName(address) {
|
|
94
|
-
var decoded = _base64url["default"].toBuffer(address);
|
|
95
|
-
var hexString = _toConsumableArray(decoded.subarray(1, 9)).map(function (_byte) {
|
|
96
|
-
return _byte.toString(16).padStart(2, "0");
|
|
97
|
-
}).join("");
|
|
98
|
-
return "http-sig-".concat(hexString);
|
|
99
|
-
};
|
|
100
27
|
var joinUrl = function joinUrl(_ref) {
|
|
101
28
|
var url = _ref.url,
|
|
102
29
|
path = _ref.path;
|
|
@@ -105,647 +32,7 @@ var joinUrl = function joinUrl(_ref) {
|
|
|
105
32
|
}
|
|
106
33
|
return url.endsWith("/") ? url.slice(0, -1) + path : url + path;
|
|
107
34
|
};
|
|
108
|
-
|
|
109
|
-
function encode_body_keys(bodyKeys) {
|
|
110
|
-
if (!bodyKeys || bodyKeys.length === 0) return "";
|
|
111
|
-
var items = bodyKeys.map(function (key) {
|
|
112
|
-
return "\"".concat(key, "\"");
|
|
113
|
-
});
|
|
114
|
-
var result = items.join(", ");
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
function hasNewline(_x) {
|
|
118
|
-
return _hasNewline.apply(this, arguments);
|
|
119
|
-
}
|
|
120
|
-
function _hasNewline() {
|
|
121
|
-
_hasNewline = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(value) {
|
|
122
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
123
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
124
|
-
case 0:
|
|
125
|
-
if (!(typeof value === "string")) {
|
|
126
|
-
_context3.next = 2;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
return _context3.abrupt("return", value.includes("\n"));
|
|
130
|
-
case 2:
|
|
131
|
-
if (!(value instanceof Blob)) {
|
|
132
|
-
_context3.next = 7;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
_context3.next = 5;
|
|
136
|
-
return value.text();
|
|
137
|
-
case 5:
|
|
138
|
-
value = _context3.sent;
|
|
139
|
-
return _context3.abrupt("return", value.includes("\n"));
|
|
140
|
-
case 7:
|
|
141
|
-
if (!isBytes(value)) {
|
|
142
|
-
_context3.next = 9;
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
return _context3.abrupt("return", Buffer.from(value).includes("\n"));
|
|
146
|
-
case 9:
|
|
147
|
-
return _context3.abrupt("return", false);
|
|
148
|
-
case 10:
|
|
149
|
-
case "end":
|
|
150
|
-
return _context3.stop();
|
|
151
|
-
}
|
|
152
|
-
}, _callee3);
|
|
153
|
-
}));
|
|
154
|
-
return _hasNewline.apply(this, arguments);
|
|
155
|
-
}
|
|
156
|
-
function sha256(_x2) {
|
|
157
|
-
return _sha.apply(this, arguments);
|
|
158
|
-
}
|
|
159
|
-
function _sha() {
|
|
160
|
-
_sha = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(data) {
|
|
161
|
-
var uint8Array, hashResult;
|
|
162
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
163
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
164
|
-
case 0:
|
|
165
|
-
if (!(data instanceof ArrayBuffer)) {
|
|
166
|
-
_context4.next = 4;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
uint8Array = new Uint8Array(data);
|
|
170
|
-
_context4.next = 13;
|
|
171
|
-
break;
|
|
172
|
-
case 4:
|
|
173
|
-
if (!(data instanceof Uint8Array)) {
|
|
174
|
-
_context4.next = 8;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
uint8Array = data;
|
|
178
|
-
_context4.next = 13;
|
|
179
|
-
break;
|
|
180
|
-
case 8:
|
|
181
|
-
if (!ArrayBuffer.isView(data)) {
|
|
182
|
-
_context4.next = 12;
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
uint8Array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
186
|
-
_context4.next = 13;
|
|
187
|
-
break;
|
|
188
|
-
case 12:
|
|
189
|
-
throw new Error("sha256 expects ArrayBuffer or ArrayBufferView");
|
|
190
|
-
case 13:
|
|
191
|
-
// fast-sha256 returns Uint8Array, convert to ArrayBuffer
|
|
192
|
-
hashResult = (0, _fastSha.hash)(uint8Array);
|
|
193
|
-
return _context4.abrupt("return", hashResult.buffer.slice(hashResult.byteOffset, hashResult.byteOffset + hashResult.byteLength));
|
|
194
|
-
case 15:
|
|
195
|
-
case "end":
|
|
196
|
-
return _context4.stop();
|
|
197
|
-
}
|
|
198
|
-
}, _callee4);
|
|
199
|
-
}));
|
|
200
|
-
return _sha.apply(this, arguments);
|
|
201
|
-
}
|
|
202
|
-
function isBytes(value) {
|
|
203
|
-
return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
204
|
-
}
|
|
205
|
-
function isPojo(value) {
|
|
206
|
-
return !isBytes(value) && !Array.isArray(value) && !(value instanceof Blob) && _typeof(value) === "object" && value !== null;
|
|
207
|
-
}
|
|
208
|
-
function hbEncodeLift(obj) {
|
|
209
|
-
var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
210
|
-
var top = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
211
|
-
var _Object$entries$reduc = Object.entries(_objectSpread({}, obj)).reduce(function (acc, _ref2) {
|
|
212
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
213
|
-
key = _ref3[0],
|
|
214
|
-
value = _ref3[1];
|
|
215
|
-
var storageKey = parent ? "".concat(parent, "/").concat(key) : key;
|
|
216
|
-
if (value == null) {
|
|
217
|
-
var _hbEncodeValue = hbEncodeValue(value),
|
|
218
|
-
_hbEncodeValue2 = _slicedToArray(_hbEncodeValue, 2),
|
|
219
|
-
_type = _hbEncodeValue2[0],
|
|
220
|
-
_encoded = _hbEncodeValue2[1];
|
|
221
|
-
if (_encoded !== undefined) acc[0][key] = _encoded;
|
|
222
|
-
if (_type) acc[1][key.toLowerCase()] = _type;
|
|
223
|
-
return acc;
|
|
224
|
-
}
|
|
225
|
-
if (Array.isArray(value)) {
|
|
226
|
-
var hasObjects = value.some(isPojo);
|
|
227
|
-
var hasBinary = value.some(isBytes);
|
|
228
|
-
if (hasObjects || hasBinary) {
|
|
229
|
-
var indexedObj = value.reduce(function (obj, v, idx) {
|
|
230
|
-
return Object.assign(obj, _defineProperty({}, idx, v));
|
|
231
|
-
}, {});
|
|
232
|
-
acc[1][key.toLowerCase()] = "list";
|
|
233
|
-
hbEncodeLift(indexedObj, storageKey, top);
|
|
234
|
-
return acc;
|
|
235
|
-
} else {
|
|
236
|
-
var _hbEncodeValue3 = hbEncodeValue(value),
|
|
237
|
-
_hbEncodeValue4 = _slicedToArray(_hbEncodeValue3, 2),
|
|
238
|
-
_type2 = _hbEncodeValue4[0],
|
|
239
|
-
_encoded2 = _hbEncodeValue4[1];
|
|
240
|
-
if (_type2) acc[1][key.toLowerCase()] = _type2;
|
|
241
|
-
if (_encoded2 !== undefined) acc[0][key] = _encoded2;
|
|
242
|
-
return acc;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
var originalValue = value;
|
|
246
|
-
if (isPojo(value)) {
|
|
247
|
-
if (Object.keys(value).length === 0) {
|
|
248
|
-
acc[1][key.toLowerCase()] = "empty-message";
|
|
249
|
-
return acc;
|
|
250
|
-
}
|
|
251
|
-
var hasComplexValues = Object.values(value).some(function (v) {
|
|
252
|
-
return isPojo(v) || Array.isArray(v) && v.some(function (item) {
|
|
253
|
-
return isPojo(item);
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
if (!hasComplexValues) {
|
|
257
|
-
var items = [];
|
|
258
|
-
var hasAnyNonEmptyValues = Object.values(value).some(function (v) {
|
|
259
|
-
return !(v === null || v === undefined || v === "" || Array.isArray(v) && v.length === 0 || isPojo(v) && Object.keys(v).length === 0);
|
|
260
|
-
});
|
|
261
|
-
Object.entries(value).forEach(function (_ref4) {
|
|
262
|
-
var _ref5 = _slicedToArray(_ref4, 2),
|
|
263
|
-
k = _ref5[0],
|
|
264
|
-
v = _ref5[1];
|
|
265
|
-
var subKey = k.toLowerCase();
|
|
266
|
-
if (v === null) {
|
|
267
|
-
items.push("".concat(subKey, "=\"null\""));
|
|
268
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "atom";
|
|
269
|
-
} else if (v === undefined) {
|
|
270
|
-
items.push("".concat(subKey, "=\"undefined\""));
|
|
271
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "atom";
|
|
272
|
-
} else if (typeof v === "string") {
|
|
273
|
-
if (v === "") {
|
|
274
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "empty-binary";
|
|
275
|
-
} else {
|
|
276
|
-
var escaped = v.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
277
|
-
items.push("".concat(subKey, "=\"").concat(escaped, "\""));
|
|
278
|
-
}
|
|
279
|
-
} else if (typeof v === "number") {
|
|
280
|
-
items.push("".concat(subKey, "=").concat(v));
|
|
281
|
-
if (Number.isInteger(v)) {
|
|
282
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "integer";
|
|
283
|
-
} else {
|
|
284
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "float";
|
|
285
|
-
}
|
|
286
|
-
} else if (typeof v === "boolean") {
|
|
287
|
-
items.push("".concat(subKey, "=").concat(v ? "?1" : "?0"));
|
|
288
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "boolean";
|
|
289
|
-
} else if (_typeof(v) === "symbol") {
|
|
290
|
-
var desc = v.description || "symbol";
|
|
291
|
-
var _escaped2 = desc.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
292
|
-
items.push("".concat(subKey, "=\"").concat(_escaped2, "\""));
|
|
293
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "atom";
|
|
294
|
-
} else if (Array.isArray(v) && !v.some(function (item) {
|
|
295
|
-
return isPojo(item);
|
|
296
|
-
})) {
|
|
297
|
-
if (v.length === 0) {
|
|
298
|
-
items.push("".concat(subKey, "=()"));
|
|
299
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "empty-list";
|
|
300
|
-
} else {
|
|
301
|
-
var listItems = v.map(function (item) {
|
|
302
|
-
if (typeof item === "string") {
|
|
303
|
-
return "\"".concat(item.replace(/\\/g, "\\\\").replace(/"/g, '\\"'), "\"");
|
|
304
|
-
} else if (typeof item === "number") {
|
|
305
|
-
return String(item);
|
|
306
|
-
} else if (typeof item === "boolean") {
|
|
307
|
-
return item ? "?1" : "?0";
|
|
308
|
-
} else if (_typeof(item) === "symbol") {
|
|
309
|
-
var _desc = item.description || "symbol";
|
|
310
|
-
return "\"".concat(_desc.replace(/\\/g, "\\\\").replace(/"/g, '\\"'), "\"");
|
|
311
|
-
} else if (item === null) {
|
|
312
|
-
return "\"null\"";
|
|
313
|
-
} else if (item === undefined) {
|
|
314
|
-
return "\"undefined\"";
|
|
315
|
-
} else {
|
|
316
|
-
return "\"".concat(String(item), "\"");
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
items.push("".concat(subKey, "=(").concat(listItems.join(" "), ")"));
|
|
320
|
-
}
|
|
321
|
-
} else if (isPojo(v) && Object.keys(v).length === 0) {
|
|
322
|
-
items.push("".concat(subKey));
|
|
323
|
-
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "empty-message";
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
var encodedValue = items.join(", ");
|
|
327
|
-
var hasOnlyEmptyValues = Object.entries(value).every(function (_ref6) {
|
|
328
|
-
var _ref7 = _slicedToArray(_ref6, 2),
|
|
329
|
-
k = _ref7[0],
|
|
330
|
-
v = _ref7[1];
|
|
331
|
-
return v === null || v === undefined || v === "" || Array.isArray(v) && v.length === 0 || isPojo(v) && Object.keys(v).length === 0;
|
|
332
|
-
});
|
|
333
|
-
if (!hasAnyNonEmptyValues) {
|
|
334
|
-
acc[1][key.toLowerCase()] = "map";
|
|
335
|
-
} else if (encodedValue === "") {
|
|
336
|
-
acc[1][key.toLowerCase()] = "empty-message";
|
|
337
|
-
} else {
|
|
338
|
-
acc[0][key] = encodedValue;
|
|
339
|
-
acc[1][key.toLowerCase()] = "map";
|
|
340
|
-
}
|
|
341
|
-
} else hbEncodeLift(value, storageKey, top);
|
|
342
|
-
return acc;
|
|
343
|
-
}
|
|
344
|
-
var _hbEncodeValue5 = hbEncodeValue(value),
|
|
345
|
-
_hbEncodeValue6 = _slicedToArray(_hbEncodeValue5, 2),
|
|
346
|
-
type = _hbEncodeValue6[0],
|
|
347
|
-
encoded = _hbEncodeValue6[1];
|
|
348
|
-
if (encoded !== undefined) {
|
|
349
|
-
if (isBytes(encoded)) top[storageKey] = encoded;else {
|
|
350
|
-
acc[0][key] = encoded;
|
|
351
|
-
if (type) acc[1][key.toLowerCase()] = type;
|
|
352
|
-
}
|
|
353
|
-
} else if (type) acc[1][key.toLowerCase()] = type;
|
|
354
|
-
return acc;
|
|
355
|
-
}, [{}, {}]),
|
|
356
|
-
_Object$entries$reduc2 = _slicedToArray(_Object$entries$reduc, 2),
|
|
357
|
-
flattened = _Object$entries$reduc2[0],
|
|
358
|
-
types = _Object$entries$reduc2[1];
|
|
359
|
-
if (Object.keys(flattened).length === 0 && Object.keys(types).length === 0) return top;
|
|
360
|
-
if (Object.keys(types).length > 0) {
|
|
361
|
-
var aoTypeItems = Object.entries(types).map(function (_ref8) {
|
|
362
|
-
var _ref9 = _slicedToArray(_ref8, 2),
|
|
363
|
-
key = _ref9[0],
|
|
364
|
-
value = _ref9[1];
|
|
365
|
-
var safeKey = key.toLowerCase().replace(/[^a-z0-9_\-.*\/]/g, function (c) {
|
|
366
|
-
return "%" + c.charCodeAt(0).toString(16).padStart(2, "0");
|
|
367
|
-
}).replace(/\//g, "%2f");
|
|
368
|
-
return "".concat(safeKey, "=\"").concat(value, "\"");
|
|
369
|
-
});
|
|
370
|
-
aoTypeItems.sort();
|
|
371
|
-
var aoTypes = aoTypeItems.join(", ");
|
|
372
|
-
if (Buffer.from(aoTypes).byteLength > MAX_HEADER_LENGTH) {
|
|
373
|
-
var flatK = parent ? "".concat(parent, "/ao-types") : "ao-types";
|
|
374
|
-
top[flatK] = aoTypes;
|
|
375
|
-
} else flattened["ao-types"] = aoTypes;
|
|
376
|
-
}
|
|
377
|
-
if (parent) top[parent] = flattened;else Object.assign(top, flattened);
|
|
378
|
-
return top;
|
|
379
|
-
}
|
|
380
|
-
function encodePart(name, _ref10) {
|
|
381
|
-
var _ref10$headers = _ref10.headers,
|
|
382
|
-
headers = _ref10$headers === void 0 ? {} : _ref10$headers,
|
|
383
|
-
body = _ref10.body;
|
|
384
|
-
var headerEntries = headers instanceof Headers ? Array.from(headers.entries()) : Object.entries(headers || {});
|
|
385
|
-
var parts = headerEntries.reduce(function (acc, _ref11) {
|
|
386
|
-
var _ref12 = _slicedToArray(_ref11, 2),
|
|
387
|
-
name = _ref12[0],
|
|
388
|
-
value = _ref12[1];
|
|
389
|
-
acc.push("".concat(name, ": "), value, "\r\n");
|
|
390
|
-
return acc;
|
|
391
|
-
}, ["content-disposition: form-data;name=\"".concat(name, "\"\r\n")]);
|
|
392
|
-
if (body) parts.push("\r\n", body);
|
|
393
|
-
return new Blob(parts);
|
|
394
|
-
}
|
|
395
|
-
function encode() {
|
|
396
|
-
return _encode.apply(this, arguments);
|
|
397
|
-
}
|
|
398
|
-
function _encode() {
|
|
399
|
-
_encode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
400
|
-
var obj,
|
|
401
|
-
originalObj,
|
|
402
|
-
flattened,
|
|
403
|
-
bodyKeys,
|
|
404
|
-
headerKeys,
|
|
405
|
-
headers,
|
|
406
|
-
body,
|
|
407
|
-
promoteToBody,
|
|
408
|
-
bodyKey,
|
|
409
|
-
originalValue,
|
|
410
|
-
flattenedValue,
|
|
411
|
-
hasSymbols,
|
|
412
|
-
_hbEncodeValue7,
|
|
413
|
-
_hbEncodeValue8,
|
|
414
|
-
type,
|
|
415
|
-
encoded,
|
|
416
|
-
bodyParts,
|
|
417
|
-
allPartsBuffer,
|
|
418
|
-
hashResult,
|
|
419
|
-
boundary,
|
|
420
|
-
finalParts,
|
|
421
|
-
_iterator,
|
|
422
|
-
_step,
|
|
423
|
-
part,
|
|
424
|
-
finalContent,
|
|
425
|
-
contentDigest,
|
|
426
|
-
base64,
|
|
427
|
-
_args7 = arguments;
|
|
428
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
429
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
430
|
-
case 0:
|
|
431
|
-
obj = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
|
|
432
|
-
if (!(Object.keys(obj).length === 0)) {
|
|
433
|
-
_context7.next = 3;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
return _context7.abrupt("return", {
|
|
437
|
-
headers: {},
|
|
438
|
-
body: undefined
|
|
439
|
-
});
|
|
440
|
-
case 3:
|
|
441
|
-
originalObj = obj;
|
|
442
|
-
flattened = hbEncodeLift(obj);
|
|
443
|
-
bodyKeys = [];
|
|
444
|
-
headerKeys = [];
|
|
445
|
-
_context7.next = 9;
|
|
446
|
-
return Promise.all(Object.keys(flattened).map(/*#__PURE__*/function () {
|
|
447
|
-
var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key) {
|
|
448
|
-
var value, subPart, uint8Array, valueStr;
|
|
449
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
450
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
451
|
-
case 0:
|
|
452
|
-
value = flattened[key];
|
|
453
|
-
if (!isPojo(value)) {
|
|
454
|
-
_context5.next = 10;
|
|
455
|
-
break;
|
|
456
|
-
}
|
|
457
|
-
_context5.next = 4;
|
|
458
|
-
return encode(value);
|
|
459
|
-
case 4:
|
|
460
|
-
subPart = _context5.sent;
|
|
461
|
-
if (subPart) {
|
|
462
|
-
_context5.next = 7;
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
return _context5.abrupt("return");
|
|
466
|
-
case 7:
|
|
467
|
-
bodyKeys.push(key);
|
|
468
|
-
flattened[key] = encodePart(key, subPart);
|
|
469
|
-
return _context5.abrupt("return");
|
|
470
|
-
case 10:
|
|
471
|
-
if (!isBytes(value)) {
|
|
472
|
-
_context5.next = 15;
|
|
473
|
-
break;
|
|
474
|
-
}
|
|
475
|
-
bodyKeys.push(key);
|
|
476
|
-
uint8Array = value instanceof Uint8Array ? value : value instanceof ArrayBuffer ? new Uint8Array(value) : Buffer.isBuffer(value) ? new Uint8Array(value.buffer, value.byteOffset, value.length) : new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
477
|
-
flattened[key] = new Blob(["content-disposition: form-data;name=\"".concat(key, "\"\r\n\r\n"), uint8Array]);
|
|
478
|
-
return _context5.abrupt("return");
|
|
479
|
-
case 15:
|
|
480
|
-
valueStr = String(value);
|
|
481
|
-
_context5.next = 18;
|
|
482
|
-
return hasNewline(valueStr);
|
|
483
|
-
case 18:
|
|
484
|
-
_context5.t2 = _context5.sent;
|
|
485
|
-
if (_context5.t2) {
|
|
486
|
-
_context5.next = 21;
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
_context5.t2 = key.includes("/");
|
|
490
|
-
case 21:
|
|
491
|
-
_context5.t1 = _context5.t2;
|
|
492
|
-
if (_context5.t1) {
|
|
493
|
-
_context5.next = 24;
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
_context5.t1 = Buffer.from(valueStr).byteLength > MAX_HEADER_LENGTH;
|
|
497
|
-
case 24:
|
|
498
|
-
_context5.t0 = _context5.t1;
|
|
499
|
-
if (_context5.t0) {
|
|
500
|
-
_context5.next = 27;
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
_context5.t0 = isPojo(value) && valueStr === "[object Object]";
|
|
504
|
-
case 27:
|
|
505
|
-
if (!_context5.t0) {
|
|
506
|
-
_context5.next = 31;
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
bodyKeys.push(key);
|
|
510
|
-
flattened[key] = new Blob(["content-disposition: form-data;name=\"".concat(key, "\"\r\n\r\n"), value]);
|
|
511
|
-
return _context5.abrupt("return");
|
|
512
|
-
case 31:
|
|
513
|
-
headerKeys.push(key);
|
|
514
|
-
case 32:
|
|
515
|
-
case "end":
|
|
516
|
-
return _context5.stop();
|
|
517
|
-
}
|
|
518
|
-
}, _callee5);
|
|
519
|
-
}));
|
|
520
|
-
return function (_x6) {
|
|
521
|
-
return _ref17.apply(this, arguments);
|
|
522
|
-
};
|
|
523
|
-
}()));
|
|
524
|
-
case 9:
|
|
525
|
-
headers = {};
|
|
526
|
-
headerKeys.forEach(function (key) {
|
|
527
|
-
headers[key] = flattened[key];
|
|
528
|
-
});
|
|
529
|
-
if ("data" in originalObj && !bodyKeys.includes("data")) {
|
|
530
|
-
bodyKeys.push("data");
|
|
531
|
-
delete headers["data"];
|
|
532
|
-
}
|
|
533
|
-
if ("body" in originalObj && !bodyKeys.includes("body")) {
|
|
534
|
-
bodyKeys.push("body");
|
|
535
|
-
delete headers["body"];
|
|
536
|
-
}
|
|
537
|
-
if (bodyKeys.length > 0) {
|
|
538
|
-
headers["body-keys"] = encode_body_keys(bodyKeys);
|
|
539
|
-
}
|
|
540
|
-
body = undefined;
|
|
541
|
-
promoteToBody = true;
|
|
542
|
-
if (!(bodyKeys.length > 0)) {
|
|
543
|
-
_context7.next = 45;
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
if (bodyKeys.length === 1) {
|
|
547
|
-
bodyKey = bodyKeys[0];
|
|
548
|
-
originalValue = originalObj[bodyKey];
|
|
549
|
-
flattenedValue = flattened[bodyKey];
|
|
550
|
-
if (!isPojo(originalValue) || isPojo(originalValue) && typeof flattenedValue === "string") {
|
|
551
|
-
if ((bodyKey === "body" || bodyKey === "data") && isPojo(originalValue) && typeof flattenedValue === "string") {
|
|
552
|
-
body = new Blob([flattenedValue]);
|
|
553
|
-
} else if (Array.isArray(originalValue)) {
|
|
554
|
-
hasSymbols = originalValue.some(function (item) {
|
|
555
|
-
return _typeof(item) === "symbol";
|
|
556
|
-
});
|
|
557
|
-
if (hasSymbols) {
|
|
558
|
-
_hbEncodeValue7 = hbEncodeValue(originalValue), _hbEncodeValue8 = _slicedToArray(_hbEncodeValue7, 2), type = _hbEncodeValue8[0], encoded = _hbEncodeValue8[1];
|
|
559
|
-
body = new Blob([encoded || originalValue.toString()]);
|
|
560
|
-
} else body = new Blob([originalValue.toString()]);
|
|
561
|
-
} else body = new Blob([originalValue || flattenedValue]);
|
|
562
|
-
headers["inline-body-key"] = bodyKey;
|
|
563
|
-
} else promoteToBody = false;
|
|
564
|
-
}
|
|
565
|
-
if (!(!promoteToBody || bodyKeys.length > 1)) {
|
|
566
|
-
_context7.next = 35;
|
|
567
|
-
break;
|
|
568
|
-
}
|
|
569
|
-
_context7.next = 21;
|
|
570
|
-
return Promise.all(bodyKeys.map(/*#__PURE__*/function () {
|
|
571
|
-
var _ref18 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(name) {
|
|
572
|
-
var value, _partBlob, valueToEncode, _hasSymbols, _hbEncodeValue9, _hbEncodeValue10, _type3, _encoded3, partBlob, uint8Array;
|
|
573
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
574
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
575
|
-
case 0:
|
|
576
|
-
if (!(flattened[name] instanceof Blob)) {
|
|
577
|
-
_context6.next = 2;
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
return _context6.abrupt("return", flattened[name]);
|
|
581
|
-
case 2:
|
|
582
|
-
value = originalObj[name] || flattened[name] || "";
|
|
583
|
-
if (!(name === "body" && isPojo(originalObj[name]) && typeof flattened[name] === "string")) {
|
|
584
|
-
_context6.next = 6;
|
|
585
|
-
break;
|
|
586
|
-
}
|
|
587
|
-
_partBlob = new Blob(["content-disposition: form-data;name=\"".concat(name, "\"\r\n\r\n"), flattened[name]]);
|
|
588
|
-
return _context6.abrupt("return", _partBlob);
|
|
589
|
-
case 6:
|
|
590
|
-
valueToEncode = value;
|
|
591
|
-
if (Array.isArray(value)) {
|
|
592
|
-
_hasSymbols = value.some(function (item) {
|
|
593
|
-
return _typeof(item) === "symbol";
|
|
594
|
-
});
|
|
595
|
-
if (_hasSymbols) {
|
|
596
|
-
_hbEncodeValue9 = hbEncodeValue(value), _hbEncodeValue10 = _slicedToArray(_hbEncodeValue9, 2), _type3 = _hbEncodeValue10[0], _encoded3 = _hbEncodeValue10[1];
|
|
597
|
-
valueToEncode = _encoded3 || value.toString();
|
|
598
|
-
}
|
|
599
|
-
} else if (isBytes(value)) valueToEncode = value;
|
|
600
|
-
if (isBytes(valueToEncode)) {
|
|
601
|
-
uint8Array = valueToEncode instanceof Uint8Array ? valueToEncode : valueToEncode instanceof ArrayBuffer ? new Uint8Array(valueToEncode) : Buffer.isBuffer(valueToEncode) ? new Uint8Array(valueToEncode.buffer, valueToEncode.byteOffset, valueToEncode.length) : new Uint8Array(valueToEncode.buffer, valueToEncode.byteOffset, valueToEncode.byteLength);
|
|
602
|
-
partBlob = new Blob(["content-disposition: form-data;name=\"".concat(name, "\"\r\n\r\n"), uint8Array]);
|
|
603
|
-
} else {
|
|
604
|
-
partBlob = new Blob(["content-disposition: form-data;name=\"".concat(name, "\"\r\n\r\n"), valueToEncode]);
|
|
605
|
-
}
|
|
606
|
-
return _context6.abrupt("return", partBlob);
|
|
607
|
-
case 10:
|
|
608
|
-
case "end":
|
|
609
|
-
return _context6.stop();
|
|
610
|
-
}
|
|
611
|
-
}, _callee6);
|
|
612
|
-
}));
|
|
613
|
-
return function (_x7) {
|
|
614
|
-
return _ref18.apply(this, arguments);
|
|
615
|
-
};
|
|
616
|
-
}()));
|
|
617
|
-
case 21:
|
|
618
|
-
bodyParts = _context7.sent;
|
|
619
|
-
_context7.next = 24;
|
|
620
|
-
return new Blob(bodyParts).arrayBuffer();
|
|
621
|
-
case 24:
|
|
622
|
-
allPartsBuffer = _context7.sent;
|
|
623
|
-
_context7.next = 27;
|
|
624
|
-
return sha256(allPartsBuffer);
|
|
625
|
-
case 27:
|
|
626
|
-
hashResult = _context7.sent;
|
|
627
|
-
boundary = _base64url["default"].encode(Buffer.from(hashResult));
|
|
628
|
-
finalParts = [];
|
|
629
|
-
_iterator = _createForOfIteratorHelper(bodyParts);
|
|
630
|
-
try {
|
|
631
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
632
|
-
part = _step.value;
|
|
633
|
-
finalParts.push("--".concat(boundary, "\r\n"));
|
|
634
|
-
finalParts.push(part);
|
|
635
|
-
finalParts.push("\r\n");
|
|
636
|
-
}
|
|
637
|
-
} catch (err) {
|
|
638
|
-
_iterator.e(err);
|
|
639
|
-
} finally {
|
|
640
|
-
_iterator.f();
|
|
641
|
-
}
|
|
642
|
-
finalParts.push("--".concat(boundary, "--"));
|
|
643
|
-
headers["content-type"] = "multipart/form-data; boundary=\"".concat(boundary, "\"");
|
|
644
|
-
body = new Blob(finalParts);
|
|
645
|
-
case 35:
|
|
646
|
-
if (!body) {
|
|
647
|
-
_context7.next = 45;
|
|
648
|
-
break;
|
|
649
|
-
}
|
|
650
|
-
_context7.next = 38;
|
|
651
|
-
return body.arrayBuffer();
|
|
652
|
-
case 38:
|
|
653
|
-
finalContent = _context7.sent;
|
|
654
|
-
_context7.next = 41;
|
|
655
|
-
return sha256(finalContent);
|
|
656
|
-
case 41:
|
|
657
|
-
contentDigest = _context7.sent;
|
|
658
|
-
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
|
|
659
|
-
headers["content-digest"] = "sha-256=:".concat(base64, ":");
|
|
660
|
-
headers["content-length"] = String(finalContent.byteLength);
|
|
661
|
-
case 45:
|
|
662
|
-
return _context7.abrupt("return", {
|
|
663
|
-
headers: headers,
|
|
664
|
-
body: body
|
|
665
|
-
});
|
|
666
|
-
case 46:
|
|
667
|
-
case "end":
|
|
668
|
-
return _context7.stop();
|
|
669
|
-
}
|
|
670
|
-
}, _callee7);
|
|
671
|
-
}));
|
|
672
|
-
return _encode.apply(this, arguments);
|
|
673
|
-
}
|
|
674
|
-
var toHttpSigner = function toHttpSigner(signer) {
|
|
675
|
-
var params = ["alg", "keyid"].sort();
|
|
676
|
-
return /*#__PURE__*/function () {
|
|
677
|
-
var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref13) {
|
|
678
|
-
var request, fields, signatureBase, signatureInput, createCalled, create, result, signatureBuffer, signedHeaders, finalHeaders, _i, _Object$entries, _Object$entries$_i, key, value;
|
|
679
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
680
|
-
while (1) switch (_context.prev = _context.next) {
|
|
681
|
-
case 0:
|
|
682
|
-
request = _ref13.request, fields = _ref13.fields;
|
|
683
|
-
createCalled = false;
|
|
684
|
-
create = function create(injected) {
|
|
685
|
-
createCalled = true;
|
|
686
|
-
var publicKey = injected.publicKey,
|
|
687
|
-
_injected$alg = injected.alg,
|
|
688
|
-
alg = _injected$alg === void 0 ? "rsa-pss-sha512" : _injected$alg;
|
|
689
|
-
var publicKeyBuffer = toView(publicKey);
|
|
690
|
-
var signingParameters = createSigningParameters({
|
|
691
|
-
params: params,
|
|
692
|
-
paramValues: {
|
|
693
|
-
keyid: _base64url["default"].encode(publicKeyBuffer),
|
|
694
|
-
alg: alg
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
var signatureBaseArray = createSignatureBase({
|
|
698
|
-
fields: fields
|
|
699
|
-
}, request);
|
|
700
|
-
signatureInput = (0, _structuredHeaders.serializeList)([[signatureBaseArray.map(function (_ref15) {
|
|
701
|
-
var _ref16 = _slicedToArray(_ref15, 1),
|
|
702
|
-
item = _ref16[0];
|
|
703
|
-
return (0, _structuredHeaders.parseItem)(item);
|
|
704
|
-
}), signingParameters]]);
|
|
705
|
-
signatureBaseArray.push(['"@signature-params"', [signatureInput]]);
|
|
706
|
-
signatureBase = formatSignatureBase(signatureBaseArray);
|
|
707
|
-
return new TextEncoder().encode(signatureBase);
|
|
708
|
-
};
|
|
709
|
-
_context.next = 5;
|
|
710
|
-
return signer(create, "httpsig");
|
|
711
|
-
case 5:
|
|
712
|
-
result = _context.sent;
|
|
713
|
-
if (createCalled) {
|
|
714
|
-
_context.next = 8;
|
|
715
|
-
break;
|
|
716
|
-
}
|
|
717
|
-
throw new Error("create() must be invoked in order to construct the data to sign");
|
|
718
|
-
case 8:
|
|
719
|
-
if (!(!result.signature || !result.address)) {
|
|
720
|
-
_context.next = 10;
|
|
721
|
-
break;
|
|
722
|
-
}
|
|
723
|
-
throw new Error("Signer must return signature and address");
|
|
724
|
-
case 10:
|
|
725
|
-
signatureBuffer = toView(result.signature);
|
|
726
|
-
signedHeaders = augmentHeaders(request.headers, signatureBuffer, signatureInput, httpSigName(result.address));
|
|
727
|
-
finalHeaders = {};
|
|
728
|
-
for (_i = 0, _Object$entries = Object.entries(signedHeaders); _i < _Object$entries.length; _i++) {
|
|
729
|
-
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
730
|
-
if (key === "Signature" || key === "Signature-Input") {
|
|
731
|
-
finalHeaders[key.toLowerCase()] = value;
|
|
732
|
-
} else finalHeaders[key] = value;
|
|
733
|
-
}
|
|
734
|
-
return _context.abrupt("return", _objectSpread(_objectSpread({}, request), {}, {
|
|
735
|
-
headers: finalHeaders
|
|
736
|
-
}));
|
|
737
|
-
case 15:
|
|
738
|
-
case "end":
|
|
739
|
-
return _context.stop();
|
|
740
|
-
}
|
|
741
|
-
}, _callee);
|
|
742
|
-
}));
|
|
743
|
-
return function (_x3) {
|
|
744
|
-
return _ref14.apply(this, arguments);
|
|
745
|
-
};
|
|
746
|
-
}();
|
|
747
|
-
};
|
|
748
|
-
function createRequest(config) {
|
|
35
|
+
function signer(config) {
|
|
749
36
|
var signer = config.signer,
|
|
750
37
|
_config$url = config.url,
|
|
751
38
|
url = _config$url === void 0 ? "http://localhost:10001" : _config$url;
|
|
@@ -753,24 +40,17 @@ function createRequest(config) {
|
|
|
753
40
|
throw new Error("Signer is required for mainnet mode");
|
|
754
41
|
}
|
|
755
42
|
return /*#__PURE__*/function () {
|
|
756
|
-
var
|
|
757
|
-
var _fields$path, path, _fields$method, method, restFields, aoFields,
|
|
758
|
-
return _regeneratorRuntime().wrap(function
|
|
759
|
-
while (1) switch (
|
|
43
|
+
var _sign = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(fields) {
|
|
44
|
+
var _fields$path, path, _fields$method, method, restFields, aoFields, encoded, headersObj, body, _url, bodySize, lowercaseHeaders, _i, _Object$entries, _Object$entries$_i, key, value, signingFields, signedRequest, finalHeaders, _i2, _Object$entries2, _Object$entries2$_i, _key, _value, result;
|
|
45
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
46
|
+
while (1) switch (_context.prev = _context.next) {
|
|
760
47
|
case 0:
|
|
761
48
|
_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, restFields = _objectWithoutProperties(fields, _excluded);
|
|
762
49
|
aoFields = _objectSpread({}, restFields);
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
if (binaryKeys.length > 1 && !aoFields.body && !aoFields.data) {
|
|
768
|
-
aoFields.body = "1984";
|
|
769
|
-
}
|
|
770
|
-
_context2.next = 7;
|
|
771
|
-
return encode(aoFields);
|
|
772
|
-
case 7:
|
|
773
|
-
encoded = _context2.sent;
|
|
50
|
+
_context.next = 4;
|
|
51
|
+
return (0, _encode.enc)(aoFields);
|
|
52
|
+
case 4:
|
|
53
|
+
encoded = _context.sent;
|
|
774
54
|
headersObj = encoded ? encoded.headers : {};
|
|
775
55
|
body = encoded ? encoded.body : undefined;
|
|
776
56
|
_url = joinUrl({
|
|
@@ -784,8 +64,8 @@ function createRequest(config) {
|
|
|
784
64
|
}
|
|
785
65
|
}
|
|
786
66
|
lowercaseHeaders = {};
|
|
787
|
-
for (
|
|
788
|
-
_Object$
|
|
67
|
+
for (_i = 0, _Object$entries = Object.entries(headersObj); _i < _Object$entries.length; _i++) {
|
|
68
|
+
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
789
69
|
lowercaseHeaders[key.toLowerCase()] = value;
|
|
790
70
|
}
|
|
791
71
|
signingFields = Object.keys(lowercaseHeaders).filter(function (key) {
|
|
@@ -795,8 +75,8 @@ function createRequest(config) {
|
|
|
795
75
|
lowercaseHeaders["content-length"] = "0";
|
|
796
76
|
signingFields.push("content-length");
|
|
797
77
|
}
|
|
798
|
-
|
|
799
|
-
return toHttpSigner(signer)({
|
|
78
|
+
_context.next = 15;
|
|
79
|
+
return (0, _send.toHttpSigner)(signer)({
|
|
800
80
|
request: {
|
|
801
81
|
url: _url,
|
|
802
82
|
method: method,
|
|
@@ -804,11 +84,11 @@ function createRequest(config) {
|
|
|
804
84
|
},
|
|
805
85
|
fields: signingFields
|
|
806
86
|
});
|
|
807
|
-
case
|
|
808
|
-
signedRequest =
|
|
87
|
+
case 15:
|
|
88
|
+
signedRequest = _context.sent;
|
|
809
89
|
finalHeaders = {};
|
|
810
|
-
for (
|
|
811
|
-
_Object$
|
|
90
|
+
for (_i2 = 0, _Object$entries2 = Object.entries(headersObj); _i2 < _Object$entries2.length; _i2++) {
|
|
91
|
+
_Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), _key = _Object$entries2$_i[0], _value = _Object$entries2$_i[1];
|
|
812
92
|
finalHeaders[_key] = _value;
|
|
813
93
|
}
|
|
814
94
|
finalHeaders["signature"] = signedRequest.headers["signature"];
|
|
@@ -822,82 +102,16 @@ function createRequest(config) {
|
|
|
822
102
|
headers: finalHeaders
|
|
823
103
|
};
|
|
824
104
|
if (body) result.body = body;
|
|
825
|
-
return
|
|
826
|
-
case
|
|
105
|
+
return _context.abrupt("return", result);
|
|
106
|
+
case 24:
|
|
827
107
|
case "end":
|
|
828
|
-
return
|
|
108
|
+
return _context.stop();
|
|
829
109
|
}
|
|
830
|
-
},
|
|
110
|
+
}, _callee);
|
|
831
111
|
}));
|
|
832
|
-
function
|
|
833
|
-
return
|
|
112
|
+
function sign(_x) {
|
|
113
|
+
return _sign.apply(this, arguments);
|
|
834
114
|
}
|
|
835
|
-
return
|
|
115
|
+
return sign;
|
|
836
116
|
}();
|
|
837
|
-
}
|
|
838
|
-
function send(_x5) {
|
|
839
|
-
return _send.apply(this, arguments);
|
|
840
|
-
}
|
|
841
|
-
function _send() {
|
|
842
|
-
_send = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(signedMsg) {
|
|
843
|
-
var fetchImpl,
|
|
844
|
-
fetchOptions,
|
|
845
|
-
response,
|
|
846
|
-
headers,
|
|
847
|
-
_args8 = arguments;
|
|
848
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
849
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
850
|
-
case 0:
|
|
851
|
-
fetchImpl = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : fetch;
|
|
852
|
-
fetchOptions = {
|
|
853
|
-
method: signedMsg.method,
|
|
854
|
-
headers: signedMsg.headers,
|
|
855
|
-
redirect: "follow"
|
|
856
|
-
};
|
|
857
|
-
if (signedMsg.body !== undefined && signedMsg.method !== "GET" && signedMsg.method !== "HEAD") {
|
|
858
|
-
fetchOptions.body = signedMsg.body;
|
|
859
|
-
}
|
|
860
|
-
_context8.next = 5;
|
|
861
|
-
return fetchImpl(signedMsg.url, fetchOptions);
|
|
862
|
-
case 5:
|
|
863
|
-
response = _context8.sent;
|
|
864
|
-
if (!(response.status >= 400)) {
|
|
865
|
-
_context8.next = 14;
|
|
866
|
-
break;
|
|
867
|
-
}
|
|
868
|
-
_context8.t0 = Error;
|
|
869
|
-
_context8.t1 = "".concat(response.status, ": ");
|
|
870
|
-
_context8.next = 11;
|
|
871
|
-
return response.text();
|
|
872
|
-
case 11:
|
|
873
|
-
_context8.t2 = _context8.sent;
|
|
874
|
-
_context8.t3 = _context8.t1.concat.call(_context8.t1, _context8.t2);
|
|
875
|
-
throw new _context8.t0(_context8.t3);
|
|
876
|
-
case 14:
|
|
877
|
-
headers = {};
|
|
878
|
-
if (response.headers && typeof response.headers.forEach === "function") {
|
|
879
|
-
response.headers.forEach(function (v, k) {
|
|
880
|
-
return headers[k] = v;
|
|
881
|
-
});
|
|
882
|
-
} else headers = response.headers;
|
|
883
|
-
_context8.t4 = response;
|
|
884
|
-
_context8.t5 = headers;
|
|
885
|
-
_context8.next = 20;
|
|
886
|
-
return response.text();
|
|
887
|
-
case 20:
|
|
888
|
-
_context8.t6 = _context8.sent;
|
|
889
|
-
_context8.t7 = response.status;
|
|
890
|
-
return _context8.abrupt("return", {
|
|
891
|
-
response: _context8.t4,
|
|
892
|
-
headers: _context8.t5,
|
|
893
|
-
body: _context8.t6,
|
|
894
|
-
status: _context8.t7
|
|
895
|
-
});
|
|
896
|
-
case 23:
|
|
897
|
-
case "end":
|
|
898
|
-
return _context8.stop();
|
|
899
|
-
}
|
|
900
|
-
}, _callee8);
|
|
901
|
-
}));
|
|
902
|
-
return _send.apply(this, arguments);
|
|
903
117
|
}
|