wao 0.24.0 → 0.24.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/hb.js +493 -326
- package/cjs/hyperbeam.js +32 -2
- package/cjs/signer.js +352 -196
- package/cjs/utils.js +1 -0
- package/esm/hb.js +121 -81
- package/esm/hyperbeam.js +21 -4
- package/esm/signer.js +172 -27
- package/esm/utils.js +1 -0
- package/package.json +1 -1
package/cjs/signer.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createRequest = createRequest;
|
|
7
|
+
exports.extractPublicKeyFromHeaders = extractPublicKeyFromHeaders;
|
|
7
8
|
exports.send = send;
|
|
8
9
|
exports.verify = verify;
|
|
9
10
|
var _base64url = _interopRequireDefault(require("base64url"));
|
|
@@ -12,6 +13,7 @@ var _httpMessageSignatures = require("http-message-signatures");
|
|
|
12
13
|
var _structuredHeaders = require("structured-headers");
|
|
13
14
|
var _excluded = ["path", "method"];
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
16
|
+
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; } } }; }
|
|
15
17
|
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; }
|
|
16
18
|
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; }
|
|
17
19
|
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; }
|
|
@@ -160,6 +162,12 @@ function hbEncodeValue(value) {
|
|
|
160
162
|
// Escape quotes and backslashes
|
|
161
163
|
var escaped = v.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
162
164
|
return "\"".concat(escaped, "\"");
|
|
165
|
+
} else if (typeof v === "number") {
|
|
166
|
+
// Numbers should be encoded as bare items, not strings
|
|
167
|
+
return String(v);
|
|
168
|
+
} else if (typeof v === "boolean") {
|
|
169
|
+
// Booleans as structured field tokens
|
|
170
|
+
return v ? "?1" : "?0";
|
|
163
171
|
}
|
|
164
172
|
return "\"".concat(String(v), "\"");
|
|
165
173
|
}).join(", ");
|
|
@@ -194,9 +202,65 @@ function hbEncodeLift(obj) {
|
|
|
194
202
|
}, {});
|
|
195
203
|
}
|
|
196
204
|
|
|
197
|
-
//
|
|
205
|
+
// Store the original value for reference
|
|
206
|
+
var originalValue = value;
|
|
207
|
+
|
|
208
|
+
// first/second lift object - handle nested objects
|
|
198
209
|
if (isPojo(value)) {
|
|
199
|
-
|
|
210
|
+
// Check if this object has any nested objects or arrays with objects
|
|
211
|
+
var hasComplexValues = Object.values(value).some(function (v) {
|
|
212
|
+
return isPojo(v) || Array.isArray(v) && v.some(function (item) {
|
|
213
|
+
return isPojo(item);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
if (!hasComplexValues) {
|
|
217
|
+
// Simple flat object - can be encoded as structured field dictionary
|
|
218
|
+
var items = [];
|
|
219
|
+
Object.entries(value).forEach(function (_ref4) {
|
|
220
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
221
|
+
k = _ref5[0],
|
|
222
|
+
v = _ref5[1];
|
|
223
|
+
var subKey = k.toLowerCase();
|
|
224
|
+
if (typeof v === "string") {
|
|
225
|
+
var escaped = v.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
226
|
+
items.push("".concat(subKey, "=\"").concat(escaped, "\""));
|
|
227
|
+
} else if (typeof v === "number") {
|
|
228
|
+
items.push("".concat(subKey, "=").concat(v));
|
|
229
|
+
if (Number.isInteger(v)) {
|
|
230
|
+
// Use URL-encoded forward slash separator
|
|
231
|
+
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "integer";
|
|
232
|
+
} else {
|
|
233
|
+
acc[1]["".concat(key.toLowerCase(), "%2f").concat(subKey)] = "float";
|
|
234
|
+
}
|
|
235
|
+
} else if (typeof v === "boolean") {
|
|
236
|
+
items.push("".concat(subKey, "=").concat(v ? "?1" : "?0"));
|
|
237
|
+
} else if (Array.isArray(v) && !v.some(function (item) {
|
|
238
|
+
return isPojo(item);
|
|
239
|
+
})) {
|
|
240
|
+
// Simple array (no objects) - encode as structured field inner list
|
|
241
|
+
var listItems = v.map(function (item) {
|
|
242
|
+
if (typeof item === "string") {
|
|
243
|
+
return "\"".concat(item.replace(/\\/g, "\\\\").replace(/"/g, '\\"'), "\"");
|
|
244
|
+
} else if (typeof item === "number") {
|
|
245
|
+
return String(item);
|
|
246
|
+
} else if (typeof item === "boolean") {
|
|
247
|
+
return item ? "?1" : "?0";
|
|
248
|
+
} else {
|
|
249
|
+
return "\"".concat(String(item), "\"");
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
items.push("".concat(subKey, "=(").concat(listItems.join(" "), ")"));
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
var encodedValue = items.join(", ");
|
|
256
|
+
acc[0][key] = encodedValue;
|
|
257
|
+
acc[1][key.toLowerCase()] = "map";
|
|
258
|
+
} else {
|
|
259
|
+
// Has nested objects - needs multipart encoding
|
|
260
|
+
hbEncodeLift(value, storageKey, top);
|
|
261
|
+
// Add the original object to flattened so it can be processed
|
|
262
|
+
acc[0][key] = value;
|
|
263
|
+
}
|
|
200
264
|
return acc;
|
|
201
265
|
}
|
|
202
266
|
|
|
@@ -206,8 +270,11 @@ function hbEncodeLift(obj) {
|
|
|
206
270
|
type = _hbEncodeValue2[0],
|
|
207
271
|
encoded = _hbEncodeValue2[1];
|
|
208
272
|
if (encoded !== undefined) {
|
|
209
|
-
|
|
210
|
-
|
|
273
|
+
// For binary data, check the byte length directly without converting to string
|
|
274
|
+
var byteLength = isBytes(encoded) ? encoded.byteLength : Buffer.from(String(encoded)).byteLength;
|
|
275
|
+
if (byteLength > MAX_HEADER_LENGTH) {
|
|
276
|
+
// Store large values, but preserve binary data as-is
|
|
277
|
+
top[storageKey] = isBytes(encoded) ? encoded : String(encoded);
|
|
211
278
|
} else {
|
|
212
279
|
// Preserve the original key casing
|
|
213
280
|
var httpKey = key;
|
|
@@ -230,13 +297,14 @@ function hbEncodeLift(obj) {
|
|
|
230
297
|
if (Object.keys(flattened).length === 0) return top;
|
|
231
298
|
if (Object.keys(types).length > 0) {
|
|
232
299
|
// Format as structured fields dictionary
|
|
233
|
-
var aoTypeItems = Object.entries(types).map(function (
|
|
234
|
-
var
|
|
235
|
-
key =
|
|
236
|
-
value =
|
|
237
|
-
|
|
300
|
+
var aoTypeItems = Object.entries(types).map(function (_ref6) {
|
|
301
|
+
var _ref7 = _slicedToArray(_ref6, 2),
|
|
302
|
+
key = _ref7[0],
|
|
303
|
+
value = _ref7[1];
|
|
304
|
+
// The Erlang side expects keys with %2f for forward slashes
|
|
305
|
+
var safeKey = key.toLowerCase().replace(/[^a-z0-9_\-.*\/]/g, function (c) {
|
|
238
306
|
return "%" + c.charCodeAt(0).toString(16).padStart(2, "0");
|
|
239
|
-
});
|
|
307
|
+
}).replace(/\//g, "%2f"); // Replace forward slashes AFTER other encoding
|
|
240
308
|
return "".concat(safeKey, "=\"").concat(value, "\"");
|
|
241
309
|
});
|
|
242
310
|
aoTypeItems.sort();
|
|
@@ -255,13 +323,16 @@ function hbEncodeLift(obj) {
|
|
|
255
323
|
}
|
|
256
324
|
return top;
|
|
257
325
|
}
|
|
258
|
-
function encodePart(name,
|
|
259
|
-
var headers =
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
326
|
+
function encodePart(name, _ref8) {
|
|
327
|
+
var _ref8$headers = _ref8.headers,
|
|
328
|
+
headers = _ref8$headers === void 0 ? {} : _ref8$headers,
|
|
329
|
+
body = _ref8.body;
|
|
330
|
+
// Convert headers to a plain object if it's a Headers instance
|
|
331
|
+
var headerEntries = headers instanceof Headers ? Array.from(headers.entries()) : Object.entries(headers || {});
|
|
332
|
+
var parts = headerEntries.reduce(function (acc, _ref9) {
|
|
333
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
334
|
+
name = _ref10[0],
|
|
335
|
+
value = _ref10[1];
|
|
265
336
|
acc.push("".concat(name, ": "), value, "\r\n");
|
|
266
337
|
return acc;
|
|
267
338
|
}, ["content-disposition: form-data;name=\"".concat(name, "\"\r\n")]);
|
|
@@ -275,7 +346,7 @@ function encode() {
|
|
|
275
346
|
* Create HTTP signer wrapper
|
|
276
347
|
*/
|
|
277
348
|
function _encode() {
|
|
278
|
-
_encode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
349
|
+
_encode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
279
350
|
var obj,
|
|
280
351
|
originalObj,
|
|
281
352
|
flattened,
|
|
@@ -283,34 +354,43 @@ function _encode() {
|
|
|
283
354
|
headerKeys,
|
|
284
355
|
headers,
|
|
285
356
|
body,
|
|
357
|
+
promoteToBody,
|
|
286
358
|
bodyKey,
|
|
359
|
+
originalValue,
|
|
360
|
+
flattenedValue,
|
|
287
361
|
bodyParts,
|
|
288
|
-
|
|
362
|
+
allPartsBuffer,
|
|
289
363
|
hash,
|
|
290
364
|
boundary,
|
|
291
|
-
|
|
365
|
+
finalParts,
|
|
366
|
+
_iterator,
|
|
367
|
+
_step,
|
|
368
|
+
part,
|
|
292
369
|
finalContent,
|
|
293
370
|
contentDigest,
|
|
294
371
|
base64,
|
|
295
|
-
|
|
296
|
-
return _regeneratorRuntime().wrap(function
|
|
297
|
-
while (1) switch (
|
|
372
|
+
_args7 = arguments;
|
|
373
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
374
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
298
375
|
case 0:
|
|
299
|
-
obj =
|
|
376
|
+
obj = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
|
|
300
377
|
if (!(Object.keys(obj).length === 0)) {
|
|
301
|
-
|
|
378
|
+
_context7.next = 3;
|
|
302
379
|
break;
|
|
303
380
|
}
|
|
304
|
-
return
|
|
381
|
+
return _context7.abrupt("return", {
|
|
382
|
+
headers: {},
|
|
383
|
+
body: undefined
|
|
384
|
+
});
|
|
305
385
|
case 3:
|
|
306
386
|
// Keep reference to original object for data field
|
|
307
387
|
originalObj = obj;
|
|
308
388
|
flattened = hbEncodeLift(obj);
|
|
309
389
|
bodyKeys = [];
|
|
310
390
|
headerKeys = []; // Process all flattened keys
|
|
311
|
-
|
|
391
|
+
_context7.next = 9;
|
|
312
392
|
return Promise.all(Object.keys(flattened).map(/*#__PURE__*/function () {
|
|
313
|
-
var
|
|
393
|
+
var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key) {
|
|
314
394
|
var value, subPart, valueStr;
|
|
315
395
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
316
396
|
while (1) switch (_context5.prev = _context5.next) {
|
|
@@ -334,43 +414,58 @@ function _encode() {
|
|
|
334
414
|
flattened[key] = encodePart(key, subPart);
|
|
335
415
|
return _context5.abrupt("return");
|
|
336
416
|
case 10:
|
|
337
|
-
|
|
417
|
+
if (!isBytes(value)) {
|
|
418
|
+
_context5.next = 14;
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
// Binary data should always go to body
|
|
422
|
+
bodyKeys.push(key);
|
|
423
|
+
flattened[key] = new Blob(["content-disposition: form-data;name=\"".concat(key, "\"\r\n\r\n"), new Uint8Array(value.buffer || value)]);
|
|
424
|
+
return _context5.abrupt("return");
|
|
425
|
+
case 14:
|
|
338
426
|
valueStr = String(value);
|
|
339
|
-
_context5.next =
|
|
427
|
+
_context5.next = 17;
|
|
340
428
|
return hasNewline(valueStr);
|
|
341
|
-
case
|
|
342
|
-
_context5.
|
|
429
|
+
case 17:
|
|
430
|
+
_context5.t2 = _context5.sent;
|
|
431
|
+
if (_context5.t2) {
|
|
432
|
+
_context5.next = 20;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
_context5.t2 = key.includes("/");
|
|
436
|
+
case 20:
|
|
437
|
+
_context5.t1 = _context5.t2;
|
|
343
438
|
if (_context5.t1) {
|
|
344
|
-
_context5.next =
|
|
439
|
+
_context5.next = 23;
|
|
345
440
|
break;
|
|
346
441
|
}
|
|
347
|
-
_context5.t1 =
|
|
348
|
-
case
|
|
442
|
+
_context5.t1 = Buffer.from(valueStr).byteLength > MAX_HEADER_LENGTH;
|
|
443
|
+
case 23:
|
|
349
444
|
_context5.t0 = _context5.t1;
|
|
350
445
|
if (_context5.t0) {
|
|
351
|
-
_context5.next =
|
|
446
|
+
_context5.next = 26;
|
|
352
447
|
break;
|
|
353
448
|
}
|
|
354
|
-
_context5.t0 =
|
|
355
|
-
case
|
|
449
|
+
_context5.t0 = isPojo(value) && valueStr === "[object Object]";
|
|
450
|
+
case 26:
|
|
356
451
|
if (!_context5.t0) {
|
|
357
|
-
_context5.next =
|
|
452
|
+
_context5.next = 30;
|
|
358
453
|
break;
|
|
359
454
|
}
|
|
360
455
|
bodyKeys.push(key);
|
|
361
456
|
flattened[key] = new Blob(["content-disposition: form-data;name=\"".concat(key, "\"\r\n\r\n"), value]);
|
|
362
457
|
return _context5.abrupt("return");
|
|
363
|
-
case
|
|
458
|
+
case 30:
|
|
364
459
|
// It's a header
|
|
365
460
|
headerKeys.push(key);
|
|
366
|
-
case
|
|
461
|
+
case 31:
|
|
367
462
|
case "end":
|
|
368
463
|
return _context5.stop();
|
|
369
464
|
}
|
|
370
465
|
}, _callee5);
|
|
371
466
|
}));
|
|
372
467
|
return function (_x9) {
|
|
373
|
-
return
|
|
468
|
+
return _ref15.apply(this, arguments);
|
|
374
469
|
};
|
|
375
470
|
}()));
|
|
376
471
|
case 9:
|
|
@@ -390,88 +485,133 @@ function _encode() {
|
|
|
390
485
|
delete headers["body"]; // Remove from headers if it was there
|
|
391
486
|
}
|
|
392
487
|
body = undefined;
|
|
488
|
+
promoteToBody = true;
|
|
393
489
|
if (!(bodyKeys.length > 0)) {
|
|
394
|
-
|
|
490
|
+
_context7.next = 44;
|
|
395
491
|
break;
|
|
396
492
|
}
|
|
397
|
-
if (
|
|
398
|
-
|
|
493
|
+
if (bodyKeys.length === 1) {
|
|
494
|
+
// If there is only one element, promote it to be the full body
|
|
495
|
+
bodyKey = bodyKeys[0];
|
|
496
|
+
originalValue = originalObj[bodyKey];
|
|
497
|
+
flattenedValue = flattened[bodyKey]; // Only promote if it's not a complex object
|
|
498
|
+
if (!isPojo(originalValue) || isPojo(originalValue) && typeof flattenedValue === "string") {
|
|
499
|
+
// For objects that were encoded as structured fields, use the encoded value
|
|
500
|
+
if ((bodyKey === "body" || bodyKey === "data") && isPojo(originalValue) && typeof flattenedValue === "string") {
|
|
501
|
+
body = new Blob([flattenedValue]);
|
|
502
|
+
} else {
|
|
503
|
+
body = new Blob([originalValue || flattenedValue]);
|
|
504
|
+
}
|
|
505
|
+
headers["inline-body-key"] = bodyKey;
|
|
506
|
+
} else {
|
|
507
|
+
// Complex object - don't promote, create multipart
|
|
508
|
+
promoteToBody = false;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (!(!promoteToBody || bodyKeys.length > 1)) {
|
|
512
|
+
_context7.next = 34;
|
|
399
513
|
break;
|
|
400
514
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
515
|
+
_context7.next = 20;
|
|
516
|
+
return Promise.all(bodyKeys.map(/*#__PURE__*/function () {
|
|
517
|
+
var _ref16 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(name) {
|
|
518
|
+
var value, _partBlob, partBlob;
|
|
519
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
520
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
521
|
+
case 0:
|
|
522
|
+
if (!(flattened[name] instanceof Blob)) {
|
|
523
|
+
_context6.next = 2;
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
return _context6.abrupt("return", flattened[name]);
|
|
527
|
+
case 2:
|
|
528
|
+
// For raw values, we need to create a proper multipart part
|
|
529
|
+
value = originalObj[name] || flattened[name] || ""; // Special case: if this is a structured field encoded value, use the flattened value
|
|
530
|
+
if (!(name === "body" && isPojo(originalObj[name]) && typeof flattened[name] === "string")) {
|
|
531
|
+
_context6.next = 6;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
_partBlob = new Blob(["content-disposition: form-data;name=\"".concat(name, "\"\r\n\r\n"), flattened[name]]);
|
|
535
|
+
return _context6.abrupt("return", _partBlob);
|
|
536
|
+
case 6:
|
|
537
|
+
partBlob = new Blob(["content-disposition: form-data;name=\"".concat(name, "\"\r\n\r\n"), value]);
|
|
538
|
+
return _context6.abrupt("return", partBlob);
|
|
539
|
+
case 8:
|
|
540
|
+
case "end":
|
|
541
|
+
return _context6.stop();
|
|
542
|
+
}
|
|
543
|
+
}, _callee6);
|
|
544
|
+
}));
|
|
545
|
+
return function (_x10) {
|
|
546
|
+
return _ref16.apply(this, arguments);
|
|
547
|
+
};
|
|
548
|
+
}()));
|
|
549
|
+
case 20:
|
|
550
|
+
bodyParts = _context7.sent;
|
|
551
|
+
_context7.next = 23;
|
|
552
|
+
return new Blob(bodyParts).arrayBuffer();
|
|
416
553
|
case 23:
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
554
|
+
allPartsBuffer = _context7.sent;
|
|
555
|
+
_context7.next = 26;
|
|
556
|
+
return sha256(allPartsBuffer);
|
|
557
|
+
case 26:
|
|
558
|
+
hash = _context7.sent;
|
|
559
|
+
boundary = _base64url["default"].encode(Buffer.from(hash)); // Build the multipart body with proper boundaries
|
|
560
|
+
finalParts = [];
|
|
561
|
+
_iterator = _createForOfIteratorHelper(bodyParts);
|
|
562
|
+
try {
|
|
563
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
564
|
+
part = _step.value;
|
|
565
|
+
finalParts.push("--".concat(boundary, "\r\n"));
|
|
566
|
+
finalParts.push(part);
|
|
567
|
+
finalParts.push("\r\n");
|
|
568
|
+
}
|
|
569
|
+
} catch (err) {
|
|
570
|
+
_iterator.e(err);
|
|
571
|
+
} finally {
|
|
572
|
+
_iterator.f();
|
|
573
|
+
}
|
|
574
|
+
finalParts.push("--".concat(boundary, "--"));
|
|
435
575
|
headers["content-type"] = "multipart/form-data; boundary=\"".concat(boundary, "\"");
|
|
436
|
-
body = new Blob(
|
|
437
|
-
case
|
|
576
|
+
body = new Blob(finalParts);
|
|
577
|
+
case 34:
|
|
438
578
|
if (!body) {
|
|
439
|
-
|
|
579
|
+
_context7.next = 44;
|
|
440
580
|
break;
|
|
441
581
|
}
|
|
442
|
-
|
|
582
|
+
_context7.next = 37;
|
|
443
583
|
return body.arrayBuffer();
|
|
444
|
-
case
|
|
445
|
-
finalContent =
|
|
446
|
-
|
|
584
|
+
case 37:
|
|
585
|
+
finalContent = _context7.sent;
|
|
586
|
+
_context7.next = 40;
|
|
447
587
|
return sha256(finalContent);
|
|
448
|
-
case
|
|
449
|
-
contentDigest =
|
|
588
|
+
case 40:
|
|
589
|
+
contentDigest = _context7.sent;
|
|
450
590
|
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest)); // Use lowercase to match what's in the other headers
|
|
451
591
|
headers["content-digest"] = "sha-256=:".concat(base64, ":");
|
|
452
592
|
headers["content-length"] = String(finalContent.byteLength);
|
|
453
|
-
case
|
|
454
|
-
return
|
|
593
|
+
case 44:
|
|
594
|
+
return _context7.abrupt("return", {
|
|
455
595
|
headers: headers,
|
|
456
596
|
body: body
|
|
457
597
|
});
|
|
458
|
-
case
|
|
598
|
+
case 45:
|
|
459
599
|
case "end":
|
|
460
|
-
return
|
|
600
|
+
return _context7.stop();
|
|
461
601
|
}
|
|
462
|
-
},
|
|
602
|
+
}, _callee7);
|
|
463
603
|
}));
|
|
464
604
|
return _encode.apply(this, arguments);
|
|
465
605
|
}
|
|
466
606
|
var toHttpSigner = function toHttpSigner(signer) {
|
|
467
607
|
var params = ["alg", "keyid"].sort();
|
|
468
608
|
return /*#__PURE__*/function () {
|
|
469
|
-
var
|
|
609
|
+
var _ref12 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref11) {
|
|
470
610
|
var request, fields, signatureBase, signatureInput, createCalled, create, result, signatureBuffer, signedHeaders, finalHeaders, _i, _Object$entries, _Object$entries$_i, key, value;
|
|
471
611
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
472
612
|
while (1) switch (_context.prev = _context.next) {
|
|
473
613
|
case 0:
|
|
474
|
-
request =
|
|
614
|
+
request = _ref11.request, fields = _ref11.fields;
|
|
475
615
|
createCalled = false;
|
|
476
616
|
create = function create(injected) {
|
|
477
617
|
createCalled = true;
|
|
@@ -489,9 +629,9 @@ var toHttpSigner = function toHttpSigner(signer) {
|
|
|
489
629
|
var signatureBaseArray = createSignatureBase({
|
|
490
630
|
fields: fields
|
|
491
631
|
}, request);
|
|
492
|
-
signatureInput = (0, _structuredHeaders.serializeList)([[signatureBaseArray.map(function (
|
|
493
|
-
var
|
|
494
|
-
item =
|
|
632
|
+
signatureInput = (0, _structuredHeaders.serializeList)([[signatureBaseArray.map(function (_ref13) {
|
|
633
|
+
var _ref14 = _slicedToArray(_ref13, 1),
|
|
634
|
+
item = _ref14[0];
|
|
495
635
|
return (0, _structuredHeaders.parseItem)(item);
|
|
496
636
|
}), signingParameters]]);
|
|
497
637
|
signatureBaseArray.push(['"@signature-params"', [signatureInput]]);
|
|
@@ -535,7 +675,7 @@ var toHttpSigner = function toHttpSigner(signer) {
|
|
|
535
675
|
}, _callee);
|
|
536
676
|
}));
|
|
537
677
|
return function (_x3) {
|
|
538
|
-
return
|
|
678
|
+
return _ref12.apply(this, arguments);
|
|
539
679
|
};
|
|
540
680
|
}();
|
|
541
681
|
};
|
|
@@ -589,8 +729,14 @@ function createRequest(config) {
|
|
|
589
729
|
}
|
|
590
730
|
|
|
591
731
|
// Get all header keys for signing (lowercase)
|
|
592
|
-
signingFields = Object.keys(lowercaseHeaders); //
|
|
593
|
-
|
|
732
|
+
signingFields = Object.keys(lowercaseHeaders); // If there are no fields to sign, add at least the content-length
|
|
733
|
+
if (signingFields.length === 0 && !body) {
|
|
734
|
+
lowercaseHeaders["content-length"] = "0";
|
|
735
|
+
signingFields.push("content-length");
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// Sign the request with lowercase headers
|
|
739
|
+
_context2.next = 15;
|
|
594
740
|
return toHttpSigner(signer)({
|
|
595
741
|
request: {
|
|
596
742
|
url: _url,
|
|
@@ -599,7 +745,7 @@ function createRequest(config) {
|
|
|
599
745
|
},
|
|
600
746
|
fields: signingFields
|
|
601
747
|
});
|
|
602
|
-
case
|
|
748
|
+
case 15:
|
|
603
749
|
signedRequest = _context2.sent;
|
|
604
750
|
// Build final headers: use original casing for all headers except signature headers
|
|
605
751
|
finalHeaders = {}; // First, add all original headers with their original casing
|
|
@@ -622,7 +768,7 @@ function createRequest(config) {
|
|
|
622
768
|
result.body = body;
|
|
623
769
|
}
|
|
624
770
|
return _context2.abrupt("return", result);
|
|
625
|
-
case
|
|
771
|
+
case 23:
|
|
626
772
|
case "end":
|
|
627
773
|
return _context2.stop();
|
|
628
774
|
}
|
|
@@ -642,17 +788,17 @@ function getMessageId(_x5) {
|
|
|
642
788
|
return _getMessageId.apply(this, arguments);
|
|
643
789
|
}
|
|
644
790
|
function _getMessageId() {
|
|
645
|
-
_getMessageId = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
791
|
+
_getMessageId = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(signedMessage) {
|
|
646
792
|
var signatureHeader, match, signature, encoder, data, hashBuffer, hashArray, hashBase64;
|
|
647
|
-
return _regeneratorRuntime().wrap(function
|
|
648
|
-
while (1) switch (
|
|
793
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
794
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
649
795
|
case 0:
|
|
650
796
|
// Extract signature from the Signature header
|
|
651
797
|
signatureHeader = signedMessage.headers.Signature || signedMessage.headers.signature;
|
|
652
798
|
match = signatureHeader.match(/Signature:\s*'http-sig-[^:]+:([^']+)'/);
|
|
653
799
|
signature = match ? match[1] : null;
|
|
654
800
|
if (signature) {
|
|
655
|
-
|
|
801
|
+
_context8.next = 5;
|
|
656
802
|
break;
|
|
657
803
|
}
|
|
658
804
|
throw new Error("Could not extract signature from headers");
|
|
@@ -660,18 +806,18 @@ function _getMessageId() {
|
|
|
660
806
|
// Hash the signature to get message ID
|
|
661
807
|
encoder = new TextEncoder();
|
|
662
808
|
data = encoder.encode(signature);
|
|
663
|
-
|
|
809
|
+
_context8.next = 9;
|
|
664
810
|
return _crypto["default"].subtle.digest("SHA-256", data);
|
|
665
811
|
case 9:
|
|
666
|
-
hashBuffer =
|
|
812
|
+
hashBuffer = _context8.sent;
|
|
667
813
|
hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
668
814
|
hashBase64 = btoa(String.fromCharCode.apply(String, hashArray));
|
|
669
|
-
return
|
|
815
|
+
return _context8.abrupt("return", hashBase64);
|
|
670
816
|
case 13:
|
|
671
817
|
case "end":
|
|
672
|
-
return
|
|
818
|
+
return _context8.stop();
|
|
673
819
|
}
|
|
674
|
-
},
|
|
820
|
+
}, _callee8);
|
|
675
821
|
}));
|
|
676
822
|
return _getMessageId.apply(this, arguments);
|
|
677
823
|
}
|
|
@@ -684,15 +830,16 @@ function send(_x6) {
|
|
|
684
830
|
* @returns {string} PEM formatted public key
|
|
685
831
|
*/
|
|
686
832
|
function _send() {
|
|
687
|
-
_send = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
833
|
+
_send = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(signedMsg) {
|
|
688
834
|
var fetchImpl,
|
|
689
835
|
fetchOptions,
|
|
690
836
|
response,
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
837
|
+
headers,
|
|
838
|
+
_args9 = arguments;
|
|
839
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
840
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
694
841
|
case 0:
|
|
695
|
-
fetchImpl =
|
|
842
|
+
fetchImpl = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : fetch;
|
|
696
843
|
fetchOptions = {
|
|
697
844
|
method: signedMsg.method,
|
|
698
845
|
headers: signedMsg.headers,
|
|
@@ -701,39 +848,48 @@ function _send() {
|
|
|
701
848
|
if (signedMsg.body !== undefined && signedMsg.method !== "GET" && signedMsg.method !== "HEAD") {
|
|
702
849
|
fetchOptions.body = signedMsg.body;
|
|
703
850
|
}
|
|
704
|
-
|
|
851
|
+
_context9.next = 5;
|
|
705
852
|
return fetchImpl(signedMsg.url, fetchOptions);
|
|
706
853
|
case 5:
|
|
707
|
-
response =
|
|
854
|
+
response = _context9.sent;
|
|
708
855
|
if (!(response.status >= 400)) {
|
|
709
|
-
|
|
856
|
+
_context9.next = 14;
|
|
710
857
|
break;
|
|
711
858
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
859
|
+
_context9.t0 = Error;
|
|
860
|
+
_context9.t1 = "".concat(response.status, ": ");
|
|
861
|
+
_context9.next = 11;
|
|
715
862
|
return response.text();
|
|
716
863
|
case 11:
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
throw new
|
|
864
|
+
_context9.t2 = _context9.sent;
|
|
865
|
+
_context9.t3 = _context9.t1.concat.call(_context9.t1, _context9.t2);
|
|
866
|
+
throw new _context9.t0(_context9.t3);
|
|
720
867
|
case 14:
|
|
721
|
-
|
|
722
|
-
|
|
868
|
+
// Convert Headers object to plain object
|
|
869
|
+
headers = {};
|
|
870
|
+
if (response.headers && typeof response.headers.forEach === "function") {
|
|
871
|
+
response.headers.forEach(function (v, k) {
|
|
872
|
+
return headers[k] = v;
|
|
873
|
+
});
|
|
874
|
+
} else headers = response.headers;
|
|
875
|
+
_context9.t4 = response;
|
|
876
|
+
_context9.t5 = headers;
|
|
877
|
+
_context9.next = 20;
|
|
723
878
|
return response.text();
|
|
724
|
-
case 17:
|
|
725
|
-
_context8.t5 = _context8.sent;
|
|
726
|
-
_context8.t6 = response.status;
|
|
727
|
-
return _context8.abrupt("return", {
|
|
728
|
-
headers: _context8.t4,
|
|
729
|
-
body: _context8.t5,
|
|
730
|
-
status: _context8.t6
|
|
731
|
-
});
|
|
732
879
|
case 20:
|
|
880
|
+
_context9.t6 = _context9.sent;
|
|
881
|
+
_context9.t7 = response.status;
|
|
882
|
+
return _context9.abrupt("return", {
|
|
883
|
+
response: _context9.t4,
|
|
884
|
+
headers: _context9.t5,
|
|
885
|
+
body: _context9.t6,
|
|
886
|
+
status: _context9.t7
|
|
887
|
+
});
|
|
888
|
+
case 23:
|
|
733
889
|
case "end":
|
|
734
|
-
return
|
|
890
|
+
return _context9.stop();
|
|
735
891
|
}
|
|
736
|
-
},
|
|
892
|
+
}, _callee9);
|
|
737
893
|
}));
|
|
738
894
|
return _send.apply(this, arguments);
|
|
739
895
|
}
|
|
@@ -818,53 +974,53 @@ function verify(_x7, _x8) {
|
|
|
818
974
|
* @returns {Buffer|null} The public key buffer or null
|
|
819
975
|
*/
|
|
820
976
|
function _verify() {
|
|
821
|
-
_verify = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
977
|
+
_verify = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(signedMessage, publicKey) {
|
|
822
978
|
var url, method, headers, body, keyLookup, pem, _signatureName, extractedKey, _pem, _request2, signatureName, extractedPublicKey, signatureInputHeader, algMatch, algorithm, verified, verificationError, verificationResult;
|
|
823
|
-
return _regeneratorRuntime().wrap(function
|
|
824
|
-
while (1) switch (
|
|
979
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
980
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
825
981
|
case 0:
|
|
826
|
-
|
|
982
|
+
_context14.prev = 0;
|
|
827
983
|
url = signedMessage.url, method = signedMessage.method, headers = signedMessage.headers, body = signedMessage.body; // Determine which public key to use
|
|
828
984
|
if (!publicKey) {
|
|
829
|
-
|
|
985
|
+
_context14.next = 7;
|
|
830
986
|
break;
|
|
831
987
|
}
|
|
832
988
|
// Use provided public key
|
|
833
989
|
pem = typeof publicKey === "string" ? publicKey : jwkModulusToPem(publicKey);
|
|
834
990
|
keyLookup = /*#__PURE__*/function () {
|
|
835
|
-
var
|
|
836
|
-
return _regeneratorRuntime().wrap(function
|
|
837
|
-
while (1) switch (
|
|
991
|
+
var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(keyId) {
|
|
992
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
993
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
838
994
|
case 0:
|
|
839
|
-
return
|
|
995
|
+
return _context11.abrupt("return", {
|
|
840
996
|
id: keyId,
|
|
841
997
|
algs: ["rsa-pss-sha512", "rsa-pss-sha256", "rsa-v1_5-sha256"],
|
|
842
998
|
verify: function () {
|
|
843
|
-
var _verify2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
999
|
+
var _verify2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(data, signature, parameters) {
|
|
844
1000
|
var verifier;
|
|
845
|
-
return _regeneratorRuntime().wrap(function
|
|
846
|
-
while (1) switch (
|
|
1001
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1002
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
847
1003
|
case 0:
|
|
848
1004
|
verifier = _crypto["default"].createVerify("RSA-SHA".concat(parameters.alg.includes("512") ? "512" : "256"));
|
|
849
1005
|
verifier.update(data);
|
|
850
1006
|
if (!parameters.alg.startsWith("rsa-pss")) {
|
|
851
|
-
|
|
1007
|
+
_context10.next = 6;
|
|
852
1008
|
break;
|
|
853
1009
|
}
|
|
854
|
-
return
|
|
1010
|
+
return _context10.abrupt("return", verifier.verify({
|
|
855
1011
|
key: pem,
|
|
856
1012
|
padding: _crypto["default"].constants.RSA_PKCS1_PSS_PADDING,
|
|
857
1013
|
saltLength: _crypto["default"].constants.RSA_PSS_SALTLEN_DIGEST
|
|
858
1014
|
}, signature));
|
|
859
1015
|
case 6:
|
|
860
|
-
return
|
|
1016
|
+
return _context10.abrupt("return", verifier.verify(pem, signature));
|
|
861
1017
|
case 7:
|
|
862
1018
|
case "end":
|
|
863
|
-
return
|
|
1019
|
+
return _context10.stop();
|
|
864
1020
|
}
|
|
865
|
-
},
|
|
1021
|
+
}, _callee10);
|
|
866
1022
|
}));
|
|
867
|
-
function verify(
|
|
1023
|
+
function verify(_x12, _x13, _x14) {
|
|
868
1024
|
return _verify2.apply(this, arguments);
|
|
869
1025
|
}
|
|
870
1026
|
return verify;
|
|
@@ -872,45 +1028,45 @@ function _verify() {
|
|
|
872
1028
|
});
|
|
873
1029
|
case 1:
|
|
874
1030
|
case "end":
|
|
875
|
-
return
|
|
1031
|
+
return _context11.stop();
|
|
876
1032
|
}
|
|
877
|
-
},
|
|
1033
|
+
}, _callee11);
|
|
878
1034
|
}));
|
|
879
|
-
return function keyLookup(
|
|
880
|
-
return
|
|
1035
|
+
return function keyLookup(_x11) {
|
|
1036
|
+
return _ref17.apply(this, arguments);
|
|
881
1037
|
};
|
|
882
1038
|
}();
|
|
883
|
-
|
|
1039
|
+
_context14.next = 13;
|
|
884
1040
|
break;
|
|
885
1041
|
case 7:
|
|
886
1042
|
// Extract public key from keyid
|
|
887
1043
|
_signatureName = extractSignatureName(headers);
|
|
888
1044
|
extractedKey = extractPublicKeyFromHeaders(headers, _signatureName);
|
|
889
1045
|
if (extractedKey) {
|
|
890
|
-
|
|
1046
|
+
_context14.next = 11;
|
|
891
1047
|
break;
|
|
892
1048
|
}
|
|
893
|
-
return
|
|
1049
|
+
return _context14.abrupt("return", {
|
|
894
1050
|
valid: false,
|
|
895
1051
|
error: "No public key provided and none found in signature"
|
|
896
1052
|
});
|
|
897
1053
|
case 11:
|
|
898
1054
|
_pem = jwkModulusToPem(extractedKey);
|
|
899
1055
|
keyLookup = /*#__PURE__*/function () {
|
|
900
|
-
var
|
|
901
|
-
return _regeneratorRuntime().wrap(function
|
|
902
|
-
while (1) switch (
|
|
1056
|
+
var _ref18 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(keyId) {
|
|
1057
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1058
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
903
1059
|
case 0:
|
|
904
|
-
return
|
|
1060
|
+
return _context13.abrupt("return", {
|
|
905
1061
|
id: keyId,
|
|
906
1062
|
algs: ["rsa-pss-sha512", "rsa-pss-sha256", "rsa-v1_5-sha256"],
|
|
907
1063
|
verify: function () {
|
|
908
|
-
var _verify3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1064
|
+
var _verify3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(data, signature, parameters) {
|
|
909
1065
|
var verifier, _verified;
|
|
910
|
-
return _regeneratorRuntime().wrap(function
|
|
911
|
-
while (1) switch (
|
|
1066
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1067
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
912
1068
|
case 0:
|
|
913
|
-
|
|
1069
|
+
_context12.prev = 0;
|
|
914
1070
|
verifier = _crypto["default"].createVerify("RSA-SHA".concat(parameters.alg.includes("512") ? "512" : "256"));
|
|
915
1071
|
verifier.update(data);
|
|
916
1072
|
if (parameters.alg.startsWith("rsa-pss")) {
|
|
@@ -922,19 +1078,19 @@ function _verify() {
|
|
|
922
1078
|
} else {
|
|
923
1079
|
_verified = verifier.verify(_pem, signature);
|
|
924
1080
|
}
|
|
925
|
-
return
|
|
1081
|
+
return _context12.abrupt("return", _verified);
|
|
926
1082
|
case 7:
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
console.error("Verification error:",
|
|
930
|
-
return
|
|
1083
|
+
_context12.prev = 7;
|
|
1084
|
+
_context12.t0 = _context12["catch"](0);
|
|
1085
|
+
console.error("Verification error:", _context12.t0);
|
|
1086
|
+
return _context12.abrupt("return", false);
|
|
931
1087
|
case 11:
|
|
932
1088
|
case "end":
|
|
933
|
-
return
|
|
1089
|
+
return _context12.stop();
|
|
934
1090
|
}
|
|
935
|
-
},
|
|
1091
|
+
}, _callee12, null, [[0, 7]]);
|
|
936
1092
|
}));
|
|
937
|
-
function verify(
|
|
1093
|
+
function verify(_x16, _x17, _x18) {
|
|
938
1094
|
return _verify3.apply(this, arguments);
|
|
939
1095
|
}
|
|
940
1096
|
return verify;
|
|
@@ -942,12 +1098,12 @@ function _verify() {
|
|
|
942
1098
|
});
|
|
943
1099
|
case 1:
|
|
944
1100
|
case "end":
|
|
945
|
-
return
|
|
1101
|
+
return _context13.stop();
|
|
946
1102
|
}
|
|
947
|
-
},
|
|
1103
|
+
}, _callee13);
|
|
948
1104
|
}));
|
|
949
|
-
return function keyLookup(
|
|
950
|
-
return
|
|
1105
|
+
return function keyLookup(_x15) {
|
|
1106
|
+
return _ref18.apply(this, arguments);
|
|
951
1107
|
};
|
|
952
1108
|
}();
|
|
953
1109
|
case 13:
|
|
@@ -964,26 +1120,26 @@ function _verify() {
|
|
|
964
1120
|
algorithm = algMatch ? algMatch[1] : undefined; // Verify using the library
|
|
965
1121
|
verified = false;
|
|
966
1122
|
verificationError = null;
|
|
967
|
-
|
|
968
|
-
|
|
1123
|
+
_context14.prev = 21;
|
|
1124
|
+
_context14.next = 24;
|
|
969
1125
|
return verifyMessage({
|
|
970
1126
|
keyLookup: keyLookup,
|
|
971
1127
|
requiredFields: [] // Don't require specific fields
|
|
972
1128
|
}, _request2);
|
|
973
1129
|
case 24:
|
|
974
|
-
verificationResult =
|
|
1130
|
+
verificationResult = _context14.sent;
|
|
975
1131
|
// If we get here without throwing, verification succeeded
|
|
976
1132
|
verified = true;
|
|
977
|
-
|
|
1133
|
+
_context14.next = 32;
|
|
978
1134
|
break;
|
|
979
1135
|
case 28:
|
|
980
|
-
|
|
981
|
-
|
|
1136
|
+
_context14.prev = 28;
|
|
1137
|
+
_context14.t0 = _context14["catch"](21);
|
|
982
1138
|
// Verification failed
|
|
983
|
-
verificationError =
|
|
1139
|
+
verificationError = _context14.t0.message;
|
|
984
1140
|
verified = false;
|
|
985
1141
|
case 32:
|
|
986
|
-
return
|
|
1142
|
+
return _context14.abrupt("return", _objectSpread({
|
|
987
1143
|
valid: true,
|
|
988
1144
|
// The signature format is valid
|
|
989
1145
|
verified: verified,
|
|
@@ -996,17 +1152,17 @@ function _verify() {
|
|
|
996
1152
|
error: verificationError
|
|
997
1153
|
}));
|
|
998
1154
|
case 35:
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
return
|
|
1155
|
+
_context14.prev = 35;
|
|
1156
|
+
_context14.t1 = _context14["catch"](0);
|
|
1157
|
+
return _context14.abrupt("return", {
|
|
1002
1158
|
valid: false,
|
|
1003
|
-
error:
|
|
1159
|
+
error: _context14.t1.message
|
|
1004
1160
|
});
|
|
1005
1161
|
case 38:
|
|
1006
1162
|
case "end":
|
|
1007
|
-
return
|
|
1163
|
+
return _context14.stop();
|
|
1008
1164
|
}
|
|
1009
|
-
},
|
|
1165
|
+
}, _callee14, null, [[0, 35], [21, 28]]);
|
|
1010
1166
|
}));
|
|
1011
1167
|
return _verify.apply(this, arguments);
|
|
1012
1168
|
}
|