wao 0.29.0 → 0.29.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/httpsig.js +47 -7
- package/esm/httpsig.js +39 -0
- package/package.json +1 -1
package/cjs/httpsig.js
CHANGED
|
@@ -12,16 +12,16 @@ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArra
|
|
|
12
12
|
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."); }
|
|
13
13
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
14
14
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
15
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
16
|
-
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."); }
|
|
17
|
-
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; } }
|
|
18
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
19
15
|
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
16
|
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
17
|
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
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
19
|
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
20
|
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); }
|
|
21
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
22
|
+
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."); }
|
|
23
|
+
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; } }
|
|
24
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
25
25
|
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; } } }; }
|
|
26
26
|
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; } }
|
|
27
27
|
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; }
|
|
@@ -70,6 +70,17 @@ var extract = function extract(http, components) {
|
|
|
70
70
|
extracted["ao-types"] = aoTypes;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
// Extract ao-ids if it's signed
|
|
75
|
+
var hasAoIds = components.some(function (c) {
|
|
76
|
+
return c.replace(/"/g, "").toLowerCase() === "ao-ids";
|
|
77
|
+
});
|
|
78
|
+
if (hasAoIds) {
|
|
79
|
+
var aoIds = http.headers["ao-ids"] || http.headers["Ao-Ids"];
|
|
80
|
+
if (aoIds) {
|
|
81
|
+
extracted["ao-ids"] = aoIds;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
73
84
|
var _iterator2 = _createForOfIteratorHelper(components),
|
|
74
85
|
_step2;
|
|
75
86
|
try {
|
|
@@ -172,6 +183,27 @@ var toBuffer = exports.toBuffer = function toBuffer(body) {
|
|
|
172
183
|
throw new Error("Unsupported body type");
|
|
173
184
|
};
|
|
174
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Parse ao-ids dictionary
|
|
188
|
+
* @param {string} aoIds - The ao-ids header value
|
|
189
|
+
* @returns {Object} Parsed ID mappings
|
|
190
|
+
*/
|
|
191
|
+
var parseAoIds = function parseAoIds(aoIds) {
|
|
192
|
+
var result = {};
|
|
193
|
+
|
|
194
|
+
// Match pattern: ID="value"
|
|
195
|
+
var regex = /([A-Za-z0-9_-]{43})="([^"]*)"/g;
|
|
196
|
+
var match;
|
|
197
|
+
while ((match = regex.exec(aoIds)) !== null) {
|
|
198
|
+
var _match = match,
|
|
199
|
+
_match2 = _slicedToArray(_match, 3),
|
|
200
|
+
id = _match2[1],
|
|
201
|
+
value = _match2[2];
|
|
202
|
+
result[id] = value;
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
};
|
|
206
|
+
|
|
175
207
|
/**
|
|
176
208
|
* Convert message to JSON with proper type conversions
|
|
177
209
|
* Following the logic from dev_codec_structured, dev_codec_httpsig_conv, and dev_codec_flat
|
|
@@ -184,6 +216,14 @@ var _toJSON = function toJSON(msg) {
|
|
|
184
216
|
}
|
|
185
217
|
var result = _objectSpread({}, msg);
|
|
186
218
|
|
|
219
|
+
// Handle ao-ids parsing
|
|
220
|
+
if (result["ao-ids"]) {
|
|
221
|
+
var parsedIds = parseAoIds(result["ao-ids"]);
|
|
222
|
+
// Remove the ao-ids header and merge the parsed IDs
|
|
223
|
+
delete result["ao-ids"];
|
|
224
|
+
result = _objectSpread(_objectSpread({}, result), parsedIds);
|
|
225
|
+
}
|
|
226
|
+
|
|
187
227
|
// First, handle the multipart body if present
|
|
188
228
|
var contentType = result["content-type"];
|
|
189
229
|
var body = result.body;
|
|
@@ -1034,9 +1074,9 @@ var verifyContentDigest = exports.verifyContentDigest = function verifyContentDi
|
|
|
1034
1074
|
error: "Invalid content-digest format"
|
|
1035
1075
|
};
|
|
1036
1076
|
}
|
|
1037
|
-
var
|
|
1038
|
-
algorithm =
|
|
1039
|
-
expectedDigest =
|
|
1077
|
+
var _match3 = _slicedToArray(match, 3),
|
|
1078
|
+
algorithm = _match3[1],
|
|
1079
|
+
expectedDigest = _match3[2];
|
|
1040
1080
|
try {
|
|
1041
1081
|
// Convert body to Buffer if needed
|
|
1042
1082
|
var bodyBuffer = typeof body === "string" ? Buffer.from(body, "utf-8") : body;
|
package/esm/httpsig.js
CHANGED
|
@@ -39,6 +39,17 @@ const extract = (http, components) => {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// Extract ao-ids if it's signed
|
|
43
|
+
const hasAoIds = components.some(
|
|
44
|
+
c => c.replace(/"/g, "").toLowerCase() === "ao-ids"
|
|
45
|
+
)
|
|
46
|
+
if (hasAoIds) {
|
|
47
|
+
const aoIds = http.headers["ao-ids"] || http.headers["Ao-Ids"]
|
|
48
|
+
if (aoIds) {
|
|
49
|
+
extracted["ao-ids"] = aoIds
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
for (const component of components) {
|
|
43
54
|
const cleanComponent = component.replace(/"/g, "")
|
|
44
55
|
|
|
@@ -139,6 +150,26 @@ export const toBuffer = body => {
|
|
|
139
150
|
throw new Error("Unsupported body type")
|
|
140
151
|
}
|
|
141
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Parse ao-ids dictionary
|
|
155
|
+
* @param {string} aoIds - The ao-ids header value
|
|
156
|
+
* @returns {Object} Parsed ID mappings
|
|
157
|
+
*/
|
|
158
|
+
const parseAoIds = aoIds => {
|
|
159
|
+
const result = {}
|
|
160
|
+
|
|
161
|
+
// Match pattern: ID="value"
|
|
162
|
+
const regex = /([A-Za-z0-9_-]{43})="([^"]*)"/g
|
|
163
|
+
let match
|
|
164
|
+
|
|
165
|
+
while ((match = regex.exec(aoIds)) !== null) {
|
|
166
|
+
const [, id, value] = match
|
|
167
|
+
result[id] = value
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return result
|
|
171
|
+
}
|
|
172
|
+
|
|
142
173
|
/**
|
|
143
174
|
* Convert message to JSON with proper type conversions
|
|
144
175
|
* Following the logic from dev_codec_structured, dev_codec_httpsig_conv, and dev_codec_flat
|
|
@@ -152,6 +183,14 @@ const toJSON = msg => {
|
|
|
152
183
|
|
|
153
184
|
let result = { ...msg }
|
|
154
185
|
|
|
186
|
+
// Handle ao-ids parsing
|
|
187
|
+
if (result["ao-ids"]) {
|
|
188
|
+
const parsedIds = parseAoIds(result["ao-ids"])
|
|
189
|
+
// Remove the ao-ids header and merge the parsed IDs
|
|
190
|
+
delete result["ao-ids"]
|
|
191
|
+
result = { ...result, ...parsedIds }
|
|
192
|
+
}
|
|
193
|
+
|
|
155
194
|
// First, handle the multipart body if present
|
|
156
195
|
const contentType = result["content-type"]
|
|
157
196
|
const body = result.body
|