wao 0.29.1 → 0.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/encode.js +4 -24
- package/cjs/hb.js +1 -3
- package/cjs/httpsig.js +51 -17
- package/cjs/send.js +1 -7
- package/cjs/signer.js +148 -116
- package/esm/encode.js +2 -5
- package/esm/hb.js +1 -1
- package/esm/httpsig.js +39 -17
- package/esm/send.js +1 -7
- package/esm/signer.js +72 -76
- package/package.json +1 -1
package/cjs/encode.js
CHANGED
|
@@ -1162,11 +1162,11 @@ function setFinalHeaders(headers, boundary, contentDigest, byteLength) {
|
|
|
1162
1162
|
}
|
|
1163
1163
|
headers["content-length"] = String(byteLength);
|
|
1164
1164
|
}
|
|
1165
|
-
function
|
|
1166
|
-
return
|
|
1165
|
+
function enc() {
|
|
1166
|
+
return _enc.apply(this, arguments);
|
|
1167
1167
|
}
|
|
1168
|
-
function
|
|
1169
|
-
|
|
1168
|
+
function _enc() {
|
|
1169
|
+
_enc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
1170
1170
|
var obj,
|
|
1171
1171
|
processedObj,
|
|
1172
1172
|
emptyResult,
|
|
@@ -1334,25 +1334,5 @@ function _encode() {
|
|
|
1334
1334
|
}
|
|
1335
1335
|
}, _callee8);
|
|
1336
1336
|
}));
|
|
1337
|
-
return _encode.apply(this, arguments);
|
|
1338
|
-
}
|
|
1339
|
-
function enc(_x11) {
|
|
1340
|
-
return _enc.apply(this, arguments);
|
|
1341
|
-
}
|
|
1342
|
-
function _enc() {
|
|
1343
|
-
_enc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fields) {
|
|
1344
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1345
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
1346
|
-
case 0:
|
|
1347
|
-
_context9.next = 2;
|
|
1348
|
-
return encode(fields);
|
|
1349
|
-
case 2:
|
|
1350
|
-
return _context9.abrupt("return", _context9.sent);
|
|
1351
|
-
case 3:
|
|
1352
|
-
case "end":
|
|
1353
|
-
return _context9.stop();
|
|
1354
|
-
}
|
|
1355
|
-
}, _callee9);
|
|
1356
|
-
}));
|
|
1357
1337
|
return _enc.apply(this, arguments);
|
|
1358
1338
|
}
|
package/cjs/hb.js
CHANGED
|
@@ -1561,9 +1561,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
1561
1561
|
body: _context38.t1,
|
|
1562
1562
|
status: _context38.t2
|
|
1563
1563
|
};
|
|
1564
|
-
return _context38.abrupt("return", _objectSpread({
|
|
1565
|
-
out: (0, _httpsig.from)(http)
|
|
1566
|
-
}, http));
|
|
1564
|
+
return _context38.abrupt("return", _objectSpread(_objectSpread({}, (0, _httpsig.from)(http)), http));
|
|
1567
1565
|
case 19:
|
|
1568
1566
|
case "end":
|
|
1569
1567
|
return _context38.stop();
|
package/cjs/httpsig.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.verifyContentDigest = exports.toBuffer = exports.hasValidSignature = exp
|
|
|
7
7
|
var _ramda = require("ramda");
|
|
8
8
|
var _signerUtils = require("./signer-utils.js");
|
|
9
9
|
var _base64url = _interopRequireDefault(require("base64url"));
|
|
10
|
+
var _utils = require("./utils.js");
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
12
|
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
12
13
|
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."); }
|
|
@@ -389,7 +390,9 @@ var _toJSON = function toJSON(msg) {
|
|
|
389
390
|
_value2 = _Object$entries7$_i[1];
|
|
390
391
|
// Skip internal keys and headers we don't want in the final result
|
|
391
392
|
if (_key5.startsWith("__")) continue;
|
|
392
|
-
|
|
393
|
+
|
|
394
|
+
// Skip @ fields EXCEPT @path which we want to include
|
|
395
|
+
if (_key5.startsWith("@") && _key5 !== "@path") continue;
|
|
393
396
|
if (_key5 === "ao-types") continue;
|
|
394
397
|
if (_key5 === "content-type") continue;
|
|
395
398
|
if (_key5 === "content-digest") continue;
|
|
@@ -910,12 +913,6 @@ var stringToBuffer = function stringToBuffer(str) {
|
|
|
910
913
|
}
|
|
911
914
|
return buffer;
|
|
912
915
|
};
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Original from function - extracts and converts only signed components
|
|
916
|
-
* @param {Object} http - HTTP message object with headers, body, and status
|
|
917
|
-
* @returns {Object|null} Converted signed components or null if not signed
|
|
918
|
-
*/
|
|
919
916
|
var from = exports.from = function from(http) {
|
|
920
917
|
var input = http.headers["signature-input"] || http.headers["Signature-Input"];
|
|
921
918
|
if (!input) {
|
|
@@ -924,34 +921,71 @@ var from = exports.from = function from(http) {
|
|
|
924
921
|
|
|
925
922
|
// Decode signature inputs
|
|
926
923
|
var inputs = (0, _signerUtils.decodeSigInput)(input);
|
|
927
|
-
|
|
928
924
|
// Process the first signature (following the original logic)
|
|
929
925
|
for (var k in inputs) {
|
|
926
|
+
var _sigData$params$tag, _sigData$params;
|
|
930
927
|
var sigData = inputs[k];
|
|
931
|
-
|
|
932
928
|
// Extract only the signed components
|
|
933
929
|
var extractedComponents = extract(http, sigData.components);
|
|
930
|
+
var ret = {
|
|
931
|
+
hashpath: (_sigData$params$tag = sigData === null || sigData === void 0 || (_sigData$params = sigData.params) === null || _sigData$params === void 0 ? void 0 : _sigData$params.tag) !== null && _sigData$params$tag !== void 0 ? _sigData$params$tag : null
|
|
932
|
+
};
|
|
933
|
+
try {
|
|
934
|
+
ret.signer = (0, _utils.toAddr)(sigData.params.keyid);
|
|
935
|
+
} catch (e) {}
|
|
934
936
|
|
|
935
|
-
// Check if
|
|
937
|
+
// Check if @path was in the signed components
|
|
938
|
+
var hasPathComponent = sigData.components.some(function (c) {
|
|
939
|
+
return c.replace(/"/g, "") === "@path";
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
// If @path is signed, add the path header to extracted components
|
|
943
|
+
if (hasPathComponent) {
|
|
944
|
+
extractedComponents["path"] = http.headers.path;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// Check if ao-result header is present
|
|
936
948
|
var aoResult = http.headers["ao-result"] || http.headers["Ao-Result"];
|
|
937
|
-
|
|
949
|
+
|
|
950
|
+
// Handle ao-result pointing to body
|
|
951
|
+
if (aoResult === "body") {
|
|
952
|
+
// Handle empty body case
|
|
953
|
+
if (!extractedComponents.body) {
|
|
954
|
+
return _objectSpread({
|
|
955
|
+
out: ""
|
|
956
|
+
}, ret); // Return empty string for empty body
|
|
957
|
+
}
|
|
938
958
|
// Check if body is binary data
|
|
939
959
|
if (isBinaryString(extractedComponents.body)) {
|
|
940
|
-
return
|
|
960
|
+
return _objectSpread({
|
|
961
|
+
out: stringToBuffer(extractedComponents.body)
|
|
962
|
+
}, ret);
|
|
941
963
|
}
|
|
964
|
+
// Return body as-is if it's not binary
|
|
965
|
+
return _objectSpread({
|
|
966
|
+
out: extractedComponents.body
|
|
967
|
+
}, ret);
|
|
942
968
|
}
|
|
943
969
|
|
|
944
970
|
// Convert the extracted components to JSON format
|
|
945
971
|
var result = _toJSON(extractedComponents);
|
|
946
972
|
|
|
947
|
-
// Handle ao-result if present
|
|
948
|
-
if (aoResult &&
|
|
973
|
+
// Handle ao-result if present and pointing to other fields
|
|
974
|
+
if (aoResult && aoResult !== "body") {
|
|
949
975
|
// Return the value of the key specified by ao-result
|
|
950
|
-
return
|
|
976
|
+
// If the key doesn't exist, return undefined (or could return null/empty string)
|
|
977
|
+
return _objectSpread({
|
|
978
|
+
out: result[aoResult] !== undefined ? result[aoResult] : ""
|
|
979
|
+
}, ret);
|
|
951
980
|
}
|
|
952
|
-
return
|
|
981
|
+
return _objectSpread({
|
|
982
|
+
out: result
|
|
983
|
+
}, ret);
|
|
953
984
|
}
|
|
954
|
-
return
|
|
985
|
+
return {
|
|
986
|
+
out: null,
|
|
987
|
+
hashpath: null
|
|
988
|
+
};
|
|
955
989
|
};
|
|
956
990
|
|
|
957
991
|
/**
|
package/cjs/send.js
CHANGED
|
@@ -48,8 +48,6 @@ function _send() {
|
|
|
48
48
|
while (1) switch (_context2.prev = _context2.next) {
|
|
49
49
|
case 0:
|
|
50
50
|
fetchImpl = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : fetch;
|
|
51
|
-
// IMPORTANT: Use the URL from signedMsg.url, NOT from any path header
|
|
52
|
-
// This ensures we send to the correct URL even if path header is different
|
|
53
51
|
fetchOptions = {
|
|
54
52
|
method: signedMsg.method,
|
|
55
53
|
headers: signedMsg.headers,
|
|
@@ -58,8 +56,6 @@ function _send() {
|
|
|
58
56
|
if (signedMsg.body !== undefined && signedMsg.method !== "GET" && signedMsg.method !== "HEAD") {
|
|
59
57
|
fetchOptions.body = signedMsg.body;
|
|
60
58
|
}
|
|
61
|
-
|
|
62
|
-
// Use the URL as provided, ignoring any path header
|
|
63
59
|
_context2.next = 5;
|
|
64
60
|
return fetchImpl(signedMsg.url, fetchOptions);
|
|
65
61
|
case 5:
|
|
@@ -94,9 +90,7 @@ function _send() {
|
|
|
94
90
|
body: _context2.t5,
|
|
95
91
|
status: _context2.t6
|
|
96
92
|
};
|
|
97
|
-
return _context2.abrupt("return", _objectSpread({
|
|
98
|
-
out: (0, _httpsig.from)(http)
|
|
99
|
-
}, http));
|
|
93
|
+
return _context2.abrupt("return", _objectSpread(_objectSpread({}, (0, _httpsig.from)(http)), http));
|
|
100
94
|
case 23:
|
|
101
95
|
case "end":
|
|
102
96
|
return _context2.stop();
|
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/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/send.js
CHANGED
|
@@ -10,8 +10,6 @@ const {
|
|
|
10
10
|
import { from } from "./httpsig.js"
|
|
11
11
|
|
|
12
12
|
export async function send(signedMsg, fetchImpl = fetch) {
|
|
13
|
-
// IMPORTANT: Use the URL from signedMsg.url, NOT from any path header
|
|
14
|
-
// This ensures we send to the correct URL even if path header is different
|
|
15
13
|
const fetchOptions = {
|
|
16
14
|
method: signedMsg.method,
|
|
17
15
|
headers: signedMsg.headers,
|
|
@@ -25,7 +23,6 @@ export async function send(signedMsg, fetchImpl = fetch) {
|
|
|
25
23
|
fetchOptions.body = signedMsg.body
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
// Use the URL as provided, ignoring any path header
|
|
29
26
|
const response = await fetchImpl(signedMsg.url, fetchOptions)
|
|
30
27
|
if (response.status >= 400) {
|
|
31
28
|
throw new Error(`${response.status}: ${await response.text()}`)
|
|
@@ -36,10 +33,7 @@ export async function send(signedMsg, fetchImpl = fetch) {
|
|
|
36
33
|
response.headers.forEach((v, k) => (headers[k] = v))
|
|
37
34
|
} else headers = response.headers
|
|
38
35
|
const http = { headers, body: await response.text(), status: response.status }
|
|
39
|
-
return {
|
|
40
|
-
out: from(http),
|
|
41
|
-
...http,
|
|
42
|
-
}
|
|
36
|
+
return { ...from(http), ...http }
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
const httpSigName = address => {
|
package/esm/signer.js
CHANGED
|
@@ -1,97 +1,93 @@
|
|
|
1
1
|
import { toHttpSigner } from "./send.js"
|
|
2
2
|
import { enc } from "./encode.js"
|
|
3
|
+
import { createSigner } from "@permaweb/aoconnect"
|
|
3
4
|
|
|
4
5
|
const joinUrl = ({ url, path }) => {
|
|
5
|
-
if (path.startsWith("http://") || path.startsWith("https://"))
|
|
6
|
-
return path
|
|
7
|
-
}
|
|
8
|
-
// Ensure path starts with /
|
|
6
|
+
if (path.startsWith("http://") || path.startsWith("https://")) return path
|
|
9
7
|
const normalizedPath = path.startsWith("/") ? path : "/" + path
|
|
10
8
|
return url.endsWith("/")
|
|
11
9
|
? url.slice(0, -1) + normalizedPath
|
|
12
10
|
: url + normalizedPath
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
export function
|
|
16
|
-
const
|
|
13
|
+
export async function sign({ url, path, msg: encoded, jwk, signPath = false }) {
|
|
14
|
+
const signer = createSigner(jwk, url)
|
|
15
|
+
const { body = null, ...headers } = encoded
|
|
16
|
+
let _enc = { headers }
|
|
17
|
+
if (body) _enc.body = new Blob([body])
|
|
18
|
+
return await _sign({ signer, encoded: _enc, url, path, _path: signPath })
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
async function _sign({
|
|
22
|
+
encoded,
|
|
23
|
+
signer,
|
|
24
|
+
path,
|
|
25
|
+
url,
|
|
26
|
+
method = "POST",
|
|
27
|
+
_path = false,
|
|
28
|
+
}) {
|
|
29
|
+
const headersObj = encoded ? encoded.headers : {}
|
|
30
|
+
const body = encoded ? encoded.body : undefined
|
|
31
|
+
const _url = joinUrl({ url, path })
|
|
32
|
+
headersObj["path"] = path
|
|
33
|
+
if (body && !headersObj["content-length"]) {
|
|
34
|
+
const bodySize = body.size || body.byteLength || 0
|
|
35
|
+
if (bodySize > 0) headersObj["content-length"] = String(bodySize)
|
|
36
|
+
}
|
|
37
|
+
const lowercaseHeaders = {}
|
|
38
|
+
for (const [key, value] of Object.entries(headersObj)) {
|
|
39
|
+
lowercaseHeaders[key.toLowerCase()] = value
|
|
40
|
+
}
|
|
41
|
+
const bodyKeys = headersObj["body-keys"]
|
|
42
|
+
? headersObj["body-keys"]
|
|
43
|
+
.replace(/"/g, "")
|
|
44
|
+
.split(",")
|
|
45
|
+
.map(k => k.trim())
|
|
46
|
+
: []
|
|
47
|
+
|
|
48
|
+
const signingFields = Object.keys(lowercaseHeaders).filter(
|
|
49
|
+
key => key !== "body-keys" && key !== "path" && !bodyKeys.includes(key)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
if (_path) signingFields.push("path")
|
|
53
|
+
|
|
54
|
+
if (signingFields.length === 0 && !body) {
|
|
55
|
+
lowercaseHeaders["content-length"] = "0"
|
|
56
|
+
signingFields.push("content-length")
|
|
20
57
|
}
|
|
21
58
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const headersObj = encoded ? encoded.headers : {}
|
|
27
|
-
const body = encoded ? encoded.body : undefined
|
|
28
|
-
|
|
29
|
-
const _url = joinUrl({ url, path })
|
|
30
|
-
|
|
31
|
-
headersObj["path"] = path
|
|
32
|
-
|
|
33
|
-
if (body && !headersObj["content-length"]) {
|
|
34
|
-
const bodySize = body.size || body.byteLength || 0
|
|
35
|
-
if (bodySize > 0) {
|
|
36
|
-
headersObj["content-length"] = String(bodySize)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const lowercaseHeaders = {}
|
|
41
|
-
for (const [key, value] of Object.entries(headersObj)) {
|
|
42
|
-
lowercaseHeaders[key.toLowerCase()] = value
|
|
43
|
-
}
|
|
44
|
-
if (lowercaseHeaders.path && /^\//.test(lowercaseHeaders.path)) {
|
|
45
|
-
//const sp = lowercaseHeaders.path.split("/")
|
|
46
|
-
//lowercaseHeaders.path = sp.slice(sp.length - 1).join("/")
|
|
47
|
-
}
|
|
48
|
-
// Parse body-keys if present
|
|
49
|
-
const bodyKeys = headersObj["body-keys"]
|
|
50
|
-
? headersObj["body-keys"]
|
|
51
|
-
.replace(/"/g, "")
|
|
52
|
-
.split(",")
|
|
53
|
-
.map(k => k.trim())
|
|
54
|
-
: []
|
|
55
|
-
|
|
56
|
-
// Collect fields to sign from headers
|
|
57
|
-
const signingFields = Object.keys(lowercaseHeaders).filter(
|
|
58
|
-
key => key !== "body-keys" && key !== "path" && !bodyKeys.includes(key) // Also exclude fields that are in body-keys
|
|
59
|
-
)
|
|
60
|
-
// Always include @path in the signature
|
|
61
|
-
//if (!signingFields.includes("path")) signingFields.push("path")
|
|
62
|
-
if (_path) signingFields.push("path")
|
|
63
|
-
// Ensure we have at least one field to sign
|
|
64
|
-
if (signingFields.length === 0 && !body) {
|
|
65
|
-
lowercaseHeaders["content-length"] = "0"
|
|
66
|
-
signingFields.push("content-length")
|
|
67
|
-
}
|
|
59
|
+
const signedRequest = await toHttpSigner(signer)({
|
|
60
|
+
request: { url: _url, method, headers: lowercaseHeaders },
|
|
61
|
+
fields: signingFields,
|
|
62
|
+
})
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
request: {
|
|
71
|
-
url: _url,
|
|
72
|
-
method,
|
|
73
|
-
headers: lowercaseHeaders,
|
|
74
|
-
},
|
|
75
|
-
fields: signingFields,
|
|
76
|
-
})
|
|
77
|
-
const finalHeaders = {}
|
|
64
|
+
const finalHeaders = {}
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
for (const [key, value] of Object.entries(headersObj)) {
|
|
67
|
+
finalHeaders[key] = value
|
|
68
|
+
}
|
|
82
69
|
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
finalHeaders["signature"] = signedRequest.headers["signature"]
|
|
71
|
+
finalHeaders["signature-input"] = signedRequest.headers["signature-input"]
|
|
85
72
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
73
|
+
if (headersObj["body-keys"]) {
|
|
74
|
+
finalHeaders["body-keys"] = headersObj["body-keys"]
|
|
75
|
+
}
|
|
76
|
+
const result = { url: _url, method, headers: finalHeaders }
|
|
90
77
|
|
|
91
|
-
|
|
78
|
+
if (body) result.body = body
|
|
92
79
|
|
|
93
|
-
|
|
80
|
+
return result
|
|
81
|
+
}
|
|
82
|
+
export function signer(config) {
|
|
83
|
+
const { signer, url = "http://localhost:10001" } = config
|
|
84
|
+
if (!signer) throw new Error("Signer is required for mainnet mode")
|
|
85
|
+
return async (
|
|
86
|
+
fields,
|
|
87
|
+
{ encoded: _encoded = false, path: _path = false } = {}
|
|
88
|
+
) => {
|
|
89
|
+
const { path = "/relay/process", method = "POST", ...aoFields } = fields
|
|
90
|
+
const encoded = _encoded ? aoFields : await enc(aoFields)
|
|
91
|
+
return await _sign({ url, method, path, _path, encoded, signer })
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
|
-
|
|
97
|
-
// stack / simple-pay / patch / hyperbeam / hyperbeam-aos / scheduler / cron
|