solid-ui 2.4.27-9d7e618e → 2.4.27-9ee704cb

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/dist/solid-ui.js CHANGED
@@ -2655,7 +2655,7 @@ var ChatChannel = /*#__PURE__*/function () {
2655
2655
  var oldMsg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2656
2656
  var deleteIt = arguments.length > 2 ? arguments[2] : undefined;
2657
2657
  return /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
2658
- var sts, now, timestamp, dateStamp, chatDocument, message, me, msg, oldMsgMaker, errMsg, privateKey, _errMsg;
2658
+ var sts, now, timestamp, dateStamp, chatDocument, message, me, msg, oldMsgMaker, errMsg, privateKey, sig, _errMsg;
2659
2659
  return _regenerator["default"].wrap(function _callee2$(_context2) {
2660
2660
  while (1) switch (_context2.prev = _context2.next) {
2661
2661
  case 0:
@@ -2666,8 +2666,8 @@ var ChatChannel = /*#__PURE__*/function () {
2666
2666
  chatDocument = oldMsg ? oldMsg.doc() : _this.dateFolder.leafDocumentFromDate(now);
2667
2667
  message = _solidLogic.store.sym(chatDocument.uri + '#' + 'Msg' + timestamp); // const content = store.literal(text)
2668
2668
  me = _solidLogic.authn.currentUser(); // If already logged on
2669
- msg = _signature.getBlankMsg;
2670
- msg.id = message;
2669
+ msg = (0, _signature.getBlankMsg)();
2670
+ msg.id = message.uri;
2671
2671
  if (!oldMsg) {
2672
2672
  _context2.next = 22;
2673
2673
  break;
@@ -2682,7 +2682,7 @@ var ChatChannel = /*#__PURE__*/function () {
2682
2682
  if (deleteIt) {
2683
2683
  // we need to add a specific signature, else anyone can delete a msg ?
2684
2684
  sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument));
2685
- msg.dateDeleted = dateStamp;
2685
+ // msg.dateDeleted = dateStamp
2686
2686
  }
2687
2687
  _context2.next = 20;
2688
2688
  break;
@@ -2701,40 +2701,48 @@ var ChatChannel = /*#__PURE__*/function () {
2701
2701
  sts.push($rdf.st(message, ns.sioc('content'), _solidLogic.store.literal(text), chatDocument));
2702
2702
  msg.content = text;
2703
2703
  sts.push($rdf.st(message, ns.dct('created'), dateStamp, chatDocument));
2704
- msg.created = dateStamp;
2704
+ msg.created = dateStamp.value;
2705
2705
  if (!me) {
2706
- _context2.next = 34;
2706
+ _context2.next = 35;
2707
2707
  break;
2708
2708
  }
2709
2709
  sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument));
2710
- msg.maker = me;
2711
- // privateKey the cached private key of me, cache should be deleted after a certain time
2710
+ msg.maker = me.uri;
2711
+ // privateKey the cached private key of me, cached in store
2712
2712
  _context2.next = 32;
2713
2713
  return (0, _keys.getPrivateKey)(me);
2714
2714
  case 32:
2715
2715
  privateKey = _context2.sent;
2716
- sts.push($rdf.st(message, $rdf.sym("".concat(_signature.SEC, "Proof")), $rdf.sym((0, _signature.signMsg)(msg, privateKey), chatDocument)));
2717
- case 34:
2718
- _context2.prev = 34;
2719
- _context2.next = 37;
2716
+ // me.uri)
2717
+ // const privateKey0 = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
2718
+ sig = (0, _signature.signMsg)(msg, privateKey); // const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
2719
+ /* const pubKey = await getPublicKey(me)
2720
+ const verify = verifySignature(sig, msg, pubKey) // alain to remove
2721
+ debug.warn('sig ' + sig)
2722
+ debug.warn('verifySign ' + verify)
2723
+ debug.warn(msg) */
2724
+ sts.push($rdf.st(message, $rdf.sym("".concat(_signature.SEC, "Proof")), $rdf.lit(sig), chatDocument));
2725
+ case 35:
2726
+ _context2.prev = 35;
2727
+ _context2.next = 38;
2720
2728
  return _solidLogic.store.updater.update([], sts);
2721
- case 37:
2722
- _context2.next = 45;
2729
+ case 38:
2730
+ _context2.next = 46;
2723
2731
  break;
2724
- case 39:
2725
- _context2.prev = 39;
2726
- _context2.t0 = _context2["catch"](34);
2732
+ case 40:
2733
+ _context2.prev = 40;
2734
+ _context2.t0 = _context2["catch"](35);
2727
2735
  _errMsg = 'Error saving chat message: ' + _context2.t0;
2728
2736
  debug.warn(_errMsg);
2729
2737
  alert(_errMsg);
2730
2738
  throw new Error(_errMsg);
2731
- case 45:
2732
- return _context2.abrupt("return", message);
2733
2739
  case 46:
2740
+ return _context2.abrupt("return", message);
2741
+ case 47:
2734
2742
  case "end":
2735
2743
  return _context2.stop();
2736
2744
  }
2737
- }, _callee2, null, [[34, 39]]);
2745
+ }, _callee2, null, [[35, 40]]);
2738
2746
  })();
2739
2747
  });
2740
2748
  function updateMessage(_x2) {
@@ -4035,6 +4043,8 @@ var _utils = __webpack_require__(/*! @noble/hashes/utils */ "./node_modules/@nob
4035
4043
  var _signature = __webpack_require__(/*! ./signature */ "./lib/chat/signature.js");
4036
4044
  var _solidLogic = __webpack_require__(/*! solid-logic */ "./node_modules/solid-logic/lib/index.js");
4037
4045
  var $rdf = _interopRequireWildcard(__webpack_require__(/*! rdflib */ "./node_modules/rdflib/esm/index.js"));
4046
+ var _accessData = __webpack_require__(/*! ../utils/keyHelpers/accessData */ "./lib/utils/keyHelpers/accessData.js");
4047
+ var _acl = __webpack_require__(/*! ../utils/keyHelpers/acl */ "./lib/utils/keyHelpers/acl.js");
4038
4048
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
4039
4049
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
4040
4050
  function generatePrivateKey() {
@@ -4043,112 +4053,209 @@ function generatePrivateKey() {
4043
4053
  function generatePublicKey(privateKey) {
4044
4054
  return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
4045
4055
  }
4046
- function getPublicKey(webId) {
4047
- var publicKey = publicKeyExists(webId);
4048
- return publicKey === null || publicKey === void 0 ? void 0 : publicKey.uri;
4049
- }
4050
- function publicKeyExists(webId) {
4051
- // find publickey
4052
- var url = new URL(webId);
4053
- url.hash = '';
4054
- _solidLogic.store.fetcher.load(url.href);
4055
- var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'publicKey'));
4056
- return publicKey;
4057
- }
4058
- function privateKeyExists(_x) {
4059
- return _privateKeyExists.apply(this, arguments);
4056
+
4057
+ /**
4058
+ * getPublicKey
4059
+ * used for displaying messages in chat, therefore does not
4060
+ * create a new key if not found
4061
+ * @param webId
4062
+ * @returns string | undefined
4063
+ */
4064
+ function getPublicKey(_x) {
4065
+ return _getPublicKey.apply(this, arguments);
4060
4066
  }
4061
- function _privateKeyExists() {
4062
- _privateKeyExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
4063
- var url, privateKeyUrl, privateKey, _err$response, data, contentType, response;
4064
- return _regenerator["default"].wrap(function _callee$(_context) {
4065
- while (1) switch (_context.prev = _context.next) {
4067
+ function _getPublicKey() {
4068
+ _getPublicKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
4069
+ var publicKeyDoc, key;
4070
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
4071
+ while (1) switch (_context2.prev = _context2.next) {
4066
4072
  case 0:
4067
- url = new URL(webId);
4068
- privateKeyUrl = url.hostname + '/profile/privateKey.ttl';
4069
- _context.prev = 2;
4070
- _solidLogic.store.fetcher.load(privateKeyUrl);
4071
- privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'privateKey'));
4072
- return _context.abrupt("return", privateKey);
4073
+ _context2.next = 2;
4074
+ return _solidLogic.store.fetcher.load(webId);
4075
+ case 2:
4076
+ _context2.next = 4;
4077
+ return (0, _accessData.pubKeyUrl)(webId);
4078
+ case 4:
4079
+ publicKeyDoc = _context2.sent;
4080
+ _context2.prev = 5;
4081
+ _context2.next = 8;
4082
+ return _solidLogic.store.fetcher.load(publicKeyDoc);
4073
4083
  case 8:
4074
- _context.prev = 8;
4075
- _context.t0 = _context["catch"](2);
4076
- if (!((_context.t0 === null || _context.t0 === void 0 ? void 0 : (_err$response = _context.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status) === 404)) {
4077
- _context.next = 25;
4078
- break;
4079
- }
4080
- _context.prev = 11;
4081
- // create privateKey resource
4082
- data = '';
4083
- contentType = 'text/ttl';
4084
- _context.next = 16;
4085
- return _solidLogic.store.fetcher.webOperation('PUT', privateKeyUrl, {
4086
- data: data,
4087
- contentType: contentType
4088
- });
4089
- case 16:
4090
- response = _context.sent;
4091
- _context.next = 23;
4092
- break;
4093
- case 19:
4094
- _context.prev = 19;
4095
- _context.t1 = _context["catch"](11);
4096
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t1);
4097
- throw _context.t1;
4098
- case 23:
4099
- delete _solidLogic.store.fetcher.requested[privateKeyUrl]; // delete cached 404 error
4100
- return _context.abrupt("return", undefined);
4101
- case 25:
4102
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t0);
4103
- throw _context.t0;
4104
- case 27:
4084
+ // url.href)
4085
+ key = _solidLogic.store.any(webId, _solidLogic.store.sym(_signature.CERT + 'PublicKey'));
4086
+ return _context2.abrupt("return", key === null || key === void 0 ? void 0 : key.value);
4087
+ case 12:
4088
+ _context2.prev = 12;
4089
+ _context2.t0 = _context2["catch"](5);
4090
+ return _context2.abrupt("return", undefined);
4091
+ case 15:
4105
4092
  case "end":
4106
- return _context.stop();
4093
+ return _context2.stop();
4107
4094
  }
4108
- }, _callee, null, [[2, 8], [11, 19]]);
4095
+ }, _callee2, null, [[5, 12]]);
4109
4096
  }));
4110
- return _privateKeyExists.apply(this, arguments);
4097
+ return _getPublicKey.apply(this, arguments);
4111
4098
  }
4112
4099
  function getPrivateKey(_x2) {
4113
4100
  return _getPrivateKey.apply(this, arguments);
4114
4101
  }
4115
4102
  function _getPrivateKey() {
4116
- _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
4117
- var url, privateKeyUrl, publicKey, privateKey, del, add;
4118
- return _regenerator["default"].wrap(function _callee2$(_context2) {
4119
- while (1) switch (_context2.prev = _context2.next) {
4103
+ _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(webId) {
4104
+ var publicKeyDoc, privateKeyDoc, publicKey, privateKey, validPublicKey, del, add, newPublicKey, keyContainer;
4105
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
4106
+ while (1) switch (_context3.prev = _context3.next) {
4120
4107
  case 0:
4121
- url = new URL(webId);
4122
- privateKeyUrl = url.hostname + '/profile/privateKey.ttl'; // find publickey
4123
- publicKey = publicKeyExists(webId); // find privateKey
4124
- _context2.next = 5;
4125
- return privateKeyExists(webId);
4126
- case 5:
4127
- privateKey = _context2.sent;
4128
- if (!(!privateKey || !publicKey)) {
4129
- _context2.next = 17;
4108
+ _context3.next = 2;
4109
+ return _solidLogic.store.fetcher.load(webId);
4110
+ case 2:
4111
+ _context3.next = 4;
4112
+ return (0, _accessData.pubKeyUrl)(webId);
4113
+ case 4:
4114
+ publicKeyDoc = _context3.sent;
4115
+ _context3.next = 7;
4116
+ return (0, _accessData.privKeyUrl)(webId);
4117
+ case 7:
4118
+ privateKeyDoc = _context3.sent;
4119
+ _context3.next = 10;
4120
+ return (0, _accessData.getExistingPublicKey)(webId, publicKeyDoc);
4121
+ case 10:
4122
+ publicKey = _context3.sent;
4123
+ _context3.next = 13;
4124
+ return (0, _accessData.getExistingPrivateKey)(webId, privateKeyDoc);
4125
+ case 13:
4126
+ privateKey = _context3.sent;
4127
+ // is publicKey valid ?
4128
+ validPublicKey = true;
4129
+ if (privateKey && publicKey !== generatePublicKey(privateKey)) {
4130
+ if (confirm('This is strange the publicKey is not valid for\n' + (webId === null || webId === void 0 ? void 0 : webId.uri) + '\'shall we repair keeping the private key ?')) validPublicKey = false;
4131
+ }
4132
+
4133
+ // create key pair or repair publicKey
4134
+ if (!(!privateKey || !publicKey || !validPublicKey)) {
4135
+ _context3.next = 34;
4130
4136
  break;
4131
4137
  }
4132
4138
  del = [];
4133
- add = [];
4134
- if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), privateKey, $rdf.sym(privateKeyUrl)));
4135
- if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), publicKey, $rdf.sym(url.href)));
4136
- privateKey = _solidLogic.store.sym(generatePrivateKey());
4137
- publicKey = _solidLogic.store.sym(generatePublicKey(privateKey.uri));
4138
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), $rdf.literal(privateKey.uri), $rdf.sym(privateKeyUrl)));
4139
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), $rdf.literal(publicKey.uri), $rdf.sym(url.href)));
4140
- _context2.next = 17;
4141
- return _solidLogic.store.updater.updateMany(del, add);
4142
- case 17:
4143
- return _context2.abrupt("return", privateKey.uri);
4144
- case 18:
4139
+ add = []; // if (privateKey) del.push($rdf.st(webId, store.sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), store.sym(privateKeyDoc)))
4140
+ if (privateKey) {
4141
+ _context3.next = 24;
4142
+ break;
4143
+ }
4144
+ // add = []
4145
+ privateKey = generatePrivateKey();
4146
+ add = [$rdf.st(webId, _solidLogic.store.sym(_signature.CERT + 'PrivateKey'), $rdf.literal(privateKey), _solidLogic.store.sym(privateKeyDoc))];
4147
+ _context3.next = 24;
4148
+ return saveKey(privateKeyDoc, [], add, webId.uri);
4149
+ case 24:
4150
+ if (!(!publicKey || !validPublicKey)) {
4151
+ _context3.next = 31;
4152
+ break;
4153
+ }
4154
+ del = [];
4155
+ // delete invalid public key
4156
+ if (publicKey) {
4157
+ del = [$rdf.st(webId, _solidLogic.store.sym(_signature.CERT + 'PublicKey'), $rdf.lit(publicKey), _solidLogic.store.sym(publicKeyDoc))];
4158
+ debug.log(del);
4159
+ }
4160
+ // update new valid key
4161
+ newPublicKey = generatePublicKey(privateKey);
4162
+ add = [$rdf.st(webId, _solidLogic.store.sym(_signature.CERT + 'PublicKey'), $rdf.literal(newPublicKey), _solidLogic.store.sym(publicKeyDoc))];
4163
+ _context3.next = 31;
4164
+ return saveKey(publicKeyDoc, del, add);
4165
+ case 31:
4166
+ keyContainer = privateKeyDoc.substring(0, privateKeyDoc.lastIndexOf('/') + 1);
4167
+ _context3.next = 34;
4168
+ return (0, _acl.setAcl)(keyContainer, (0, _acl.keyContainerAclBody)(webId.uri));
4169
+ case 34:
4170
+ return _context3.abrupt("return", privateKey);
4171
+ case 35:
4145
4172
  case "end":
4146
- return _context2.stop();
4173
+ return _context3.stop();
4147
4174
  }
4148
- }, _callee2);
4175
+ }, _callee3);
4149
4176
  }));
4150
4177
  return _getPrivateKey.apply(this, arguments);
4151
4178
  }
4179
+ var deleteKeyAcl = /*#__PURE__*/function () {
4180
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(keyDoc) {
4181
+ var keyAclDoc, response;
4182
+ return _regenerator["default"].wrap(function _callee$(_context) {
4183
+ while (1) switch (_context.prev = _context.next) {
4184
+ case 0:
4185
+ _context.next = 2;
4186
+ return _solidLogic.store.fetcher.load(keyDoc);
4187
+ case 2:
4188
+ keyAclDoc = _solidLogic.store.any(_solidLogic.store.sym(keyDoc), _solidLogic.store.sym('http://www.iana.org/assignments/link-relations/acl'));
4189
+ if (!keyAclDoc) {
4190
+ _context.next = 16;
4191
+ break;
4192
+ }
4193
+ _context.prev = 4;
4194
+ _context.next = 7;
4195
+ return _solidLogic.store.fetcher.webOperation('DELETE', keyAclDoc.value);
4196
+ case 7:
4197
+ response = _context.sent;
4198
+ // this may fail if webId is not an owner
4199
+ debug.log('delete ' + keyAclDoc.value + ' ' + response.status); // should test 404 and 2xx
4200
+ _context.next = 16;
4201
+ break;
4202
+ case 11:
4203
+ _context.prev = 11;
4204
+ _context.t0 = _context["catch"](4);
4205
+ if (!(_context.t0.response.status !== 404)) {
4206
+ _context.next = 15;
4207
+ break;
4208
+ }
4209
+ throw new Error(_context.t0);
4210
+ case 15:
4211
+ debug.log('delete ' + keyAclDoc.value + ' ' + _context.t0.response.status); // should test 404 and 2xx
4212
+ case 16:
4213
+ case "end":
4214
+ return _context.stop();
4215
+ }
4216
+ }, _callee, null, [[4, 11]]);
4217
+ }));
4218
+ return function deleteKeyAcl(_x3) {
4219
+ return _ref.apply(this, arguments);
4220
+ };
4221
+ }();
4222
+
4223
+ /**
4224
+ * delete acl if keydoc exists
4225
+ * create/edit keyDoc
4226
+ * set keyDoc acl
4227
+ */
4228
+ function saveKey(_x4, _x5, _x6) {
4229
+ return _saveKey.apply(this, arguments);
4230
+ }
4231
+ function _saveKey() {
4232
+ _saveKey = (0, _asyncToGenerator2["default"])(function (keyDoc, del, add) {
4233
+ var me = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
4234
+ return /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
4235
+ var aclBody;
4236
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
4237
+ while (1) switch (_context4.prev = _context4.next) {
4238
+ case 0:
4239
+ _context4.next = 2;
4240
+ return deleteKeyAcl(keyDoc);
4241
+ case 2:
4242
+ _context4.next = 4;
4243
+ return _solidLogic.store.updater.updateMany(del, add);
4244
+ case 4:
4245
+ // or a promise store.updater.update ?
4246
+ // create READ only ACL
4247
+ aclBody = (0, _acl.keyAclBody)(keyDoc, me);
4248
+ _context4.next = 7;
4249
+ return (0, _acl.setAcl)(keyDoc, aclBody);
4250
+ case 7:
4251
+ case "end":
4252
+ return _context4.stop();
4253
+ }
4254
+ }, _callee4);
4255
+ })();
4256
+ });
4257
+ return _saveKey.apply(this, arguments);
4258
+ }
4152
4259
  //# sourceMappingURL=keys.js.map
4153
4260
 
4154
4261
  /***/ }),
@@ -4201,7 +4308,11 @@ var messageBodyStyle = style.messageBodyStyle;
4201
4308
  var label = utils.label;
4202
4309
 
4203
4310
  /**
4311
+ * elementForImageURI
4204
4312
  * HTML component for an image
4313
+ * @param imageUri
4314
+ * @param options { inlineImageHeightEms }
4315
+ * @returns HTMLAnchorElement For Image
4205
4316
  */
4206
4317
  function elementForImageURI(imageUri, options) {
4207
4318
  var img = dom.createElement('img');
@@ -4231,21 +4342,27 @@ var anchor = function anchor(text, term) {
4231
4342
  a.textContent = text;
4232
4343
  return a;
4233
4344
  };
4234
- function nick(person) {
4345
+ function nickname(person) {
4235
4346
  var s = _solidLogic.store.any(person, ns.foaf('nick'));
4236
4347
  if (s) return '' + s.value;
4237
4348
  return '' + label(person);
4238
4349
  }
4239
4350
 
4240
4351
  /**
4352
+ * creatorAndDate
4241
4353
  * Displays creator and date for a chat message
4242
4354
  * inside the `td1` element
4355
+ * @param td1
4356
+ * @param creator
4357
+ * @param date
4358
+ * @param message
4359
+ * @returns HTMLAnchorElement For Image
4243
4360
  */
4244
4361
  function creatorAndDate(td1, creator, date, message) {
4245
- var nickAnchor = td1.appendChild(anchor(nick(creator), creator));
4362
+ var nickAnchor = td1.appendChild(anchor(nickname(creator), creator));
4246
4363
  if (creator.uri) {
4247
4364
  _solidLogic.store.fetcher.nowOrWhenFetched(creator.doc(), undefined, function (_ok, _body) {
4248
- nickAnchor.textContent = nick(creator);
4365
+ nickAnchor.textContent = nickname(creator);
4249
4366
  });
4250
4367
  }
4251
4368
  td1.appendChild(dom.createElement('br'));
@@ -4253,14 +4370,20 @@ function creatorAndDate(td1, creator, date, message) {
4253
4370
  }
4254
4371
 
4255
4372
  /**
4373
+ * creatorAndDateHorizontal
4256
4374
  * Horizontally displays creator and date for a chat message
4257
4375
  * inside the `td1` element
4376
+ * @param td1
4377
+ * @param creator
4378
+ * @param date
4379
+ * @param message
4380
+ * @returns HTMLAnchorElement For Image
4258
4381
  */
4259
4382
  function creatorAndDateHorizontal(td1, creator, date, message) {
4260
4383
  var nickAnchor = td1.appendChild(anchor(label(creator), creator));
4261
4384
  if (creator.uri) {
4262
4385
  _solidLogic.store.fetcher.nowOrWhenFetched(creator.doc(), undefined, function (_ok, _body) {
4263
- nickAnchor.textContent = nick(creator);
4386
+ nickAnchor.textContent = nickname(creator);
4264
4387
  });
4265
4388
  }
4266
4389
  var dateBit = td1.appendChild(anchor(date, message));
@@ -4270,33 +4393,61 @@ function creatorAndDateHorizontal(td1, creator, date, message) {
4270
4393
  }
4271
4394
 
4272
4395
  /**
4396
+ * renderMessageRow
4273
4397
  * Renders a chat message, read-only mode
4398
+ * @param channelObject
4399
+ * @param message
4400
+ * @param fresh
4401
+ * @param options
4402
+ * @param userContext
4403
+ * @returns Message Row HTML Table Element
4274
4404
  */
4275
4405
  function renderMessageRow(channelObject, message, fresh, options, userContext) {
4406
+ var unsignedMessage = false;
4276
4407
  var colorizeByAuthor = options.colorizeByAuthor === '1' || options.colorizeByAuthor === true;
4277
4408
  var creator = _solidLogic.store.any(message, ns.foaf('maker'));
4278
4409
  var date = _solidLogic.store.any(message, ns.dct('created'));
4279
4410
  var latestVersion = (0, _chatLogic.mostRecentVersion)(message);
4280
- var content = _solidLogic.store.any(latestVersion, ns.sioc('content'));
4281
- var signature = _solidLogic.store.any(message, $rdf.sym("".concat(_signature.SEC, "Proof")));
4411
+ var latestVersionCreator = _solidLogic.store.any(latestVersion, ns.foaf('maker'));
4282
4412
 
4283
- // verify signature
4413
+ // use latest content if same owner, else use original
4414
+ var msgId = creator.uri === latestVersionCreator.uri ? latestVersion : message;
4415
+ var content = _solidLogic.store.any(msgId, ns.sioc('content'));
4416
+ var signature = _solidLogic.store.any(msgId, $rdf.sym("".concat(_signature.SEC, "Proof")));
4417
+
4418
+ // set message object
4284
4419
  var msg = (0, _signature.getBlankMsg)();
4285
- msg.id = message;
4286
- msg.created = date;
4287
- // this is not correct.
4288
- // If the message has been edited/deleted we must verify the latest message and may be the intermediate ones
4289
- msg.content = content;
4290
- msg.maker = creator;
4291
-
4292
- // pubKey could be store in a cache for all makers
4293
- var pubKey = (0, _keys.getPublicKey)(creator); // alain no
4294
- if (!(0, _signature.verifySignature)(signature, msg, pubKey)) throw new Error();
4420
+ msg.id = msgId.uri;
4421
+ msg.created = _solidLogic.store.any(msgId, ns.dct('created')).value;
4422
+ msg.content = content.value;
4423
+ msg.maker = creator.uri;
4424
+
4425
+ // unsigned message
4426
+ if (!(signature !== null && signature !== void 0 && signature.value)) {
4427
+ unsignedMessage = true;
4428
+ debug.warn(msgId.uri + ' is unsigned'); // TODO replace with UI (colored message ?)
4429
+ } else {
4430
+ // signed message, get public key and check signature
4431
+ (0, _keys.getPublicKey)(creator).then(function (publicKey) {
4432
+ debug.log(creator.uri + '\n' + msg.created + '\n' + msg.id + '\n' + publicKey);
4433
+ if (!publicKey) {
4434
+ // TODO try to recreate the publicKey
4435
+ // if(me.uri === creator.uri) await getPrivateKey(creator)
4436
+ debug.warn('message is signed but ' + creator.uri + ' is missing publicKey');
4437
+ }
4438
+ // check that publicKey is a valid hex string
4439
+ var regex = /[0-9A-Fa-f]{6}/g;
4440
+ if (!(publicKey !== null && publicKey !== void 0 && publicKey.match(regex))) debug.warn('invalid publicKey hex string\n' + creator.uri + '\n' + publicKey);
4441
+ // verify signature
4442
+ else if (signature !== null && signature !== void 0 && signature.value && !(0, _signature.verifySignature)(signature === null || signature === void 0 ? void 0 : signature.value, msg, publicKey)) debug.warn('invalid signature\n' + msg.id);
4443
+ });
4444
+ }
4295
4445
  var originalMessage = (0, _chatLogic.originalVersion)(message);
4296
4446
  var edited = !message.sameTerm(originalMessage);
4297
4447
  var sortDate = _solidLogic.store.the(originalMessage, ns.dct('created'), null, originalMessage.doc()); // In message
4298
4448
 
4299
4449
  var messageRow = dom.createElement('tr');
4450
+ if (unsignedMessage) messageRow.setAttribute('style', 'background-color: red');
4300
4451
  messageRow.AJAR_date = sortDate.value;
4301
4452
  messageRow.AJAR_subject = message;
4302
4453
  var td1 = dom.createElement('td');
@@ -4385,7 +4536,8 @@ function renderMessageRow(channelObject, message, fresh, options, userContext) {
4385
4536
  toolsTD.appendChild(tools);
4386
4537
  });
4387
4538
  return messageRow;
4388
- }
4539
+ } // END OF RENDERMESSAGE
4540
+
4389
4541
  function switchToEditor(messageRow, message, channelObject, userContext) {
4390
4542
  var messageTable = messageRow.parentNode;
4391
4543
  var editRow = renderMessageEditor(channelObject, messageTable, userContext, channelObject.options, (0, _chatLogic.mostRecentVersion)(message));
@@ -5085,13 +5237,11 @@ Object.defineProperty(exports, "__esModule", ({
5085
5237
  value: true
5086
5238
  }));
5087
5239
  exports.SEC = exports.CERT = void 0;
5088
- exports.finishMsg = finishMsg;
5089
5240
  exports.getBlankMsg = getBlankMsg;
5090
5241
  exports.getMsgHash = getMsgHash;
5091
5242
  exports.serializeMsg = serializeMsg;
5092
5243
  exports.signMsg = signMsg;
5093
5244
  exports.utf8Encoder = exports.utf8Decoder = void 0;
5094
- exports.validateMsg = validateMsg;
5095
5245
  exports.verifySignature = verifySignature;
5096
5246
  var _secp256k = __webpack_require__(/*! @noble/curves/secp256k1 */ "./node_modules/@noble/curves/secp256k1.js");
5097
5247
  var _utils = __webpack_require__(/*! @noble/hashes/utils */ "./node_modules/@noble/hashes/utils.js");
@@ -5105,7 +5255,7 @@ var utf8Encoder = new TextEncoder();
5105
5255
  exports.utf8Encoder = utf8Encoder;
5106
5256
  var SEC = 'https://w3id.org/security#'; // Proof, VerificationMethod
5107
5257
  exports.SEC = SEC;
5108
- var CERT = 'http://www.w3.org/ns/auth/cert#'; // PrivatKey, PublicKey
5258
+ var CERT = 'http://www.w3.org/ns/auth/cert#'; // PrivateKey, PublicKey
5109
5259
 
5110
5260
  /* eslint-disable no-unused-vars */
5111
5261
  /* export enum Kind {
@@ -5137,19 +5287,22 @@ function getBlankMsg() {
5137
5287
  id: '',
5138
5288
  created: '',
5139
5289
  dateDeleted: '',
5290
+ // TODO to remove if not used
5140
5291
  content: '',
5141
5292
  maker: '',
5142
- sig: ''
5293
+ sig: '' // TODO to remove if not used
5143
5294
  };
5144
5295
  }
5145
- function finishMsg(t, privateKey) {
5146
- // to update to chat message triples
5147
- var message = t;
5148
- // message.pubkey = getPublicKey(privateKey)
5149
- message.id = getMsgHash(message);
5150
- message.sig = signMsg(message, privateKey);
5151
- return message;
5152
- }
5296
+
5297
+ /* export function finishMsg (t: MsgTemplate, privateKey: string): Message {
5298
+ // to update to chat message triples
5299
+ const message = t as Message
5300
+ // message.pubkey = getPublicKey(privateKey)
5301
+ message.id = getMsgHash(message)
5302
+ message.sig = signMsg(message, privateKey)
5303
+ return message
5304
+ } */
5305
+
5153
5306
  function serializeMsg(msg) {
5154
5307
  // to update to chat messages triples
5155
5308
  /* if (!validateMsg(msg))
@@ -5161,27 +5314,29 @@ function getMsgHash(message) {
5161
5314
  var msgHash = (0, _sha.sha256)(utf8Encoder.encode(serializeMsg(message)));
5162
5315
  return (0, _utils.bytesToHex)(msgHash);
5163
5316
  }
5164
- var isRecord = function isRecord(obj) {
5165
- return obj instanceof Object;
5166
- };
5167
- function validateMsg(message) {
5168
- /* if (!isRecord(message)) return false
5317
+
5318
+ // const isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object
5319
+
5320
+ /* export function validateMsg<T> (message: T): message is T & UnsignedMsg {
5321
+ if (!isRecord(message)) return false
5169
5322
  if (typeof message.kind !== 'number') return false
5170
5323
  if (typeof message.content !== 'string') return false
5171
5324
  if (typeof message.created_at !== 'number') return false
5172
5325
  if (typeof message.pubkey !== 'string') return false
5173
5326
  if (!message.pubkey.match(/^[a-f0-9]{64}$/)) return false
5174
- if (!Array.isArray(message.tags)) return false
5327
+
5328
+ if (!Array.isArray(message.tags)) return false
5175
5329
  for (let i = 0; i < message.tags.length; i++) {
5176
5330
  let tag = message.tags[i]
5177
5331
  if (!Array.isArray(tag)) return false
5178
5332
  for (let j = 0; j < tag.length; j++) {
5179
5333
  if (typeof tag[j] === 'object') return false
5180
5334
  }
5181
- } */
5335
+ }
5336
+
5337
+ return true
5338
+ } */
5182
5339
 
5183
- return true;
5184
- }
5185
5340
  function verifySignature(sig, message, pubKey) {
5186
5341
  return _secp256k.schnorr.verify(sig, getMsgHash(message), pubKey);
5187
5342
  }
@@ -13110,6 +13265,328 @@ function predParentOf(node) {
13110
13265
 
13111
13266
  /***/ }),
13112
13267
 
13268
+ /***/ "./lib/utils/keyHelpers/accessData.js":
13269
+ /*!********************************************!*\
13270
+ !*** ./lib/utils/keyHelpers/accessData.js ***!
13271
+ \********************************************/
13272
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
13273
+
13274
+ "use strict";
13275
+
13276
+
13277
+ var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js");
13278
+ var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
13279
+ Object.defineProperty(exports, "__esModule", ({
13280
+ value: true
13281
+ }));
13282
+ exports.getExistingPrivateKey = getExistingPrivateKey;
13283
+ exports.getExistingPublicKey = getExistingPublicKey;
13284
+ exports.getKeyIfExists = getKeyIfExists;
13285
+ exports.pubKeyUrl = exports.privKeyUrl = exports.getPodRoot = void 0;
13286
+ var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js"));
13287
+ var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ "./node_modules/@babel/runtime/helpers/asyncToGenerator.js"));
13288
+ var debug = _interopRequireWildcard(__webpack_require__(/*! ../../debug */ "./lib/debug.js"));
13289
+ var _signature = __webpack_require__(/*! ../../chat/signature */ "./lib/chat/signature.js");
13290
+ var _solidLogic = __webpack_require__(/*! solid-logic */ "./node_modules/solid-logic/lib/index.js");
13291
+ var ns = _interopRequireWildcard(__webpack_require__(/*! ../../ns */ "./lib/ns.js"));
13292
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13293
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13294
+ var getPodRoot = /*#__PURE__*/function () {
13295
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
13296
+ var webIdURL, storages, podRoot, path, _res$headers$get, res;
13297
+ return _regenerator["default"].wrap(function _callee$(_context) {
13298
+ while (1) switch (_context.prev = _context.next) {
13299
+ case 0:
13300
+ webIdURL = new URL(webId.uri); // find storages in webId document
13301
+ _context.next = 3;
13302
+ return _solidLogic.store.fetcher.load(webId.uri);
13303
+ case 3:
13304
+ storages = _solidLogic.store.each(webId, ns.space('storage'), null, webId.doc());
13305
+ if (storages !== null && storages !== void 0 && storages.length) {
13306
+ _context.next = 19;
13307
+ break;
13308
+ }
13309
+ // find storage recursively in webId URL
13310
+ path = webIdURL.pathname;
13311
+ case 6:
13312
+ if (!path.length) {
13313
+ _context.next = 17;
13314
+ break;
13315
+ }
13316
+ path = path.substring(0, path.lastIndexOf('/'));
13317
+ podRoot = _solidLogic.store.sym(webIdURL.origin + path + '/');
13318
+ _context.next = 11;
13319
+ return _solidLogic.store.fetcher.webOperation('HEAD', podRoot.uri);
13320
+ case 11:
13321
+ res = _context.sent;
13322
+ if (!((_res$headers$get = res.headers.get('link')) !== null && _res$headers$get !== void 0 && _res$headers$get.includes(ns.space('Storage').value))) {
13323
+ _context.next = 14;
13324
+ break;
13325
+ }
13326
+ return _context.abrupt("break", 17);
13327
+ case 14:
13328
+ if (!path) debug.warn("Current user storage not found for\n".concat(webId));
13329
+ _context.next = 6;
13330
+ break;
13331
+ case 17:
13332
+ _context.next = 21;
13333
+ break;
13334
+ case 19:
13335
+ // give preference to storage in webId root
13336
+ podRoot = storages.find(function (storage) {
13337
+ return webIdURL.origin === new URL(storage.value).origin;
13338
+ });
13339
+ if (!podRoot) podRoot = storages[0];
13340
+ case 21:
13341
+ return _context.abrupt("return", podRoot);
13342
+ case 22:
13343
+ case "end":
13344
+ return _context.stop();
13345
+ }
13346
+ }, _callee);
13347
+ }));
13348
+ return function getPodRoot(_x) {
13349
+ return _ref.apply(this, arguments);
13350
+ };
13351
+ }();
13352
+ exports.getPodRoot = getPodRoot;
13353
+ var pubKeyUrl = /*#__PURE__*/function () {
13354
+ var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
13355
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
13356
+ while (1) switch (_context2.prev = _context2.next) {
13357
+ case 0:
13358
+ _context2.prev = 0;
13359
+ _context2.next = 3;
13360
+ return getPodRoot(webId);
13361
+ case 3:
13362
+ _context2.t0 = _context2.sent.value;
13363
+ return _context2.abrupt("return", _context2.t0 + 'profile/keys/publicKey.ttl');
13364
+ case 7:
13365
+ _context2.prev = 7;
13366
+ _context2.t1 = _context2["catch"](0);
13367
+ throw new Error(_context2.t1);
13368
+ case 10:
13369
+ case "end":
13370
+ return _context2.stop();
13371
+ }
13372
+ }, _callee2, null, [[0, 7]]);
13373
+ }));
13374
+ return function pubKeyUrl(_x2) {
13375
+ return _ref2.apply(this, arguments);
13376
+ };
13377
+ }();
13378
+ exports.pubKeyUrl = pubKeyUrl;
13379
+ function getExistingPublicKey(_x3, _x4) {
13380
+ return _getExistingPublicKey.apply(this, arguments);
13381
+ }
13382
+ function _getExistingPublicKey() {
13383
+ _getExistingPublicKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(webId, publicKeyUrl) {
13384
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
13385
+ while (1) switch (_context4.prev = _context4.next) {
13386
+ case 0:
13387
+ _context4.next = 2;
13388
+ return getKeyIfExists(webId, publicKeyUrl, 'PublicKey');
13389
+ case 2:
13390
+ return _context4.abrupt("return", _context4.sent);
13391
+ case 3:
13392
+ case "end":
13393
+ return _context4.stop();
13394
+ }
13395
+ }, _callee4);
13396
+ }));
13397
+ return _getExistingPublicKey.apply(this, arguments);
13398
+ }
13399
+ var privKeyUrl = /*#__PURE__*/function () {
13400
+ var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(webId) {
13401
+ var _store$any, _settings;
13402
+ var settings, _settings2, podRoot;
13403
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
13404
+ while (1) switch (_context3.prev = _context3.next) {
13405
+ case 0:
13406
+ settings = (_store$any = _solidLogic.store.any(webId, ns.space('preferencesFile'), null, webId.doc())) === null || _store$any === void 0 ? void 0 : _store$any.value;
13407
+ settings = (_settings = settings) === null || _settings === void 0 ? void 0 : _settings.split('/').slice(0, -1).join('/');
13408
+ _context3.prev = 2;
13409
+ _context3.next = 5;
13410
+ return getPodRoot(webId);
13411
+ case 5:
13412
+ podRoot = _context3.sent;
13413
+ if ((_settings2 = settings) !== null && _settings2 !== void 0 && _settings2.startsWith(podRoot.value)) {
13414
+ _context3.next = 8;
13415
+ break;
13416
+ }
13417
+ throw new Error("/settings/ is expected to be in ".concat(podRoot.value));
13418
+ case 8:
13419
+ return _context3.abrupt("return", "".concat(settings, "/keys/privateKey.ttl"));
13420
+ case 11:
13421
+ _context3.prev = 11;
13422
+ _context3.t0 = _context3["catch"](2);
13423
+ throw new Error(_context3.t0);
13424
+ case 14:
13425
+ case "end":
13426
+ return _context3.stop();
13427
+ }
13428
+ }, _callee3, null, [[2, 11]]);
13429
+ }));
13430
+ return function privKeyUrl(_x5) {
13431
+ return _ref3.apply(this, arguments);
13432
+ };
13433
+ }();
13434
+ exports.privKeyUrl = privKeyUrl;
13435
+ function getExistingPrivateKey(_x6, _x7) {
13436
+ return _getExistingPrivateKey.apply(this, arguments);
13437
+ }
13438
+ function _getExistingPrivateKey() {
13439
+ _getExistingPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(webId, privateKeyUrl) {
13440
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
13441
+ while (1) switch (_context5.prev = _context5.next) {
13442
+ case 0:
13443
+ _context5.next = 2;
13444
+ return getKeyIfExists(webId, privateKeyUrl, 'PrivateKey');
13445
+ case 2:
13446
+ return _context5.abrupt("return", _context5.sent);
13447
+ case 3:
13448
+ case "end":
13449
+ return _context5.stop();
13450
+ }
13451
+ }, _callee5);
13452
+ }));
13453
+ return _getExistingPrivateKey.apply(this, arguments);
13454
+ }
13455
+ function getKeyIfExists(_x8, _x9, _x10) {
13456
+ return _getKeyIfExists.apply(this, arguments);
13457
+ }
13458
+ function _getKeyIfExists() {
13459
+ _getKeyIfExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(webId, keyUrl, keyType) {
13460
+ var key;
13461
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
13462
+ while (1) switch (_context6.prev = _context6.next) {
13463
+ case 0:
13464
+ _context6.prev = 0;
13465
+ _context6.next = 3;
13466
+ return _solidLogic.store.fetcher.load(keyUrl);
13467
+ case 3:
13468
+ key = _solidLogic.store.any(webId, _solidLogic.store.sym(_signature.CERT + keyType));
13469
+ return _context6.abrupt("return", key === null || key === void 0 ? void 0 : key.value);
13470
+ case 7:
13471
+ _context6.prev = 7;
13472
+ _context6.t0 = _context6["catch"](0);
13473
+ debug.log('createIfNotExists doc FAILED: ' + keyUrl + ': ' + _context6.t0);
13474
+ throw _context6.t0;
13475
+ case 11:
13476
+ case "end":
13477
+ return _context6.stop();
13478
+ }
13479
+ }, _callee6, null, [[0, 7]]);
13480
+ }));
13481
+ return _getKeyIfExists.apply(this, arguments);
13482
+ }
13483
+ //# sourceMappingURL=accessData.js.map
13484
+
13485
+ /***/ }),
13486
+
13487
+ /***/ "./lib/utils/keyHelpers/acl.js":
13488
+ /*!*************************************!*\
13489
+ !*** ./lib/utils/keyHelpers/acl.js ***!
13490
+ \*************************************/
13491
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
13492
+
13493
+ "use strict";
13494
+
13495
+
13496
+ var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js");
13497
+ var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
13498
+ Object.defineProperty(exports, "__esModule", ({
13499
+ value: true
13500
+ }));
13501
+ exports.keyContainerAclBody = exports.keyAclBody = void 0;
13502
+ exports.setAcl = setAcl;
13503
+ var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js"));
13504
+ var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ "./node_modules/@babel/runtime/helpers/asyncToGenerator.js"));
13505
+ var debug = _interopRequireWildcard(__webpack_require__(/*! ../../debug */ "./lib/debug.js"));
13506
+ var _solidLogic = __webpack_require__(/*! solid-logic */ "./node_modules/solid-logic/lib/index.js");
13507
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13508
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13509
+ /**
13510
+ * set ACL
13511
+ * @param keyDoc
13512
+ * @param aclBody
13513
+ */
13514
+ function setAcl(_x, _x2) {
13515
+ return _setAcl.apply(this, arguments);
13516
+ }
13517
+ /**
13518
+ * key container ACL
13519
+ * @param me
13520
+ * @returns aclBody
13521
+ */
13522
+ function _setAcl() {
13523
+ _setAcl = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(keyDoc, aclBody) {
13524
+ var keyAclDoc, _err$response;
13525
+ return _regenerator["default"].wrap(function _callee$(_context) {
13526
+ while (1) switch (_context.prev = _context.next) {
13527
+ case 0:
13528
+ _context.next = 2;
13529
+ return _solidLogic.store.fetcher.load(keyDoc);
13530
+ case 2:
13531
+ // FIXME: check the Why value on this quad:
13532
+ debug.log(_solidLogic.store.statementsMatching(_solidLogic.store.sym(keyDoc), _solidLogic.store.sym('http://www.iana.org/assignments/link-relations/acl')));
13533
+ keyAclDoc = _solidLogic.store.any(_solidLogic.store.sym(keyDoc), _solidLogic.store.sym('http://www.iana.org/assignments/link-relations/acl'));
13534
+ if (keyAclDoc) {
13535
+ _context.next = 6;
13536
+ break;
13537
+ }
13538
+ throw new Error('Key ACL doc not found!');
13539
+ case 6:
13540
+ _context.prev = 6;
13541
+ _context.next = 9;
13542
+ return _solidLogic.store.fetcher.webOperation('PUT', keyAclDoc.value, {
13543
+ data: aclBody,
13544
+ contentType: 'text/turtle'
13545
+ });
13546
+ case 9:
13547
+ _context.next = 16;
13548
+ break;
13549
+ case 11:
13550
+ _context.prev = 11;
13551
+ _context.t0 = _context["catch"](6);
13552
+ if (!((_context.t0 === null || _context.t0 === void 0 ? void 0 : (_err$response = _context.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status) !== 404)) {
13553
+ _context.next = 15;
13554
+ break;
13555
+ }
13556
+ throw new Error(_context.t0);
13557
+ case 15:
13558
+ debug.log('delete ' + keyAclDoc.value + ' ' + _context.t0.response.status); // should test 404 and 2xx
13559
+ case 16:
13560
+ case "end":
13561
+ return _context.stop();
13562
+ }
13563
+ }, _callee, null, [[6, 11]]);
13564
+ }));
13565
+ return _setAcl.apply(this, arguments);
13566
+ }
13567
+ var keyContainerAclBody = function keyContainerAclBody(me) {
13568
+ var aclBody = "\n@prefix : <#>.\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\n@prefix key: <./>.\n\n:ReadWrite\n a acl:Authorization;\n acl:accessTo key:;\n acl:default key:;\n acl:agent <".concat(me, ">;\n acl:mode acl:Read, acl:Write.\n");
13569
+ return aclBody;
13570
+ };
13571
+
13572
+ /**
13573
+ * Read only ACL
13574
+ * @param keyDoc
13575
+ * @param me
13576
+ * @returns aclBody
13577
+ */
13578
+ exports.keyContainerAclBody = keyContainerAclBody;
13579
+ var keyAclBody = function keyAclBody(keyDoc, me) {
13580
+ var keyAgent = 'acl:agentClass foaf:Agent'; // publicKey
13581
+ if (me !== null && me !== void 0 && me.length) keyAgent = "acl:agent <".concat(me, ">"); // privateKey
13582
+ var aclBody = "\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n<#Read>\n a acl:Authorization;\n ".concat(keyAgent, ";\n acl:accessTo <").concat(keyDoc.split('/').pop(), ">;\n acl:mode acl:Read.\n");
13583
+ return aclBody;
13584
+ };
13585
+ exports.keyAclBody = keyAclBody;
13586
+ //# sourceMappingURL=acl.js.map
13587
+
13588
+ /***/ }),
13589
+
13113
13590
  /***/ "./lib/utils/label.js":
13114
13591
  /*!****************************!*\
13115
13592
  !*** ./lib/utils/label.js ***!
@@ -13238,8 +13715,8 @@ Object.defineProperty(exports, "__esModule", ({
13238
13715
  }));
13239
13716
  exports.versionInfo = void 0;
13240
13717
  var versionInfo = {
13241
- buildTime: '2023-04-19T18:00:23Z',
13242
- commit: '9d7e618ee7fcecf32422bd474b50a9bd5f142647',
13718
+ buildTime: '2023-05-22T23:33:26Z',
13719
+ commit: '9ee704cb3d4f7cee133d5ac15202f5978853c92a',
13243
13720
  npmInfo: {
13244
13721
  'solid-ui': '2.4.27',
13245
13722
  npm: '8.19.4',
@@ -25402,6 +25879,8 @@ __webpack_require__.r(__webpack_exports__);
25402
25879
  /* harmony import */ var _inrupt_oidc_client__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @inrupt/oidc-client */ "./node_modules/@inrupt/oidc-client/lib/oidc-client.min.js");
25403
25880
  /* harmony import */ var _inrupt_oidc_client__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_inrupt_oidc_client__WEBPACK_IMPORTED_MODULE_0__);
25404
25881
  /* harmony import */ var _inrupt_solid_client_authn_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @inrupt/solid-client-authn-core */ "./node_modules/@inrupt/solid-client-authn-core/dist/index.mjs");
25882
+ /* harmony import */ var _inrupt_universal_fetch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @inrupt/universal-fetch */ "./node_modules/@inrupt/universal-fetch/dist/index-browser.mjs");
25883
+
25405
25884
 
25406
25885
 
25407
25886
 
@@ -25555,7 +26034,7 @@ async function getTokens(issuer, client, data, dpop) {
25555
26034
  headers,
25556
26035
  body: new URLSearchParams(requestBody).toString(),
25557
26036
  };
25558
- const rawTokenResponse = await await fetch(issuer.tokenEndpoint, tokenRequestInit);
26037
+ const rawTokenResponse = await (0,_inrupt_universal_fetch__WEBPACK_IMPORTED_MODULE_2__.fetch)(issuer.tokenEndpoint, tokenRequestInit);
25559
26038
  const jsonTokenResponse = (await rawTokenResponse.json());
25560
26039
  const tokenResponse = validateTokenEndpointResponse(jsonTokenResponse, dpop);
25561
26040
  const webId = await (0,_inrupt_solid_client_authn_core__WEBPACK_IMPORTED_MODULE_1__.getWebidFromTokenPayload)(tokenResponse.id_token, issuer.jwksUri, issuer.issuer, client.clientId);
@@ -25639,7 +26118,7 @@ async function refresh(refreshToken, issuer, client, dpopKey) {
25639
26118
  else if (isValidUrl(client.clientId)) {
25640
26119
  requestBody.client_id = client.clientId;
25641
26120
  }
25642
- const rawResponse = await fetch(issuer.tokenEndpoint, {
26121
+ const rawResponse = await (0,_inrupt_universal_fetch__WEBPACK_IMPORTED_MODULE_2__.fetch)(issuer.tokenEndpoint, {
25643
26122
  method: "POST",
25644
26123
  body: new URLSearchParams(requestBody).toString(),
25645
26124
  headers: {
@@ -25754,8 +26233,9 @@ e.read=function(t,e,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,h=-7,l=r?i-1:0,f=
25754
26233
 
25755
26234
  Object.defineProperty(exports, "__esModule", ({ value: true }));
25756
26235
  const solid_client_authn_core_1 = __webpack_require__(/*! @inrupt/solid-client-authn-core */ "./node_modules/@inrupt/solid-client-authn-core/dist/index.js");
26236
+ const universal_fetch_1 = __webpack_require__(/*! @inrupt/universal-fetch */ "./node_modules/@inrupt/universal-fetch/dist/index-browser.js");
25757
26237
  const oidc_client_ext_1 = __webpack_require__(/*! @inrupt/oidc-client-ext */ "./node_modules/@inrupt/oidc-client-ext/dist/index.es.js");
25758
- const globalFetch = (request, init) => window.fetch(request, init);
26238
+ const globalFetch = (request, init) => (0, universal_fetch_1.fetch)(request, init);
25759
26239
  class ClientAuthentication {
25760
26240
  constructor(loginHandler, redirectHandler, logoutHandler, sessionInfoManager, issuerConfigFetcher) {
25761
26241
  this.loginHandler = loginHandler;
@@ -26249,6 +26729,7 @@ exports["default"] = ClientRegistrar;
26249
26729
  Object.defineProperty(exports, "__esModule", ({ value: true }));
26250
26730
  exports.WELL_KNOWN_OPENID_CONFIG = void 0;
26251
26731
  const solid_client_authn_core_1 = __webpack_require__(/*! @inrupt/solid-client-authn-core */ "./node_modules/@inrupt/solid-client-authn-core/dist/index.js");
26732
+ const universal_fetch_1 = __webpack_require__(/*! @inrupt/universal-fetch */ "./node_modules/@inrupt/universal-fetch/dist/index-browser.js");
26252
26733
  exports.WELL_KNOWN_OPENID_CONFIG = ".well-known/openid-configuration";
26253
26734
  const issuerConfigKeyMap = {
26254
26735
  issuer: {
@@ -26355,7 +26836,7 @@ class IssuerConfigFetcher {
26355
26836
  async fetchConfig(issuer) {
26356
26837
  let issuerConfig;
26357
26838
  const openIdConfigUrl = new URL(exports.WELL_KNOWN_OPENID_CONFIG, issuer.endsWith("/") ? issuer : `${issuer}/`).href;
26358
- const issuerConfigRequestBody = await window.fetch(openIdConfigUrl);
26839
+ const issuerConfigRequestBody = await (0, universal_fetch_1.fetch)(openIdConfigUrl);
26359
26840
  try {
26360
26841
  issuerConfig = processConfig(await issuerConfigRequestBody.json());
26361
26842
  }
@@ -26458,6 +26939,7 @@ exports["default"] = Redirector;
26458
26939
 
26459
26940
  Object.defineProperty(exports, "__esModule", ({ value: true }));
26460
26941
  exports.AuthCodeRedirectHandler = void 0;
26942
+ const universal_fetch_1 = __webpack_require__(/*! @inrupt/universal-fetch */ "./node_modules/@inrupt/universal-fetch/dist/index-browser.js");
26461
26943
  const solid_client_authn_core_1 = __webpack_require__(/*! @inrupt/solid-client-authn-core */ "./node_modules/@inrupt/solid-client-authn-core/dist/index.js");
26462
26944
  const oidc_client_ext_1 = __webpack_require__(/*! @inrupt/oidc-client-ext */ "./node_modules/@inrupt/oidc-client-ext/dist/index.es.js");
26463
26945
  class AuthCodeRedirectHandler {
@@ -26521,7 +27003,7 @@ class AuthCodeRedirectHandler {
26521
27003
  tokenRefresher: this.tokerRefresher,
26522
27004
  };
26523
27005
  }
26524
- const authFetch = await (0, solid_client_authn_core_1.buildAuthenticatedFetch)(fetch, tokens.accessToken, {
27006
+ const authFetch = await (0, solid_client_authn_core_1.buildAuthenticatedFetch)(universal_fetch_1.fetch, tokens.accessToken, {
26525
27007
  dpopKey: tokens.dpopKey,
26526
27008
  refreshOptions,
26527
27009
  eventEmitter,
@@ -26759,11 +27241,12 @@ exports.SessionInfoManager = exports.clear = exports.getUnauthenticatedSession =
26759
27241
  const solid_client_authn_core_1 = __webpack_require__(/*! @inrupt/solid-client-authn-core */ "./node_modules/@inrupt/solid-client-authn-core/dist/index.js");
26760
27242
  const uuid_1 = __webpack_require__(/*! uuid */ "./node_modules/@inrupt/solid-client-authn-browser/node_modules/uuid/dist/commonjs-browser/index.js");
26761
27243
  const oidc_client_ext_1 = __webpack_require__(/*! @inrupt/oidc-client-ext */ "./node_modules/@inrupt/oidc-client-ext/dist/index.es.js");
27244
+ const universal_fetch_1 = __webpack_require__(/*! @inrupt/universal-fetch */ "./node_modules/@inrupt/universal-fetch/dist/index-browser.js");
26762
27245
  function getUnauthenticatedSession() {
26763
27246
  return {
26764
27247
  isLoggedIn: false,
26765
27248
  sessionId: (0, uuid_1.v4)(),
26766
- fetch,
27249
+ fetch: universal_fetch_1.fetch,
26767
27250
  };
26768
27251
  }
26769
27252
  exports.getUnauthenticatedSession = getUnauthenticatedSession;
@@ -27916,513 +28399,513 @@ exports["default"] = _default;
27916
28399
 
27917
28400
 
27918
28401
  var events = __webpack_require__(/*! events */ "./node_modules/events/events.js");
27919
- var crossFetch = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/browser-ponyfill.js");
28402
+ var universalFetch = __webpack_require__(/*! @inrupt/universal-fetch */ "./node_modules/@inrupt/universal-fetch/dist/index-browser.js");
27920
28403
  var jose = __webpack_require__(/*! jose */ "./node_modules/jose/dist/browser/index.js");
27921
28404
  var uuid = __webpack_require__(/*! uuid */ "./node_modules/@inrupt/solid-client-authn-core/node_modules/uuid/dist/commonjs-browser/index.js");
27922
28405
 
27923
- const SOLID_CLIENT_AUTHN_KEY_PREFIX = "solidClientAuthn:";
27924
- const PREFERRED_SIGNING_ALG = ["ES256", "RS256"];
27925
- const EVENTS = {
27926
- ERROR: "error",
27927
- LOGIN: "login",
27928
- LOGOUT: "logout",
27929
- NEW_REFRESH_TOKEN: "newRefreshToken",
27930
- SESSION_EXPIRED: "sessionExpired",
27931
- SESSION_EXTENDED: "sessionExtended",
27932
- SESSION_RESTORED: "sessionRestore",
27933
- TIMEOUT_SET: "timeoutSet",
27934
- };
27935
- const REFRESH_BEFORE_EXPIRATION_SECONDS = 5;
27936
- const SCOPE_OPENID = "openid";
27937
- const SCOPE_OFFLINE = "offline_access";
27938
- const SCOPE_WEBID = "webid";
28406
+ const SOLID_CLIENT_AUTHN_KEY_PREFIX = "solidClientAuthn:";
28407
+ const PREFERRED_SIGNING_ALG = ["ES256", "RS256"];
28408
+ const EVENTS = {
28409
+ ERROR: "error",
28410
+ LOGIN: "login",
28411
+ LOGOUT: "logout",
28412
+ NEW_REFRESH_TOKEN: "newRefreshToken",
28413
+ SESSION_EXPIRED: "sessionExpired",
28414
+ SESSION_EXTENDED: "sessionExtended",
28415
+ SESSION_RESTORED: "sessionRestore",
28416
+ TIMEOUT_SET: "timeoutSet",
28417
+ };
28418
+ const REFRESH_BEFORE_EXPIRATION_SECONDS = 5;
28419
+ const SCOPE_OPENID = "openid";
28420
+ const SCOPE_OFFLINE = "offline_access";
28421
+ const SCOPE_WEBID = "webid";
27939
28422
  const DEFAULT_SCOPES = [SCOPE_OPENID, SCOPE_OFFLINE, SCOPE_WEBID].join(" ");
27940
28423
 
27941
- const buildProxyHandler = (toExclude, errorMessage) => ({
27942
- get(target, prop, receiver) {
27943
- if (!Object.getOwnPropertyNames(events.EventEmitter).includes(prop) &&
27944
- Object.getOwnPropertyNames(toExclude).includes(prop)) {
27945
- throw new Error(`${errorMessage}: [${prop}] is not supported`);
27946
- }
27947
- return Reflect.get(target, prop, receiver);
27948
- },
28424
+ const buildProxyHandler = (toExclude, errorMessage) => ({
28425
+ get(target, prop, receiver) {
28426
+ if (!Object.getOwnPropertyNames(events.EventEmitter).includes(prop) &&
28427
+ Object.getOwnPropertyNames(toExclude).includes(prop)) {
28428
+ throw new Error(`${errorMessage}: [${prop}] is not supported`);
28429
+ }
28430
+ return Reflect.get(target, prop, receiver);
28431
+ },
27949
28432
  });
27950
28433
 
27951
- class AggregateHandler {
27952
- constructor(handleables) {
27953
- this.handleables = handleables;
27954
- }
27955
- async getProperHandler(params) {
27956
- const canHandleList = await Promise.all(this.handleables.map((handleable) => handleable.canHandle(...params)));
27957
- for (let i = 0; i < canHandleList.length; i += 1) {
27958
- if (canHandleList[i]) {
27959
- return this.handleables[i];
27960
- }
27961
- }
27962
- return null;
27963
- }
27964
- async canHandle(...params) {
27965
- return (await this.getProperHandler(params)) !== null;
27966
- }
27967
- async handle(...params) {
27968
- const handler = await this.getProperHandler(params);
27969
- if (handler) {
27970
- return handler.handle(...params);
27971
- }
27972
- throw new Error(`[${this.constructor.name}] cannot find a suitable handler for: ${params
27973
- .map((param) => {
27974
- try {
27975
- return JSON.stringify(param);
27976
- }
27977
- catch (err) {
27978
- return param.toString();
27979
- }
27980
- })
27981
- .join(", ")}`);
27982
- }
28434
+ class AggregateHandler {
28435
+ constructor(handleables) {
28436
+ this.handleables = handleables;
28437
+ }
28438
+ async getProperHandler(params) {
28439
+ const canHandleList = await Promise.all(this.handleables.map((handleable) => handleable.canHandle(...params)));
28440
+ for (let i = 0; i < canHandleList.length; i += 1) {
28441
+ if (canHandleList[i]) {
28442
+ return this.handleables[i];
28443
+ }
28444
+ }
28445
+ return null;
28446
+ }
28447
+ async canHandle(...params) {
28448
+ return (await this.getProperHandler(params)) !== null;
28449
+ }
28450
+ async handle(...params) {
28451
+ const handler = await this.getProperHandler(params);
28452
+ if (handler) {
28453
+ return handler.handle(...params);
28454
+ }
28455
+ throw new Error(`[${this.constructor.name}] cannot find a suitable handler for: ${params
28456
+ .map((param) => {
28457
+ try {
28458
+ return JSON.stringify(param);
28459
+ }
28460
+ catch (err) {
28461
+ return param.toString();
28462
+ }
28463
+ })
28464
+ .join(", ")}`);
28465
+ }
27983
28466
  }
27984
28467
 
27985
- async function fetchJwks(jwksIri, issuerIri) {
27986
- const jwksResponse = await crossFetch.fetch(jwksIri);
27987
- if (jwksResponse.status !== 200) {
27988
- throw new Error(`Could not fetch JWKS for [${issuerIri}] at [${jwksIri}]: ${jwksResponse.status} ${jwksResponse.statusText}`);
27989
- }
27990
- let jwk;
27991
- try {
27992
- jwk = (await jwksResponse.json()).keys[0];
27993
- }
27994
- catch (e) {
27995
- throw new Error(`Malformed JWKS for [${issuerIri}] at [${jwksIri}]: ${e.message}`);
27996
- }
27997
- return jwk;
27998
- }
27999
- async function getWebidFromTokenPayload(idToken, jwksIri, issuerIri, clientId) {
28000
- const jwk = await fetchJwks(jwksIri, issuerIri);
28001
- let payload;
28002
- try {
28003
- const { payload: verifiedPayload } = await jose.jwtVerify(idToken, await jose.importJWK(jwk), {
28004
- issuer: issuerIri,
28005
- audience: clientId,
28006
- });
28007
- payload = verifiedPayload;
28008
- }
28009
- catch (e) {
28010
- throw new Error(`Token verification failed: ${e.stack}`);
28011
- }
28012
- if (typeof payload.webid === "string") {
28013
- return payload.webid;
28014
- }
28015
- if (typeof payload.sub !== "string") {
28016
- throw new Error(`The token ${JSON.stringify(payload)} is invalid: it has no 'webid' claim and no 'sub' claim.`);
28017
- }
28018
- try {
28019
- new URL(payload.sub);
28020
- return payload.sub;
28021
- }
28022
- catch (e) {
28023
- throw new Error(`The token has no 'webid' claim, and its 'sub' claim of [${payload.sub}] is invalid as a URL - error [${e}].`);
28024
- }
28468
+ async function fetchJwks(jwksIri, issuerIri) {
28469
+ const jwksResponse = await universalFetch.fetch(jwksIri);
28470
+ if (jwksResponse.status !== 200) {
28471
+ throw new Error(`Could not fetch JWKS for [${issuerIri}] at [${jwksIri}]: ${jwksResponse.status} ${jwksResponse.statusText}`);
28472
+ }
28473
+ let jwk;
28474
+ try {
28475
+ jwk = (await jwksResponse.json()).keys[0];
28476
+ }
28477
+ catch (e) {
28478
+ throw new Error(`Malformed JWKS for [${issuerIri}] at [${jwksIri}]: ${e.message}`);
28479
+ }
28480
+ return jwk;
28481
+ }
28482
+ async function getWebidFromTokenPayload(idToken, jwksIri, issuerIri, clientId) {
28483
+ const jwk = await fetchJwks(jwksIri, issuerIri);
28484
+ let payload;
28485
+ try {
28486
+ const { payload: verifiedPayload } = await jose.jwtVerify(idToken, await jose.importJWK(jwk), {
28487
+ issuer: issuerIri,
28488
+ audience: clientId,
28489
+ });
28490
+ payload = verifiedPayload;
28491
+ }
28492
+ catch (e) {
28493
+ throw new Error(`Token verification failed: ${e.stack}`);
28494
+ }
28495
+ if (typeof payload.webid === "string") {
28496
+ return payload.webid;
28497
+ }
28498
+ if (typeof payload.sub !== "string") {
28499
+ throw new Error(`The token ${JSON.stringify(payload)} is invalid: it has no 'webid' claim and no 'sub' claim.`);
28500
+ }
28501
+ try {
28502
+ new URL(payload.sub);
28503
+ return payload.sub;
28504
+ }
28505
+ catch (e) {
28506
+ throw new Error(`The token has no 'webid' claim, and its 'sub' claim of [${payload.sub}] is invalid as a URL - error [${e}].`);
28507
+ }
28025
28508
  }
28026
28509
 
28027
- function isValidRedirectUrl(redirectUrl) {
28028
- try {
28029
- const urlObject = new URL(redirectUrl);
28030
- return urlObject.hash === "";
28031
- }
28032
- catch (e) {
28033
- return false;
28034
- }
28510
+ function isValidRedirectUrl(redirectUrl) {
28511
+ try {
28512
+ const urlObject = new URL(redirectUrl);
28513
+ return urlObject.hash === "";
28514
+ }
28515
+ catch (e) {
28516
+ return false;
28517
+ }
28035
28518
  }
28036
28519
 
28037
- function isSupportedTokenType(token) {
28038
- return typeof token === "string" && ["DPoP", "Bearer"].includes(token);
28520
+ function isSupportedTokenType(token) {
28521
+ return typeof token === "string" && ["DPoP", "Bearer"].includes(token);
28039
28522
  }
28040
28523
 
28041
28524
  const USER_SESSION_PREFIX = "solidClientAuthenticationUser";
28042
28525
 
28043
- function isValidUrl(url) {
28044
- try {
28045
- new URL(url);
28046
- return true;
28047
- }
28048
- catch (_a) {
28049
- return false;
28050
- }
28051
- }
28052
- function determineSigningAlg(supported, preferred) {
28053
- var _a;
28054
- return ((_a = preferred.find((signingAlg) => {
28055
- return supported.includes(signingAlg);
28056
- })) !== null && _a !== void 0 ? _a : null);
28057
- }
28058
- function determineClientType(options, issuerConfig) {
28059
- if (options.clientId !== undefined && !isValidUrl(options.clientId)) {
28060
- return "static";
28061
- }
28062
- if (issuerConfig.scopesSupported.includes("webid") &&
28063
- options.clientId !== undefined &&
28064
- isValidUrl(options.clientId)) {
28065
- return "solid-oidc";
28066
- }
28067
- return "dynamic";
28068
- }
28069
- async function handleRegistration(options, issuerConfig, storageUtility, clientRegistrar) {
28070
- const clientType = determineClientType(options, issuerConfig);
28071
- if (clientType === "dynamic") {
28072
- return clientRegistrar.getClient({
28073
- sessionId: options.sessionId,
28074
- clientName: options.clientName,
28075
- redirectUrl: options.redirectUrl,
28076
- }, issuerConfig);
28077
- }
28078
- await storageUtility.setForUser(options.sessionId, {
28079
- clientId: options.clientId,
28080
- });
28081
- if (options.clientSecret) {
28082
- await storageUtility.setForUser(options.sessionId, {
28083
- clientSecret: options.clientSecret,
28084
- });
28085
- }
28086
- if (options.clientName) {
28087
- await storageUtility.setForUser(options.sessionId, {
28088
- clientName: options.clientName,
28089
- });
28090
- }
28091
- return {
28092
- clientId: options.clientId,
28093
- clientSecret: options.clientSecret,
28094
- clientName: options.clientName,
28095
- clientType,
28096
- };
28526
+ function isValidUrl(url) {
28527
+ try {
28528
+ new URL(url);
28529
+ return true;
28530
+ }
28531
+ catch (_a) {
28532
+ return false;
28533
+ }
28534
+ }
28535
+ function determineSigningAlg(supported, preferred) {
28536
+ var _a;
28537
+ return ((_a = preferred.find((signingAlg) => {
28538
+ return supported.includes(signingAlg);
28539
+ })) !== null && _a !== void 0 ? _a : null);
28540
+ }
28541
+ function determineClientType(options, issuerConfig) {
28542
+ if (options.clientId !== undefined && !isValidUrl(options.clientId)) {
28543
+ return "static";
28544
+ }
28545
+ if (issuerConfig.scopesSupported.includes("webid") &&
28546
+ options.clientId !== undefined &&
28547
+ isValidUrl(options.clientId)) {
28548
+ return "solid-oidc";
28549
+ }
28550
+ return "dynamic";
28551
+ }
28552
+ async function handleRegistration(options, issuerConfig, storageUtility, clientRegistrar) {
28553
+ const clientType = determineClientType(options, issuerConfig);
28554
+ if (clientType === "dynamic") {
28555
+ return clientRegistrar.getClient({
28556
+ sessionId: options.sessionId,
28557
+ clientName: options.clientName,
28558
+ redirectUrl: options.redirectUrl,
28559
+ }, issuerConfig);
28560
+ }
28561
+ await storageUtility.setForUser(options.sessionId, {
28562
+ clientId: options.clientId,
28563
+ });
28564
+ if (options.clientSecret) {
28565
+ await storageUtility.setForUser(options.sessionId, {
28566
+ clientSecret: options.clientSecret,
28567
+ });
28568
+ }
28569
+ if (options.clientName) {
28570
+ await storageUtility.setForUser(options.sessionId, {
28571
+ clientName: options.clientName,
28572
+ });
28573
+ }
28574
+ return {
28575
+ clientId: options.clientId,
28576
+ clientSecret: options.clientSecret,
28577
+ clientName: options.clientName,
28578
+ clientType,
28579
+ };
28097
28580
  }
28098
28581
 
28099
- async function getSessionIdFromOauthState(storageUtility, oauthState) {
28100
- return storageUtility.getForUser(oauthState, "sessionId");
28101
- }
28102
- async function loadOidcContextFromStorage(sessionId, storageUtility, configFetcher) {
28103
- try {
28104
- const [issuerIri, codeVerifier, storedRedirectIri, dpop] = await Promise.all([
28105
- storageUtility.getForUser(sessionId, "issuer", {
28106
- errorIfNull: true,
28107
- }),
28108
- storageUtility.getForUser(sessionId, "codeVerifier"),
28109
- storageUtility.getForUser(sessionId, "redirectUrl"),
28110
- storageUtility.getForUser(sessionId, "dpop", { errorIfNull: true }),
28111
- ]);
28112
- await storageUtility.deleteForUser(sessionId, "codeVerifier");
28113
- const issuerConfig = await configFetcher.fetchConfig(issuerIri);
28114
- return {
28115
- codeVerifier,
28116
- redirectUrl: storedRedirectIri,
28117
- issuerConfig,
28118
- dpop: dpop === "true",
28119
- };
28120
- }
28121
- catch (e) {
28122
- throw new Error(`Failed to retrieve OIDC context from storage associated with session [${sessionId}]: ${e}`);
28123
- }
28124
- }
28125
- async function saveSessionInfoToStorage(storageUtility, sessionId, webId, isLoggedIn, refreshToken, secure, dpopKey) {
28126
- if (refreshToken !== undefined) {
28127
- await storageUtility.setForUser(sessionId, { refreshToken }, { secure });
28128
- }
28129
- if (webId !== undefined) {
28130
- await storageUtility.setForUser(sessionId, { webId }, { secure });
28131
- }
28132
- if (isLoggedIn !== undefined) {
28133
- await storageUtility.setForUser(sessionId, { isLoggedIn }, { secure });
28134
- }
28135
- if (dpopKey !== undefined) {
28136
- await storageUtility.setForUser(sessionId, {
28137
- publicKey: JSON.stringify(dpopKey.publicKey),
28138
- privateKey: JSON.stringify(await jose.exportJWK(dpopKey.privateKey)),
28139
- }, { secure });
28140
- }
28141
- }
28142
- class StorageUtility {
28143
- constructor(secureStorage, insecureStorage) {
28144
- this.secureStorage = secureStorage;
28145
- this.insecureStorage = insecureStorage;
28146
- }
28147
- getKey(userId) {
28148
- return `solidClientAuthenticationUser:${userId}`;
28149
- }
28150
- async getUserData(userId, secure) {
28151
- const stored = await (secure
28152
- ? this.secureStorage
28153
- : this.insecureStorage).get(this.getKey(userId));
28154
- if (stored === undefined) {
28155
- return {};
28156
- }
28157
- try {
28158
- return JSON.parse(stored);
28159
- }
28160
- catch (err) {
28161
- throw new Error(`Data for user [${userId}] in [${secure ? "secure" : "unsecure"}] storage is corrupted - expected valid JSON, but got: ${stored}`);
28162
- }
28163
- }
28164
- async setUserData(userId, data, secure) {
28165
- await (secure ? this.secureStorage : this.insecureStorage).set(this.getKey(userId), JSON.stringify(data));
28166
- }
28167
- async get(key, options) {
28168
- const value = await ((options === null || options === void 0 ? void 0 : options.secure)
28169
- ? this.secureStorage
28170
- : this.insecureStorage).get(key);
28171
- if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
28172
- throw new Error(`[${key}] is not stored`);
28173
- }
28174
- return value;
28175
- }
28176
- async set(key, value, options) {
28177
- return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).set(key, value);
28178
- }
28179
- async delete(key, options) {
28180
- return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(key);
28181
- }
28182
- async getForUser(userId, key, options) {
28183
- const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
28184
- let value;
28185
- if (!userData || !userData[key]) {
28186
- value = undefined;
28187
- }
28188
- value = userData[key];
28189
- if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
28190
- throw new Error(`Field [${key}] for user [${userId}] is not stored`);
28191
- }
28192
- return value || undefined;
28193
- }
28194
- async setForUser(userId, values, options) {
28195
- let userData;
28196
- try {
28197
- userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
28198
- }
28199
- catch (_a) {
28200
- userData = {};
28201
- }
28202
- await this.setUserData(userId, { ...userData, ...values }, options === null || options === void 0 ? void 0 : options.secure);
28203
- }
28204
- async deleteForUser(userId, key, options) {
28205
- const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
28206
- delete userData[key];
28207
- await this.setUserData(userId, userData, options === null || options === void 0 ? void 0 : options.secure);
28208
- }
28209
- async deleteAllUserData(userId, options) {
28210
- await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
28211
- }
28582
+ async function getSessionIdFromOauthState(storageUtility, oauthState) {
28583
+ return storageUtility.getForUser(oauthState, "sessionId");
28584
+ }
28585
+ async function loadOidcContextFromStorage(sessionId, storageUtility, configFetcher) {
28586
+ try {
28587
+ const [issuerIri, codeVerifier, storedRedirectIri, dpop] = await Promise.all([
28588
+ storageUtility.getForUser(sessionId, "issuer", {
28589
+ errorIfNull: true,
28590
+ }),
28591
+ storageUtility.getForUser(sessionId, "codeVerifier"),
28592
+ storageUtility.getForUser(sessionId, "redirectUrl"),
28593
+ storageUtility.getForUser(sessionId, "dpop", { errorIfNull: true }),
28594
+ ]);
28595
+ await storageUtility.deleteForUser(sessionId, "codeVerifier");
28596
+ const issuerConfig = await configFetcher.fetchConfig(issuerIri);
28597
+ return {
28598
+ codeVerifier,
28599
+ redirectUrl: storedRedirectIri,
28600
+ issuerConfig,
28601
+ dpop: dpop === "true",
28602
+ };
28603
+ }
28604
+ catch (e) {
28605
+ throw new Error(`Failed to retrieve OIDC context from storage associated with session [${sessionId}]: ${e}`);
28606
+ }
28607
+ }
28608
+ async function saveSessionInfoToStorage(storageUtility, sessionId, webId, isLoggedIn, refreshToken, secure, dpopKey) {
28609
+ if (refreshToken !== undefined) {
28610
+ await storageUtility.setForUser(sessionId, { refreshToken }, { secure });
28611
+ }
28612
+ if (webId !== undefined) {
28613
+ await storageUtility.setForUser(sessionId, { webId }, { secure });
28614
+ }
28615
+ if (isLoggedIn !== undefined) {
28616
+ await storageUtility.setForUser(sessionId, { isLoggedIn }, { secure });
28617
+ }
28618
+ if (dpopKey !== undefined) {
28619
+ await storageUtility.setForUser(sessionId, {
28620
+ publicKey: JSON.stringify(dpopKey.publicKey),
28621
+ privateKey: JSON.stringify(await jose.exportJWK(dpopKey.privateKey)),
28622
+ }, { secure });
28623
+ }
28624
+ }
28625
+ class StorageUtility {
28626
+ constructor(secureStorage, insecureStorage) {
28627
+ this.secureStorage = secureStorage;
28628
+ this.insecureStorage = insecureStorage;
28629
+ }
28630
+ getKey(userId) {
28631
+ return `solidClientAuthenticationUser:${userId}`;
28632
+ }
28633
+ async getUserData(userId, secure) {
28634
+ const stored = await (secure
28635
+ ? this.secureStorage
28636
+ : this.insecureStorage).get(this.getKey(userId));
28637
+ if (stored === undefined) {
28638
+ return {};
28639
+ }
28640
+ try {
28641
+ return JSON.parse(stored);
28642
+ }
28643
+ catch (err) {
28644
+ throw new Error(`Data for user [${userId}] in [${secure ? "secure" : "unsecure"}] storage is corrupted - expected valid JSON, but got: ${stored}`);
28645
+ }
28646
+ }
28647
+ async setUserData(userId, data, secure) {
28648
+ await (secure ? this.secureStorage : this.insecureStorage).set(this.getKey(userId), JSON.stringify(data));
28649
+ }
28650
+ async get(key, options) {
28651
+ const value = await ((options === null || options === void 0 ? void 0 : options.secure)
28652
+ ? this.secureStorage
28653
+ : this.insecureStorage).get(key);
28654
+ if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
28655
+ throw new Error(`[${key}] is not stored`);
28656
+ }
28657
+ return value;
28658
+ }
28659
+ async set(key, value, options) {
28660
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).set(key, value);
28661
+ }
28662
+ async delete(key, options) {
28663
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(key);
28664
+ }
28665
+ async getForUser(userId, key, options) {
28666
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
28667
+ let value;
28668
+ if (!userData || !userData[key]) {
28669
+ value = undefined;
28670
+ }
28671
+ value = userData[key];
28672
+ if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
28673
+ throw new Error(`Field [${key}] for user [${userId}] is not stored`);
28674
+ }
28675
+ return value || undefined;
28676
+ }
28677
+ async setForUser(userId, values, options) {
28678
+ let userData;
28679
+ try {
28680
+ userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
28681
+ }
28682
+ catch (_a) {
28683
+ userData = {};
28684
+ }
28685
+ await this.setUserData(userId, { ...userData, ...values }, options === null || options === void 0 ? void 0 : options.secure);
28686
+ }
28687
+ async deleteForUser(userId, key, options) {
28688
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
28689
+ delete userData[key];
28690
+ await this.setUserData(userId, userData, options === null || options === void 0 ? void 0 : options.secure);
28691
+ }
28692
+ async deleteAllUserData(userId, options) {
28693
+ await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
28694
+ }
28212
28695
  }
28213
28696
 
28214
- class InMemoryStorage {
28215
- constructor() {
28216
- this.map = {};
28217
- }
28218
- async get(key) {
28219
- return this.map[key] || undefined;
28220
- }
28221
- async set(key, value) {
28222
- this.map[key] = value;
28223
- }
28224
- async delete(key) {
28225
- delete this.map[key];
28226
- }
28697
+ class InMemoryStorage {
28698
+ constructor() {
28699
+ this.map = {};
28700
+ }
28701
+ async get(key) {
28702
+ return this.map[key] || undefined;
28703
+ }
28704
+ async set(key, value) {
28705
+ this.map[key] = value;
28706
+ }
28707
+ async delete(key) {
28708
+ delete this.map[key];
28709
+ }
28227
28710
  }
28228
28711
 
28229
- class ConfigurationError extends Error {
28230
- constructor(message) {
28231
- super(message);
28232
- }
28712
+ class ConfigurationError extends Error {
28713
+ constructor(message) {
28714
+ super(message);
28715
+ }
28233
28716
  }
28234
28717
 
28235
- class NotImplementedError extends Error {
28236
- constructor(methodName) {
28237
- super(`[${methodName}] is not implemented`);
28238
- }
28718
+ class NotImplementedError extends Error {
28719
+ constructor(methodName) {
28720
+ super(`[${methodName}] is not implemented`);
28721
+ }
28239
28722
  }
28240
28723
 
28241
- class InvalidResponseError extends Error {
28242
- constructor(missingFields) {
28243
- super(`Invalid response from OIDC provider: missing fields ${missingFields}`);
28244
- this.missingFields = missingFields;
28245
- }
28724
+ class InvalidResponseError extends Error {
28725
+ constructor(missingFields) {
28726
+ super(`Invalid response from OIDC provider: missing fields ${missingFields}`);
28727
+ this.missingFields = missingFields;
28728
+ }
28246
28729
  }
28247
28730
 
28248
- class OidcProviderError extends Error {
28249
- constructor(message, error, errorDescription) {
28250
- super(message);
28251
- this.error = error;
28252
- this.errorDescription = errorDescription;
28253
- }
28731
+ class OidcProviderError extends Error {
28732
+ constructor(message, error, errorDescription) {
28733
+ super(message);
28734
+ this.error = error;
28735
+ this.errorDescription = errorDescription;
28736
+ }
28254
28737
  }
28255
28738
 
28256
- function normalizeHTU(audience) {
28257
- const audienceUrl = new URL(audience);
28258
- return new URL(audienceUrl.pathname, audienceUrl.origin).toString();
28259
- }
28260
- async function createDpopHeader(audience, method, dpopKey) {
28261
- return new jose.SignJWT({
28262
- htu: normalizeHTU(audience),
28263
- htm: method.toUpperCase(),
28264
- jti: uuid.v4(),
28265
- })
28266
- .setProtectedHeader({
28267
- alg: PREFERRED_SIGNING_ALG[0],
28268
- jwk: dpopKey.publicKey,
28269
- typ: "dpop+jwt",
28270
- })
28271
- .setIssuedAt()
28272
- .sign(dpopKey.privateKey, {});
28273
- }
28274
- async function generateDpopKeyPair() {
28275
- const { privateKey, publicKey } = await jose.generateKeyPair(PREFERRED_SIGNING_ALG[0]);
28276
- const dpopKeyPair = {
28277
- privateKey,
28278
- publicKey: await jose.exportJWK(publicKey),
28279
- };
28280
- [dpopKeyPair.publicKey.alg] = PREFERRED_SIGNING_ALG;
28281
- return dpopKeyPair;
28739
+ function normalizeHTU(audience) {
28740
+ const audienceUrl = new URL(audience);
28741
+ return new URL(audienceUrl.pathname, audienceUrl.origin).toString();
28742
+ }
28743
+ async function createDpopHeader(audience, method, dpopKey) {
28744
+ return new jose.SignJWT({
28745
+ htu: normalizeHTU(audience),
28746
+ htm: method.toUpperCase(),
28747
+ jti: uuid.v4(),
28748
+ })
28749
+ .setProtectedHeader({
28750
+ alg: PREFERRED_SIGNING_ALG[0],
28751
+ jwk: dpopKey.publicKey,
28752
+ typ: "dpop+jwt",
28753
+ })
28754
+ .setIssuedAt()
28755
+ .sign(dpopKey.privateKey, {});
28756
+ }
28757
+ async function generateDpopKeyPair() {
28758
+ const { privateKey, publicKey } = await jose.generateKeyPair(PREFERRED_SIGNING_ALG[0]);
28759
+ const dpopKeyPair = {
28760
+ privateKey,
28761
+ publicKey: await jose.exportJWK(publicKey),
28762
+ };
28763
+ [dpopKeyPair.publicKey.alg] = PREFERRED_SIGNING_ALG;
28764
+ return dpopKeyPair;
28282
28765
  }
28283
28766
 
28284
- const DEFAULT_EXPIRATION_TIME_SECONDS = 600;
28285
- function isExpectedAuthError(statusCode) {
28286
- return [401, 403].includes(statusCode);
28287
- }
28288
- async function buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions) {
28289
- var _a;
28290
- const headers = new crossFetch.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
28291
- headers.set("Authorization", `DPoP ${authToken}`);
28292
- headers.set("DPoP", await createDpopHeader(targetUrl, (_a = defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.method) !== null && _a !== void 0 ? _a : "get", dpopKey));
28293
- return {
28294
- ...defaultOptions,
28295
- headers,
28296
- };
28297
- }
28298
- async function buildAuthenticatedHeaders(targetUrl, authToken, dpopKey, defaultOptions) {
28299
- if (dpopKey !== undefined) {
28300
- return buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions);
28301
- }
28302
- const headers = new crossFetch.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
28303
- headers.set("Authorization", `Bearer ${authToken}`);
28304
- return {
28305
- ...defaultOptions,
28306
- headers,
28307
- };
28308
- }
28309
- async function makeAuthenticatedRequest(unauthFetch, accessToken, url, defaultRequestInit, dpopKey) {
28310
- return unauthFetch(url, await buildAuthenticatedHeaders(url.toString(), accessToken, dpopKey, defaultRequestInit));
28311
- }
28312
- async function refreshAccessToken(refreshOptions, dpopKey, eventEmitter) {
28313
- var _a;
28314
- const tokenSet = await refreshOptions.tokenRefresher.refresh(refreshOptions.sessionId, refreshOptions.refreshToken, dpopKey);
28315
- eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.SESSION_EXTENDED, (_a = tokenSet.expiresIn) !== null && _a !== void 0 ? _a : DEFAULT_EXPIRATION_TIME_SECONDS);
28316
- if (typeof tokenSet.refreshToken === "string") {
28317
- eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
28318
- }
28319
- return {
28320
- accessToken: tokenSet.accessToken,
28321
- refreshToken: tokenSet.refreshToken,
28322
- expiresIn: tokenSet.expiresIn,
28323
- };
28324
- }
28325
- const computeRefreshDelay = (expiresIn) => {
28326
- if (expiresIn !== undefined) {
28327
- return expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS > 0
28328
- ?
28329
- expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS
28330
- : expiresIn;
28331
- }
28332
- return DEFAULT_EXPIRATION_TIME_SECONDS;
28333
- };
28334
- async function buildAuthenticatedFetch(unauthFetch, accessToken, options) {
28335
- var _a;
28336
- let currentAccessToken = accessToken;
28337
- let latestTimeout;
28338
- const currentRefreshOptions = options === null || options === void 0 ? void 0 : options.refreshOptions;
28339
- if (currentRefreshOptions !== undefined) {
28340
- const proactivelyRefreshToken = async () => {
28341
- var _a, _b, _c, _d;
28342
- try {
28343
- const { accessToken: refreshedAccessToken, refreshToken, expiresIn, } = await refreshAccessToken(currentRefreshOptions, options.dpopKey, options.eventEmitter);
28344
- currentAccessToken = refreshedAccessToken;
28345
- if (refreshToken !== undefined) {
28346
- currentRefreshOptions.refreshToken = refreshToken;
28347
- }
28348
- clearTimeout(latestTimeout);
28349
- latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(expiresIn) * 1000);
28350
- (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
28351
- }
28352
- catch (e) {
28353
- if (e instanceof OidcProviderError) {
28354
- (_b = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(EVENTS.ERROR, e.error, e.errorDescription);
28355
- (_c = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _c === void 0 ? void 0 : _c.emit(EVENTS.SESSION_EXPIRED);
28356
- }
28357
- if (e instanceof InvalidResponseError &&
28358
- e.missingFields.includes("access_token")) {
28359
- (_d = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _d === void 0 ? void 0 : _d.emit(EVENTS.SESSION_EXPIRED);
28360
- }
28361
- }
28362
- };
28363
- latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(options.expiresIn) * 1000);
28364
- (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
28365
- }
28366
- else if (options !== undefined && options.eventEmitter !== undefined) {
28367
- const expirationTimeout = setTimeout(() => {
28368
- options.eventEmitter.emit(EVENTS.SESSION_EXPIRED);
28369
- }, computeRefreshDelay(options.expiresIn) * 1000);
28370
- options.eventEmitter.emit(EVENTS.TIMEOUT_SET, expirationTimeout);
28371
- }
28372
- return async (url, requestInit) => {
28373
- let response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, url, requestInit, options === null || options === void 0 ? void 0 : options.dpopKey);
28374
- const failedButNotExpectedAuthError = !response.ok && !isExpectedAuthError(response.status);
28375
- if (response.ok || failedButNotExpectedAuthError) {
28376
- return response;
28377
- }
28378
- const hasBeenRedirected = response.url !== url;
28379
- if (hasBeenRedirected && (options === null || options === void 0 ? void 0 : options.dpopKey) !== undefined) {
28380
- response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, response.url, requestInit, options.dpopKey);
28381
- }
28382
- return response;
28383
- };
28767
+ const DEFAULT_EXPIRATION_TIME_SECONDS = 600;
28768
+ function isExpectedAuthError(statusCode) {
28769
+ return [401, 403].includes(statusCode);
28770
+ }
28771
+ async function buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions) {
28772
+ var _a;
28773
+ const headers = new universalFetch.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
28774
+ headers.set("Authorization", `DPoP ${authToken}`);
28775
+ headers.set("DPoP", await createDpopHeader(targetUrl, (_a = defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.method) !== null && _a !== void 0 ? _a : "get", dpopKey));
28776
+ return {
28777
+ ...defaultOptions,
28778
+ headers,
28779
+ };
28780
+ }
28781
+ async function buildAuthenticatedHeaders(targetUrl, authToken, dpopKey, defaultOptions) {
28782
+ if (dpopKey !== undefined) {
28783
+ return buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions);
28784
+ }
28785
+ const headers = new universalFetch.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
28786
+ headers.set("Authorization", `Bearer ${authToken}`);
28787
+ return {
28788
+ ...defaultOptions,
28789
+ headers,
28790
+ };
28791
+ }
28792
+ async function makeAuthenticatedRequest(unauthFetch, accessToken, url, defaultRequestInit, dpopKey) {
28793
+ return unauthFetch(url, await buildAuthenticatedHeaders(url.toString(), accessToken, dpopKey, defaultRequestInit));
28794
+ }
28795
+ async function refreshAccessToken(refreshOptions, dpopKey, eventEmitter) {
28796
+ var _a;
28797
+ const tokenSet = await refreshOptions.tokenRefresher.refresh(refreshOptions.sessionId, refreshOptions.refreshToken, dpopKey);
28798
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.SESSION_EXTENDED, (_a = tokenSet.expiresIn) !== null && _a !== void 0 ? _a : DEFAULT_EXPIRATION_TIME_SECONDS);
28799
+ if (typeof tokenSet.refreshToken === "string") {
28800
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
28801
+ }
28802
+ return {
28803
+ accessToken: tokenSet.accessToken,
28804
+ refreshToken: tokenSet.refreshToken,
28805
+ expiresIn: tokenSet.expiresIn,
28806
+ };
28807
+ }
28808
+ const computeRefreshDelay = (expiresIn) => {
28809
+ if (expiresIn !== undefined) {
28810
+ return expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS > 0
28811
+ ?
28812
+ expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS
28813
+ : expiresIn;
28814
+ }
28815
+ return DEFAULT_EXPIRATION_TIME_SECONDS;
28816
+ };
28817
+ async function buildAuthenticatedFetch(unauthFetch, accessToken, options) {
28818
+ var _a;
28819
+ let currentAccessToken = accessToken;
28820
+ let latestTimeout;
28821
+ const currentRefreshOptions = options === null || options === void 0 ? void 0 : options.refreshOptions;
28822
+ if (currentRefreshOptions !== undefined) {
28823
+ const proactivelyRefreshToken = async () => {
28824
+ var _a, _b, _c, _d;
28825
+ try {
28826
+ const { accessToken: refreshedAccessToken, refreshToken, expiresIn, } = await refreshAccessToken(currentRefreshOptions, options.dpopKey, options.eventEmitter);
28827
+ currentAccessToken = refreshedAccessToken;
28828
+ if (refreshToken !== undefined) {
28829
+ currentRefreshOptions.refreshToken = refreshToken;
28830
+ }
28831
+ clearTimeout(latestTimeout);
28832
+ latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(expiresIn) * 1000);
28833
+ (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
28834
+ }
28835
+ catch (e) {
28836
+ if (e instanceof OidcProviderError) {
28837
+ (_b = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(EVENTS.ERROR, e.error, e.errorDescription);
28838
+ (_c = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _c === void 0 ? void 0 : _c.emit(EVENTS.SESSION_EXPIRED);
28839
+ }
28840
+ if (e instanceof InvalidResponseError &&
28841
+ e.missingFields.includes("access_token")) {
28842
+ (_d = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _d === void 0 ? void 0 : _d.emit(EVENTS.SESSION_EXPIRED);
28843
+ }
28844
+ }
28845
+ };
28846
+ latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(options.expiresIn) * 1000);
28847
+ (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
28848
+ }
28849
+ else if (options !== undefined && options.eventEmitter !== undefined) {
28850
+ const expirationTimeout = setTimeout(() => {
28851
+ options.eventEmitter.emit(EVENTS.SESSION_EXPIRED);
28852
+ }, computeRefreshDelay(options.expiresIn) * 1000);
28853
+ options.eventEmitter.emit(EVENTS.TIMEOUT_SET, expirationTimeout);
28854
+ }
28855
+ return async (url, requestInit) => {
28856
+ let response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, url, requestInit, options === null || options === void 0 ? void 0 : options.dpopKey);
28857
+ const failedButNotExpectedAuthError = !response.ok && !isExpectedAuthError(response.status);
28858
+ if (response.ok || failedButNotExpectedAuthError) {
28859
+ return response;
28860
+ }
28861
+ const hasBeenRedirected = response.url !== url;
28862
+ if (hasBeenRedirected && (options === null || options === void 0 ? void 0 : options.dpopKey) !== undefined) {
28863
+ response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, response.url, requestInit, options.dpopKey);
28864
+ }
28865
+ return response;
28866
+ };
28384
28867
  }
28385
28868
 
28386
- const StorageUtilityGetResponse = "getResponse";
28387
- const StorageUtilityMock = {
28388
- get: async (key, options) => StorageUtilityGetResponse,
28389
- set: async (key, value) => {
28390
- },
28391
- delete: async (key) => {
28392
- },
28393
- getForUser: async (userId, key, options) => StorageUtilityGetResponse,
28394
- setForUser: async (userId, values, options) => {
28395
- },
28396
- deleteForUser: async (userId, key, options) => {
28397
- },
28398
- deleteAllUserData: async (userId, options) => {
28399
- },
28400
- };
28401
- const mockStorage = (stored) => {
28402
- const store = stored;
28403
- return {
28404
- get: async (key) => {
28405
- if (store[key] === undefined) {
28406
- return undefined;
28407
- }
28408
- if (typeof store[key] === "string") {
28409
- return store[key];
28410
- }
28411
- return JSON.stringify(store[key]);
28412
- },
28413
- set: async (key, value) => {
28414
- store[key] = value;
28415
- },
28416
- delete: async (key) => {
28417
- delete store[key];
28418
- },
28419
- };
28420
- };
28421
- const mockStorageUtility = (stored, isSecure = false) => {
28422
- if (isSecure) {
28423
- return new StorageUtility(mockStorage(stored), mockStorage({}));
28424
- }
28425
- return new StorageUtility(mockStorage({}), mockStorage(stored));
28869
+ const StorageUtilityGetResponse = "getResponse";
28870
+ const StorageUtilityMock = {
28871
+ get: async (key, options) => StorageUtilityGetResponse,
28872
+ set: async (key, value) => {
28873
+ },
28874
+ delete: async (key) => {
28875
+ },
28876
+ getForUser: async (userId, key, options) => StorageUtilityGetResponse,
28877
+ setForUser: async (userId, values, options) => {
28878
+ },
28879
+ deleteForUser: async (userId, key, options) => {
28880
+ },
28881
+ deleteAllUserData: async (userId, options) => {
28882
+ },
28883
+ };
28884
+ const mockStorage = (stored) => {
28885
+ const store = stored;
28886
+ return {
28887
+ get: async (key) => {
28888
+ if (store[key] === undefined) {
28889
+ return undefined;
28890
+ }
28891
+ if (typeof store[key] === "string") {
28892
+ return store[key];
28893
+ }
28894
+ return JSON.stringify(store[key]);
28895
+ },
28896
+ set: async (key, value) => {
28897
+ store[key] = value;
28898
+ },
28899
+ delete: async (key) => {
28900
+ delete store[key];
28901
+ },
28902
+ };
28903
+ };
28904
+ const mockStorageUtility = (stored, isSecure = false) => {
28905
+ if (isSecure) {
28906
+ return new StorageUtility(mockStorage(stored), mockStorage({}));
28907
+ }
28908
+ return new StorageUtility(mockStorage({}), mockStorage(stored));
28426
28909
  };
28427
28910
 
28428
28911
  exports.AggregateHandler = AggregateHandler;
@@ -29646,6 +30129,29 @@ function validate(uuid) {
29646
30129
 
29647
30130
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (validate);
29648
30131
 
30132
+ /***/ }),
30133
+
30134
+ /***/ "./node_modules/@inrupt/universal-fetch/dist/index-browser.js":
30135
+ /*!********************************************************************!*\
30136
+ !*** ./node_modules/@inrupt/universal-fetch/dist/index-browser.js ***!
30137
+ \********************************************************************/
30138
+ /***/ ((__unused_webpack_module, exports) => {
30139
+
30140
+ "use strict";
30141
+
30142
+
30143
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
30144
+
30145
+ var indexBrowser = globalThis.fetch;
30146
+ const { fetch, Response, Request, Headers } = globalThis;
30147
+
30148
+ exports.Headers = Headers;
30149
+ exports.Request = Request;
30150
+ exports.Response = Response;
30151
+ exports["default"] = indexBrowser;
30152
+ exports.fetch = fetch;
30153
+
30154
+
29649
30155
  /***/ }),
29650
30156
 
29651
30157
  /***/ "./node_modules/@noble/curves/_shortw_utils.js":
@@ -60290,522 +60796,545 @@ __webpack_require__.r(__webpack_exports__);
60290
60796
  /* harmony export */ "saveSessionInfoToStorage": () => (/* binding */ saveSessionInfoToStorage)
60291
60797
  /* harmony export */ });
60292
60798
  /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
60293
- /* harmony import */ var cross_fetch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/browser-ponyfill.js");
60294
- /* harmony import */ var jose__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! jose */ "./node_modules/jose/dist/browser/index.js");
60799
+ /* harmony import */ var _inrupt_universal_fetch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @inrupt/universal-fetch */ "./node_modules/@inrupt/universal-fetch/dist/index-browser.mjs");
60800
+ /* harmony import */ var jose__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jose */ "./node_modules/jose/dist/browser/index.js");
60295
60801
  /* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! uuid */ "./node_modules/@inrupt/solid-client-authn-core/node_modules/uuid/dist/esm-browser/v4.js");
60296
60802
 
60297
60803
 
60298
60804
 
60299
60805
 
60300
60806
 
60301
- const SOLID_CLIENT_AUTHN_KEY_PREFIX = "solidClientAuthn:";
60302
- const PREFERRED_SIGNING_ALG = ["ES256", "RS256"];
60303
- const EVENTS = {
60304
- ERROR: "error",
60305
- LOGIN: "login",
60306
- LOGOUT: "logout",
60307
- NEW_REFRESH_TOKEN: "newRefreshToken",
60308
- SESSION_EXPIRED: "sessionExpired",
60309
- SESSION_EXTENDED: "sessionExtended",
60310
- SESSION_RESTORED: "sessionRestore",
60311
- TIMEOUT_SET: "timeoutSet",
60312
- };
60313
- const REFRESH_BEFORE_EXPIRATION_SECONDS = 5;
60314
- const SCOPE_OPENID = "openid";
60315
- const SCOPE_OFFLINE = "offline_access";
60316
- const SCOPE_WEBID = "webid";
60807
+ const SOLID_CLIENT_AUTHN_KEY_PREFIX = "solidClientAuthn:";
60808
+ const PREFERRED_SIGNING_ALG = ["ES256", "RS256"];
60809
+ const EVENTS = {
60810
+ ERROR: "error",
60811
+ LOGIN: "login",
60812
+ LOGOUT: "logout",
60813
+ NEW_REFRESH_TOKEN: "newRefreshToken",
60814
+ SESSION_EXPIRED: "sessionExpired",
60815
+ SESSION_EXTENDED: "sessionExtended",
60816
+ SESSION_RESTORED: "sessionRestore",
60817
+ TIMEOUT_SET: "timeoutSet",
60818
+ };
60819
+ const REFRESH_BEFORE_EXPIRATION_SECONDS = 5;
60820
+ const SCOPE_OPENID = "openid";
60821
+ const SCOPE_OFFLINE = "offline_access";
60822
+ const SCOPE_WEBID = "webid";
60317
60823
  const DEFAULT_SCOPES = [SCOPE_OPENID, SCOPE_OFFLINE, SCOPE_WEBID].join(" ");
60318
60824
 
60319
- const buildProxyHandler = (toExclude, errorMessage) => ({
60320
- get(target, prop, receiver) {
60321
- if (!Object.getOwnPropertyNames(events__WEBPACK_IMPORTED_MODULE_0__.EventEmitter).includes(prop) &&
60322
- Object.getOwnPropertyNames(toExclude).includes(prop)) {
60323
- throw new Error(`${errorMessage}: [${prop}] is not supported`);
60324
- }
60325
- return Reflect.get(target, prop, receiver);
60326
- },
60825
+ const buildProxyHandler = (toExclude, errorMessage) => ({
60826
+ get(target, prop, receiver) {
60827
+ if (!Object.getOwnPropertyNames(events__WEBPACK_IMPORTED_MODULE_0__.EventEmitter).includes(prop) &&
60828
+ Object.getOwnPropertyNames(toExclude).includes(prop)) {
60829
+ throw new Error(`${errorMessage}: [${prop}] is not supported`);
60830
+ }
60831
+ return Reflect.get(target, prop, receiver);
60832
+ },
60327
60833
  });
60328
60834
 
60329
- class AggregateHandler {
60330
- constructor(handleables) {
60331
- this.handleables = handleables;
60332
- }
60333
- async getProperHandler(params) {
60334
- const canHandleList = await Promise.all(this.handleables.map((handleable) => handleable.canHandle(...params)));
60335
- for (let i = 0; i < canHandleList.length; i += 1) {
60336
- if (canHandleList[i]) {
60337
- return this.handleables[i];
60338
- }
60339
- }
60340
- return null;
60341
- }
60342
- async canHandle(...params) {
60343
- return (await this.getProperHandler(params)) !== null;
60344
- }
60345
- async handle(...params) {
60346
- const handler = await this.getProperHandler(params);
60347
- if (handler) {
60348
- return handler.handle(...params);
60349
- }
60350
- throw new Error(`[${this.constructor.name}] cannot find a suitable handler for: ${params
60351
- .map((param) => {
60352
- try {
60353
- return JSON.stringify(param);
60354
- }
60355
- catch (err) {
60356
- return param.toString();
60357
- }
60358
- })
60359
- .join(", ")}`);
60360
- }
60835
+ class AggregateHandler {
60836
+ constructor(handleables) {
60837
+ this.handleables = handleables;
60838
+ }
60839
+ async getProperHandler(params) {
60840
+ const canHandleList = await Promise.all(this.handleables.map((handleable) => handleable.canHandle(...params)));
60841
+ for (let i = 0; i < canHandleList.length; i += 1) {
60842
+ if (canHandleList[i]) {
60843
+ return this.handleables[i];
60844
+ }
60845
+ }
60846
+ return null;
60847
+ }
60848
+ async canHandle(...params) {
60849
+ return (await this.getProperHandler(params)) !== null;
60850
+ }
60851
+ async handle(...params) {
60852
+ const handler = await this.getProperHandler(params);
60853
+ if (handler) {
60854
+ return handler.handle(...params);
60855
+ }
60856
+ throw new Error(`[${this.constructor.name}] cannot find a suitable handler for: ${params
60857
+ .map((param) => {
60858
+ try {
60859
+ return JSON.stringify(param);
60860
+ }
60861
+ catch (err) {
60862
+ return param.toString();
60863
+ }
60864
+ })
60865
+ .join(", ")}`);
60866
+ }
60361
60867
  }
60362
60868
 
60363
- async function fetchJwks(jwksIri, issuerIri) {
60364
- const jwksResponse = await (0,cross_fetch__WEBPACK_IMPORTED_MODULE_1__.fetch)(jwksIri);
60365
- if (jwksResponse.status !== 200) {
60366
- throw new Error(`Could not fetch JWKS for [${issuerIri}] at [${jwksIri}]: ${jwksResponse.status} ${jwksResponse.statusText}`);
60367
- }
60368
- let jwk;
60369
- try {
60370
- jwk = (await jwksResponse.json()).keys[0];
60371
- }
60372
- catch (e) {
60373
- throw new Error(`Malformed JWKS for [${issuerIri}] at [${jwksIri}]: ${e.message}`);
60374
- }
60375
- return jwk;
60376
- }
60377
- async function getWebidFromTokenPayload(idToken, jwksIri, issuerIri, clientId) {
60378
- const jwk = await fetchJwks(jwksIri, issuerIri);
60379
- let payload;
60380
- try {
60381
- const { payload: verifiedPayload } = await (0,jose__WEBPACK_IMPORTED_MODULE_2__.jwtVerify)(idToken, await (0,jose__WEBPACK_IMPORTED_MODULE_2__.importJWK)(jwk), {
60382
- issuer: issuerIri,
60383
- audience: clientId,
60384
- });
60385
- payload = verifiedPayload;
60386
- }
60387
- catch (e) {
60388
- throw new Error(`Token verification failed: ${e.stack}`);
60389
- }
60390
- if (typeof payload.webid === "string") {
60391
- return payload.webid;
60392
- }
60393
- if (typeof payload.sub !== "string") {
60394
- throw new Error(`The token ${JSON.stringify(payload)} is invalid: it has no 'webid' claim and no 'sub' claim.`);
60395
- }
60396
- try {
60397
- new URL(payload.sub);
60398
- return payload.sub;
60399
- }
60400
- catch (e) {
60401
- throw new Error(`The token has no 'webid' claim, and its 'sub' claim of [${payload.sub}] is invalid as a URL - error [${e}].`);
60402
- }
60869
+ async function fetchJwks(jwksIri, issuerIri) {
60870
+ const jwksResponse = await (0,_inrupt_universal_fetch__WEBPACK_IMPORTED_MODULE_2__.fetch)(jwksIri);
60871
+ if (jwksResponse.status !== 200) {
60872
+ throw new Error(`Could not fetch JWKS for [${issuerIri}] at [${jwksIri}]: ${jwksResponse.status} ${jwksResponse.statusText}`);
60873
+ }
60874
+ let jwk;
60875
+ try {
60876
+ jwk = (await jwksResponse.json()).keys[0];
60877
+ }
60878
+ catch (e) {
60879
+ throw new Error(`Malformed JWKS for [${issuerIri}] at [${jwksIri}]: ${e.message}`);
60880
+ }
60881
+ return jwk;
60882
+ }
60883
+ async function getWebidFromTokenPayload(idToken, jwksIri, issuerIri, clientId) {
60884
+ const jwk = await fetchJwks(jwksIri, issuerIri);
60885
+ let payload;
60886
+ try {
60887
+ const { payload: verifiedPayload } = await (0,jose__WEBPACK_IMPORTED_MODULE_1__.jwtVerify)(idToken, await (0,jose__WEBPACK_IMPORTED_MODULE_1__.importJWK)(jwk), {
60888
+ issuer: issuerIri,
60889
+ audience: clientId,
60890
+ });
60891
+ payload = verifiedPayload;
60892
+ }
60893
+ catch (e) {
60894
+ throw new Error(`Token verification failed: ${e.stack}`);
60895
+ }
60896
+ if (typeof payload.webid === "string") {
60897
+ return payload.webid;
60898
+ }
60899
+ if (typeof payload.sub !== "string") {
60900
+ throw new Error(`The token ${JSON.stringify(payload)} is invalid: it has no 'webid' claim and no 'sub' claim.`);
60901
+ }
60902
+ try {
60903
+ new URL(payload.sub);
60904
+ return payload.sub;
60905
+ }
60906
+ catch (e) {
60907
+ throw new Error(`The token has no 'webid' claim, and its 'sub' claim of [${payload.sub}] is invalid as a URL - error [${e}].`);
60908
+ }
60403
60909
  }
60404
60910
 
60405
- function isValidRedirectUrl(redirectUrl) {
60406
- try {
60407
- const urlObject = new URL(redirectUrl);
60408
- return urlObject.hash === "";
60409
- }
60410
- catch (e) {
60411
- return false;
60412
- }
60911
+ function isValidRedirectUrl(redirectUrl) {
60912
+ try {
60913
+ const urlObject = new URL(redirectUrl);
60914
+ return urlObject.hash === "";
60915
+ }
60916
+ catch (e) {
60917
+ return false;
60918
+ }
60413
60919
  }
60414
60920
 
60415
- function isSupportedTokenType(token) {
60416
- return typeof token === "string" && ["DPoP", "Bearer"].includes(token);
60921
+ function isSupportedTokenType(token) {
60922
+ return typeof token === "string" && ["DPoP", "Bearer"].includes(token);
60417
60923
  }
60418
60924
 
60419
60925
  const USER_SESSION_PREFIX = "solidClientAuthenticationUser";
60420
60926
 
60421
- function isValidUrl(url) {
60422
- try {
60423
- new URL(url);
60424
- return true;
60425
- }
60426
- catch (_a) {
60427
- return false;
60428
- }
60429
- }
60430
- function determineSigningAlg(supported, preferred) {
60431
- var _a;
60432
- return ((_a = preferred.find((signingAlg) => {
60433
- return supported.includes(signingAlg);
60434
- })) !== null && _a !== void 0 ? _a : null);
60435
- }
60436
- function determineClientType(options, issuerConfig) {
60437
- if (options.clientId !== undefined && !isValidUrl(options.clientId)) {
60438
- return "static";
60439
- }
60440
- if (issuerConfig.scopesSupported.includes("webid") &&
60441
- options.clientId !== undefined &&
60442
- isValidUrl(options.clientId)) {
60443
- return "solid-oidc";
60444
- }
60445
- return "dynamic";
60446
- }
60447
- async function handleRegistration(options, issuerConfig, storageUtility, clientRegistrar) {
60448
- const clientType = determineClientType(options, issuerConfig);
60449
- if (clientType === "dynamic") {
60450
- return clientRegistrar.getClient({
60451
- sessionId: options.sessionId,
60452
- clientName: options.clientName,
60453
- redirectUrl: options.redirectUrl,
60454
- }, issuerConfig);
60455
- }
60456
- await storageUtility.setForUser(options.sessionId, {
60457
- clientId: options.clientId,
60458
- });
60459
- if (options.clientSecret) {
60460
- await storageUtility.setForUser(options.sessionId, {
60461
- clientSecret: options.clientSecret,
60462
- });
60463
- }
60464
- if (options.clientName) {
60465
- await storageUtility.setForUser(options.sessionId, {
60466
- clientName: options.clientName,
60467
- });
60468
- }
60469
- return {
60470
- clientId: options.clientId,
60471
- clientSecret: options.clientSecret,
60472
- clientName: options.clientName,
60473
- clientType,
60474
- };
60927
+ function isValidUrl(url) {
60928
+ try {
60929
+ new URL(url);
60930
+ return true;
60931
+ }
60932
+ catch (_a) {
60933
+ return false;
60934
+ }
60935
+ }
60936
+ function determineSigningAlg(supported, preferred) {
60937
+ var _a;
60938
+ return ((_a = preferred.find((signingAlg) => {
60939
+ return supported.includes(signingAlg);
60940
+ })) !== null && _a !== void 0 ? _a : null);
60941
+ }
60942
+ function determineClientType(options, issuerConfig) {
60943
+ if (options.clientId !== undefined && !isValidUrl(options.clientId)) {
60944
+ return "static";
60945
+ }
60946
+ if (issuerConfig.scopesSupported.includes("webid") &&
60947
+ options.clientId !== undefined &&
60948
+ isValidUrl(options.clientId)) {
60949
+ return "solid-oidc";
60950
+ }
60951
+ return "dynamic";
60952
+ }
60953
+ async function handleRegistration(options, issuerConfig, storageUtility, clientRegistrar) {
60954
+ const clientType = determineClientType(options, issuerConfig);
60955
+ if (clientType === "dynamic") {
60956
+ return clientRegistrar.getClient({
60957
+ sessionId: options.sessionId,
60958
+ clientName: options.clientName,
60959
+ redirectUrl: options.redirectUrl,
60960
+ }, issuerConfig);
60961
+ }
60962
+ await storageUtility.setForUser(options.sessionId, {
60963
+ clientId: options.clientId,
60964
+ });
60965
+ if (options.clientSecret) {
60966
+ await storageUtility.setForUser(options.sessionId, {
60967
+ clientSecret: options.clientSecret,
60968
+ });
60969
+ }
60970
+ if (options.clientName) {
60971
+ await storageUtility.setForUser(options.sessionId, {
60972
+ clientName: options.clientName,
60973
+ });
60974
+ }
60975
+ return {
60976
+ clientId: options.clientId,
60977
+ clientSecret: options.clientSecret,
60978
+ clientName: options.clientName,
60979
+ clientType,
60980
+ };
60475
60981
  }
60476
60982
 
60477
- async function getSessionIdFromOauthState(storageUtility, oauthState) {
60478
- return storageUtility.getForUser(oauthState, "sessionId");
60479
- }
60480
- async function loadOidcContextFromStorage(sessionId, storageUtility, configFetcher) {
60481
- try {
60482
- const [issuerIri, codeVerifier, storedRedirectIri, dpop] = await Promise.all([
60483
- storageUtility.getForUser(sessionId, "issuer", {
60484
- errorIfNull: true,
60485
- }),
60486
- storageUtility.getForUser(sessionId, "codeVerifier"),
60487
- storageUtility.getForUser(sessionId, "redirectUrl"),
60488
- storageUtility.getForUser(sessionId, "dpop", { errorIfNull: true }),
60489
- ]);
60490
- await storageUtility.deleteForUser(sessionId, "codeVerifier");
60491
- const issuerConfig = await configFetcher.fetchConfig(issuerIri);
60492
- return {
60493
- codeVerifier,
60494
- redirectUrl: storedRedirectIri,
60495
- issuerConfig,
60496
- dpop: dpop === "true",
60497
- };
60498
- }
60499
- catch (e) {
60500
- throw new Error(`Failed to retrieve OIDC context from storage associated with session [${sessionId}]: ${e}`);
60501
- }
60502
- }
60503
- async function saveSessionInfoToStorage(storageUtility, sessionId, webId, isLoggedIn, refreshToken, secure, dpopKey) {
60504
- if (refreshToken !== undefined) {
60505
- await storageUtility.setForUser(sessionId, { refreshToken }, { secure });
60506
- }
60507
- if (webId !== undefined) {
60508
- await storageUtility.setForUser(sessionId, { webId }, { secure });
60509
- }
60510
- if (isLoggedIn !== undefined) {
60511
- await storageUtility.setForUser(sessionId, { isLoggedIn }, { secure });
60512
- }
60513
- if (dpopKey !== undefined) {
60514
- await storageUtility.setForUser(sessionId, {
60515
- publicKey: JSON.stringify(dpopKey.publicKey),
60516
- privateKey: JSON.stringify(await (0,jose__WEBPACK_IMPORTED_MODULE_2__.exportJWK)(dpopKey.privateKey)),
60517
- }, { secure });
60518
- }
60519
- }
60520
- class StorageUtility {
60521
- constructor(secureStorage, insecureStorage) {
60522
- this.secureStorage = secureStorage;
60523
- this.insecureStorage = insecureStorage;
60524
- }
60525
- getKey(userId) {
60526
- return `solidClientAuthenticationUser:${userId}`;
60527
- }
60528
- async getUserData(userId, secure) {
60529
- const stored = await (secure
60530
- ? this.secureStorage
60531
- : this.insecureStorage).get(this.getKey(userId));
60532
- if (stored === undefined) {
60533
- return {};
60534
- }
60535
- try {
60536
- return JSON.parse(stored);
60537
- }
60538
- catch (err) {
60539
- throw new Error(`Data for user [${userId}] in [${secure ? "secure" : "unsecure"}] storage is corrupted - expected valid JSON, but got: ${stored}`);
60540
- }
60541
- }
60542
- async setUserData(userId, data, secure) {
60543
- await (secure ? this.secureStorage : this.insecureStorage).set(this.getKey(userId), JSON.stringify(data));
60544
- }
60545
- async get(key, options) {
60546
- const value = await ((options === null || options === void 0 ? void 0 : options.secure)
60547
- ? this.secureStorage
60548
- : this.insecureStorage).get(key);
60549
- if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
60550
- throw new Error(`[${key}] is not stored`);
60551
- }
60552
- return value;
60553
- }
60554
- async set(key, value, options) {
60555
- return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).set(key, value);
60556
- }
60557
- async delete(key, options) {
60558
- return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(key);
60559
- }
60560
- async getForUser(userId, key, options) {
60561
- const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
60562
- let value;
60563
- if (!userData || !userData[key]) {
60564
- value = undefined;
60565
- }
60566
- value = userData[key];
60567
- if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
60568
- throw new Error(`Field [${key}] for user [${userId}] is not stored`);
60569
- }
60570
- return value || undefined;
60571
- }
60572
- async setForUser(userId, values, options) {
60573
- let userData;
60574
- try {
60575
- userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
60576
- }
60577
- catch (_a) {
60578
- userData = {};
60579
- }
60580
- await this.setUserData(userId, { ...userData, ...values }, options === null || options === void 0 ? void 0 : options.secure);
60581
- }
60582
- async deleteForUser(userId, key, options) {
60583
- const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
60584
- delete userData[key];
60585
- await this.setUserData(userId, userData, options === null || options === void 0 ? void 0 : options.secure);
60586
- }
60587
- async deleteAllUserData(userId, options) {
60588
- await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
60589
- }
60983
+ async function getSessionIdFromOauthState(storageUtility, oauthState) {
60984
+ return storageUtility.getForUser(oauthState, "sessionId");
60985
+ }
60986
+ async function loadOidcContextFromStorage(sessionId, storageUtility, configFetcher) {
60987
+ try {
60988
+ const [issuerIri, codeVerifier, storedRedirectIri, dpop] = await Promise.all([
60989
+ storageUtility.getForUser(sessionId, "issuer", {
60990
+ errorIfNull: true,
60991
+ }),
60992
+ storageUtility.getForUser(sessionId, "codeVerifier"),
60993
+ storageUtility.getForUser(sessionId, "redirectUrl"),
60994
+ storageUtility.getForUser(sessionId, "dpop", { errorIfNull: true }),
60995
+ ]);
60996
+ await storageUtility.deleteForUser(sessionId, "codeVerifier");
60997
+ const issuerConfig = await configFetcher.fetchConfig(issuerIri);
60998
+ return {
60999
+ codeVerifier,
61000
+ redirectUrl: storedRedirectIri,
61001
+ issuerConfig,
61002
+ dpop: dpop === "true",
61003
+ };
61004
+ }
61005
+ catch (e) {
61006
+ throw new Error(`Failed to retrieve OIDC context from storage associated with session [${sessionId}]: ${e}`);
61007
+ }
61008
+ }
61009
+ async function saveSessionInfoToStorage(storageUtility, sessionId, webId, isLoggedIn, refreshToken, secure, dpopKey) {
61010
+ if (refreshToken !== undefined) {
61011
+ await storageUtility.setForUser(sessionId, { refreshToken }, { secure });
61012
+ }
61013
+ if (webId !== undefined) {
61014
+ await storageUtility.setForUser(sessionId, { webId }, { secure });
61015
+ }
61016
+ if (isLoggedIn !== undefined) {
61017
+ await storageUtility.setForUser(sessionId, { isLoggedIn }, { secure });
61018
+ }
61019
+ if (dpopKey !== undefined) {
61020
+ await storageUtility.setForUser(sessionId, {
61021
+ publicKey: JSON.stringify(dpopKey.publicKey),
61022
+ privateKey: JSON.stringify(await (0,jose__WEBPACK_IMPORTED_MODULE_1__.exportJWK)(dpopKey.privateKey)),
61023
+ }, { secure });
61024
+ }
61025
+ }
61026
+ class StorageUtility {
61027
+ constructor(secureStorage, insecureStorage) {
61028
+ this.secureStorage = secureStorage;
61029
+ this.insecureStorage = insecureStorage;
61030
+ }
61031
+ getKey(userId) {
61032
+ return `solidClientAuthenticationUser:${userId}`;
61033
+ }
61034
+ async getUserData(userId, secure) {
61035
+ const stored = await (secure
61036
+ ? this.secureStorage
61037
+ : this.insecureStorage).get(this.getKey(userId));
61038
+ if (stored === undefined) {
61039
+ return {};
61040
+ }
61041
+ try {
61042
+ return JSON.parse(stored);
61043
+ }
61044
+ catch (err) {
61045
+ throw new Error(`Data for user [${userId}] in [${secure ? "secure" : "unsecure"}] storage is corrupted - expected valid JSON, but got: ${stored}`);
61046
+ }
61047
+ }
61048
+ async setUserData(userId, data, secure) {
61049
+ await (secure ? this.secureStorage : this.insecureStorage).set(this.getKey(userId), JSON.stringify(data));
61050
+ }
61051
+ async get(key, options) {
61052
+ const value = await ((options === null || options === void 0 ? void 0 : options.secure)
61053
+ ? this.secureStorage
61054
+ : this.insecureStorage).get(key);
61055
+ if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
61056
+ throw new Error(`[${key}] is not stored`);
61057
+ }
61058
+ return value;
61059
+ }
61060
+ async set(key, value, options) {
61061
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).set(key, value);
61062
+ }
61063
+ async delete(key, options) {
61064
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(key);
61065
+ }
61066
+ async getForUser(userId, key, options) {
61067
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
61068
+ let value;
61069
+ if (!userData || !userData[key]) {
61070
+ value = undefined;
61071
+ }
61072
+ value = userData[key];
61073
+ if (value === undefined && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
61074
+ throw new Error(`Field [${key}] for user [${userId}] is not stored`);
61075
+ }
61076
+ return value || undefined;
61077
+ }
61078
+ async setForUser(userId, values, options) {
61079
+ let userData;
61080
+ try {
61081
+ userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
61082
+ }
61083
+ catch (_a) {
61084
+ userData = {};
61085
+ }
61086
+ await this.setUserData(userId, { ...userData, ...values }, options === null || options === void 0 ? void 0 : options.secure);
61087
+ }
61088
+ async deleteForUser(userId, key, options) {
61089
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
61090
+ delete userData[key];
61091
+ await this.setUserData(userId, userData, options === null || options === void 0 ? void 0 : options.secure);
61092
+ }
61093
+ async deleteAllUserData(userId, options) {
61094
+ await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
61095
+ }
60590
61096
  }
60591
61097
 
60592
- class InMemoryStorage {
60593
- constructor() {
60594
- this.map = {};
60595
- }
60596
- async get(key) {
60597
- return this.map[key] || undefined;
60598
- }
60599
- async set(key, value) {
60600
- this.map[key] = value;
60601
- }
60602
- async delete(key) {
60603
- delete this.map[key];
60604
- }
61098
+ class InMemoryStorage {
61099
+ constructor() {
61100
+ this.map = {};
61101
+ }
61102
+ async get(key) {
61103
+ return this.map[key] || undefined;
61104
+ }
61105
+ async set(key, value) {
61106
+ this.map[key] = value;
61107
+ }
61108
+ async delete(key) {
61109
+ delete this.map[key];
61110
+ }
60605
61111
  }
60606
61112
 
60607
- class ConfigurationError extends Error {
60608
- constructor(message) {
60609
- super(message);
60610
- }
61113
+ class ConfigurationError extends Error {
61114
+ constructor(message) {
61115
+ super(message);
61116
+ }
60611
61117
  }
60612
61118
 
60613
- class NotImplementedError extends Error {
60614
- constructor(methodName) {
60615
- super(`[${methodName}] is not implemented`);
60616
- }
61119
+ class NotImplementedError extends Error {
61120
+ constructor(methodName) {
61121
+ super(`[${methodName}] is not implemented`);
61122
+ }
60617
61123
  }
60618
61124
 
60619
- class InvalidResponseError extends Error {
60620
- constructor(missingFields) {
60621
- super(`Invalid response from OIDC provider: missing fields ${missingFields}`);
60622
- this.missingFields = missingFields;
60623
- }
61125
+ class InvalidResponseError extends Error {
61126
+ constructor(missingFields) {
61127
+ super(`Invalid response from OIDC provider: missing fields ${missingFields}`);
61128
+ this.missingFields = missingFields;
61129
+ }
60624
61130
  }
60625
61131
 
60626
- class OidcProviderError extends Error {
60627
- constructor(message, error, errorDescription) {
60628
- super(message);
60629
- this.error = error;
60630
- this.errorDescription = errorDescription;
60631
- }
61132
+ class OidcProviderError extends Error {
61133
+ constructor(message, error, errorDescription) {
61134
+ super(message);
61135
+ this.error = error;
61136
+ this.errorDescription = errorDescription;
61137
+ }
60632
61138
  }
60633
61139
 
60634
- function normalizeHTU(audience) {
60635
- const audienceUrl = new URL(audience);
60636
- return new URL(audienceUrl.pathname, audienceUrl.origin).toString();
60637
- }
60638
- async function createDpopHeader(audience, method, dpopKey) {
60639
- return new jose__WEBPACK_IMPORTED_MODULE_2__.SignJWT({
60640
- htu: normalizeHTU(audience),
60641
- htm: method.toUpperCase(),
60642
- jti: (0,uuid__WEBPACK_IMPORTED_MODULE_3__["default"])(),
60643
- })
60644
- .setProtectedHeader({
60645
- alg: PREFERRED_SIGNING_ALG[0],
60646
- jwk: dpopKey.publicKey,
60647
- typ: "dpop+jwt",
60648
- })
60649
- .setIssuedAt()
60650
- .sign(dpopKey.privateKey, {});
60651
- }
60652
- async function generateDpopKeyPair() {
60653
- const { privateKey, publicKey } = await (0,jose__WEBPACK_IMPORTED_MODULE_2__.generateKeyPair)(PREFERRED_SIGNING_ALG[0]);
60654
- const dpopKeyPair = {
60655
- privateKey,
60656
- publicKey: await (0,jose__WEBPACK_IMPORTED_MODULE_2__.exportJWK)(publicKey),
60657
- };
60658
- [dpopKeyPair.publicKey.alg] = PREFERRED_SIGNING_ALG;
60659
- return dpopKeyPair;
61140
+ function normalizeHTU(audience) {
61141
+ const audienceUrl = new URL(audience);
61142
+ return new URL(audienceUrl.pathname, audienceUrl.origin).toString();
61143
+ }
61144
+ async function createDpopHeader(audience, method, dpopKey) {
61145
+ return new jose__WEBPACK_IMPORTED_MODULE_1__.SignJWT({
61146
+ htu: normalizeHTU(audience),
61147
+ htm: method.toUpperCase(),
61148
+ jti: (0,uuid__WEBPACK_IMPORTED_MODULE_3__["default"])(),
61149
+ })
61150
+ .setProtectedHeader({
61151
+ alg: PREFERRED_SIGNING_ALG[0],
61152
+ jwk: dpopKey.publicKey,
61153
+ typ: "dpop+jwt",
61154
+ })
61155
+ .setIssuedAt()
61156
+ .sign(dpopKey.privateKey, {});
61157
+ }
61158
+ async function generateDpopKeyPair() {
61159
+ const { privateKey, publicKey } = await (0,jose__WEBPACK_IMPORTED_MODULE_1__.generateKeyPair)(PREFERRED_SIGNING_ALG[0]);
61160
+ const dpopKeyPair = {
61161
+ privateKey,
61162
+ publicKey: await (0,jose__WEBPACK_IMPORTED_MODULE_1__.exportJWK)(publicKey),
61163
+ };
61164
+ [dpopKeyPair.publicKey.alg] = PREFERRED_SIGNING_ALG;
61165
+ return dpopKeyPair;
60660
61166
  }
60661
61167
 
60662
- const DEFAULT_EXPIRATION_TIME_SECONDS = 600;
60663
- function isExpectedAuthError(statusCode) {
60664
- return [401, 403].includes(statusCode);
60665
- }
60666
- async function buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions) {
60667
- var _a;
60668
- const headers = new cross_fetch__WEBPACK_IMPORTED_MODULE_1__.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
60669
- headers.set("Authorization", `DPoP ${authToken}`);
60670
- headers.set("DPoP", await createDpopHeader(targetUrl, (_a = defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.method) !== null && _a !== void 0 ? _a : "get", dpopKey));
60671
- return {
60672
- ...defaultOptions,
60673
- headers,
60674
- };
60675
- }
60676
- async function buildAuthenticatedHeaders(targetUrl, authToken, dpopKey, defaultOptions) {
60677
- if (dpopKey !== undefined) {
60678
- return buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions);
60679
- }
60680
- const headers = new cross_fetch__WEBPACK_IMPORTED_MODULE_1__.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
60681
- headers.set("Authorization", `Bearer ${authToken}`);
60682
- return {
60683
- ...defaultOptions,
60684
- headers,
60685
- };
60686
- }
60687
- async function makeAuthenticatedRequest(unauthFetch, accessToken, url, defaultRequestInit, dpopKey) {
60688
- return unauthFetch(url, await buildAuthenticatedHeaders(url.toString(), accessToken, dpopKey, defaultRequestInit));
60689
- }
60690
- async function refreshAccessToken(refreshOptions, dpopKey, eventEmitter) {
60691
- var _a;
60692
- const tokenSet = await refreshOptions.tokenRefresher.refresh(refreshOptions.sessionId, refreshOptions.refreshToken, dpopKey);
60693
- eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.SESSION_EXTENDED, (_a = tokenSet.expiresIn) !== null && _a !== void 0 ? _a : DEFAULT_EXPIRATION_TIME_SECONDS);
60694
- if (typeof tokenSet.refreshToken === "string") {
60695
- eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
60696
- }
60697
- return {
60698
- accessToken: tokenSet.accessToken,
60699
- refreshToken: tokenSet.refreshToken,
60700
- expiresIn: tokenSet.expiresIn,
60701
- };
60702
- }
60703
- const computeRefreshDelay = (expiresIn) => {
60704
- if (expiresIn !== undefined) {
60705
- return expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS > 0
60706
- ?
60707
- expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS
60708
- : expiresIn;
60709
- }
60710
- return DEFAULT_EXPIRATION_TIME_SECONDS;
60711
- };
60712
- async function buildAuthenticatedFetch(unauthFetch, accessToken, options) {
60713
- var _a;
60714
- let currentAccessToken = accessToken;
60715
- let latestTimeout;
60716
- const currentRefreshOptions = options === null || options === void 0 ? void 0 : options.refreshOptions;
60717
- if (currentRefreshOptions !== undefined) {
60718
- const proactivelyRefreshToken = async () => {
60719
- var _a, _b, _c, _d;
60720
- try {
60721
- const { accessToken: refreshedAccessToken, refreshToken, expiresIn, } = await refreshAccessToken(currentRefreshOptions, options.dpopKey, options.eventEmitter);
60722
- currentAccessToken = refreshedAccessToken;
60723
- if (refreshToken !== undefined) {
60724
- currentRefreshOptions.refreshToken = refreshToken;
60725
- }
60726
- clearTimeout(latestTimeout);
60727
- latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(expiresIn) * 1000);
60728
- (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
60729
- }
60730
- catch (e) {
60731
- if (e instanceof OidcProviderError) {
60732
- (_b = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(EVENTS.ERROR, e.error, e.errorDescription);
60733
- (_c = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _c === void 0 ? void 0 : _c.emit(EVENTS.SESSION_EXPIRED);
60734
- }
60735
- if (e instanceof InvalidResponseError &&
60736
- e.missingFields.includes("access_token")) {
60737
- (_d = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _d === void 0 ? void 0 : _d.emit(EVENTS.SESSION_EXPIRED);
60738
- }
60739
- }
60740
- };
60741
- latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(options.expiresIn) * 1000);
60742
- (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
60743
- }
60744
- else if (options !== undefined && options.eventEmitter !== undefined) {
60745
- const expirationTimeout = setTimeout(() => {
60746
- options.eventEmitter.emit(EVENTS.SESSION_EXPIRED);
60747
- }, computeRefreshDelay(options.expiresIn) * 1000);
60748
- options.eventEmitter.emit(EVENTS.TIMEOUT_SET, expirationTimeout);
60749
- }
60750
- return async (url, requestInit) => {
60751
- let response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, url, requestInit, options === null || options === void 0 ? void 0 : options.dpopKey);
60752
- const failedButNotExpectedAuthError = !response.ok && !isExpectedAuthError(response.status);
60753
- if (response.ok || failedButNotExpectedAuthError) {
60754
- return response;
60755
- }
60756
- const hasBeenRedirected = response.url !== url;
60757
- if (hasBeenRedirected && (options === null || options === void 0 ? void 0 : options.dpopKey) !== undefined) {
60758
- response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, response.url, requestInit, options.dpopKey);
60759
- }
60760
- return response;
60761
- };
61168
+ const DEFAULT_EXPIRATION_TIME_SECONDS = 600;
61169
+ function isExpectedAuthError(statusCode) {
61170
+ return [401, 403].includes(statusCode);
61171
+ }
61172
+ async function buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions) {
61173
+ var _a;
61174
+ const headers = new _inrupt_universal_fetch__WEBPACK_IMPORTED_MODULE_2__.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
61175
+ headers.set("Authorization", `DPoP ${authToken}`);
61176
+ headers.set("DPoP", await createDpopHeader(targetUrl, (_a = defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.method) !== null && _a !== void 0 ? _a : "get", dpopKey));
61177
+ return {
61178
+ ...defaultOptions,
61179
+ headers,
61180
+ };
61181
+ }
61182
+ async function buildAuthenticatedHeaders(targetUrl, authToken, dpopKey, defaultOptions) {
61183
+ if (dpopKey !== undefined) {
61184
+ return buildDpopFetchOptions(targetUrl, authToken, dpopKey, defaultOptions);
61185
+ }
61186
+ const headers = new _inrupt_universal_fetch__WEBPACK_IMPORTED_MODULE_2__.Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
61187
+ headers.set("Authorization", `Bearer ${authToken}`);
61188
+ return {
61189
+ ...defaultOptions,
61190
+ headers,
61191
+ };
61192
+ }
61193
+ async function makeAuthenticatedRequest(unauthFetch, accessToken, url, defaultRequestInit, dpopKey) {
61194
+ return unauthFetch(url, await buildAuthenticatedHeaders(url.toString(), accessToken, dpopKey, defaultRequestInit));
61195
+ }
61196
+ async function refreshAccessToken(refreshOptions, dpopKey, eventEmitter) {
61197
+ var _a;
61198
+ const tokenSet = await refreshOptions.tokenRefresher.refresh(refreshOptions.sessionId, refreshOptions.refreshToken, dpopKey);
61199
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.SESSION_EXTENDED, (_a = tokenSet.expiresIn) !== null && _a !== void 0 ? _a : DEFAULT_EXPIRATION_TIME_SECONDS);
61200
+ if (typeof tokenSet.refreshToken === "string") {
61201
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
61202
+ }
61203
+ return {
61204
+ accessToken: tokenSet.accessToken,
61205
+ refreshToken: tokenSet.refreshToken,
61206
+ expiresIn: tokenSet.expiresIn,
61207
+ };
61208
+ }
61209
+ const computeRefreshDelay = (expiresIn) => {
61210
+ if (expiresIn !== undefined) {
61211
+ return expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS > 0
61212
+ ?
61213
+ expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS
61214
+ : expiresIn;
61215
+ }
61216
+ return DEFAULT_EXPIRATION_TIME_SECONDS;
61217
+ };
61218
+ async function buildAuthenticatedFetch(unauthFetch, accessToken, options) {
61219
+ var _a;
61220
+ let currentAccessToken = accessToken;
61221
+ let latestTimeout;
61222
+ const currentRefreshOptions = options === null || options === void 0 ? void 0 : options.refreshOptions;
61223
+ if (currentRefreshOptions !== undefined) {
61224
+ const proactivelyRefreshToken = async () => {
61225
+ var _a, _b, _c, _d;
61226
+ try {
61227
+ const { accessToken: refreshedAccessToken, refreshToken, expiresIn, } = await refreshAccessToken(currentRefreshOptions, options.dpopKey, options.eventEmitter);
61228
+ currentAccessToken = refreshedAccessToken;
61229
+ if (refreshToken !== undefined) {
61230
+ currentRefreshOptions.refreshToken = refreshToken;
61231
+ }
61232
+ clearTimeout(latestTimeout);
61233
+ latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(expiresIn) * 1000);
61234
+ (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
61235
+ }
61236
+ catch (e) {
61237
+ if (e instanceof OidcProviderError) {
61238
+ (_b = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(EVENTS.ERROR, e.error, e.errorDescription);
61239
+ (_c = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _c === void 0 ? void 0 : _c.emit(EVENTS.SESSION_EXPIRED);
61240
+ }
61241
+ if (e instanceof InvalidResponseError &&
61242
+ e.missingFields.includes("access_token")) {
61243
+ (_d = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _d === void 0 ? void 0 : _d.emit(EVENTS.SESSION_EXPIRED);
61244
+ }
61245
+ }
61246
+ };
61247
+ latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(options.expiresIn) * 1000);
61248
+ (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
61249
+ }
61250
+ else if (options !== undefined && options.eventEmitter !== undefined) {
61251
+ const expirationTimeout = setTimeout(() => {
61252
+ options.eventEmitter.emit(EVENTS.SESSION_EXPIRED);
61253
+ }, computeRefreshDelay(options.expiresIn) * 1000);
61254
+ options.eventEmitter.emit(EVENTS.TIMEOUT_SET, expirationTimeout);
61255
+ }
61256
+ return async (url, requestInit) => {
61257
+ let response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, url, requestInit, options === null || options === void 0 ? void 0 : options.dpopKey);
61258
+ const failedButNotExpectedAuthError = !response.ok && !isExpectedAuthError(response.status);
61259
+ if (response.ok || failedButNotExpectedAuthError) {
61260
+ return response;
61261
+ }
61262
+ const hasBeenRedirected = response.url !== url;
61263
+ if (hasBeenRedirected && (options === null || options === void 0 ? void 0 : options.dpopKey) !== undefined) {
61264
+ response = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, response.url, requestInit, options.dpopKey);
61265
+ }
61266
+ return response;
61267
+ };
60762
61268
  }
60763
61269
 
60764
- const StorageUtilityGetResponse = "getResponse";
60765
- const StorageUtilityMock = {
60766
- get: async (key, options) => StorageUtilityGetResponse,
60767
- set: async (key, value) => {
60768
- },
60769
- delete: async (key) => {
60770
- },
60771
- getForUser: async (userId, key, options) => StorageUtilityGetResponse,
60772
- setForUser: async (userId, values, options) => {
60773
- },
60774
- deleteForUser: async (userId, key, options) => {
60775
- },
60776
- deleteAllUserData: async (userId, options) => {
60777
- },
60778
- };
60779
- const mockStorage = (stored) => {
60780
- const store = stored;
60781
- return {
60782
- get: async (key) => {
60783
- if (store[key] === undefined) {
60784
- return undefined;
60785
- }
60786
- if (typeof store[key] === "string") {
60787
- return store[key];
60788
- }
60789
- return JSON.stringify(store[key]);
60790
- },
60791
- set: async (key, value) => {
60792
- store[key] = value;
60793
- },
60794
- delete: async (key) => {
60795
- delete store[key];
60796
- },
60797
- };
60798
- };
60799
- const mockStorageUtility = (stored, isSecure = false) => {
60800
- if (isSecure) {
60801
- return new StorageUtility(mockStorage(stored), mockStorage({}));
60802
- }
60803
- return new StorageUtility(mockStorage({}), mockStorage(stored));
61270
+ const StorageUtilityGetResponse = "getResponse";
61271
+ const StorageUtilityMock = {
61272
+ get: async (key, options) => StorageUtilityGetResponse,
61273
+ set: async (key, value) => {
61274
+ },
61275
+ delete: async (key) => {
61276
+ },
61277
+ getForUser: async (userId, key, options) => StorageUtilityGetResponse,
61278
+ setForUser: async (userId, values, options) => {
61279
+ },
61280
+ deleteForUser: async (userId, key, options) => {
61281
+ },
61282
+ deleteAllUserData: async (userId, options) => {
61283
+ },
61284
+ };
61285
+ const mockStorage = (stored) => {
61286
+ const store = stored;
61287
+ return {
61288
+ get: async (key) => {
61289
+ if (store[key] === undefined) {
61290
+ return undefined;
61291
+ }
61292
+ if (typeof store[key] === "string") {
61293
+ return store[key];
61294
+ }
61295
+ return JSON.stringify(store[key]);
61296
+ },
61297
+ set: async (key, value) => {
61298
+ store[key] = value;
61299
+ },
61300
+ delete: async (key) => {
61301
+ delete store[key];
61302
+ },
61303
+ };
61304
+ };
61305
+ const mockStorageUtility = (stored, isSecure = false) => {
61306
+ if (isSecure) {
61307
+ return new StorageUtility(mockStorage(stored), mockStorage({}));
61308
+ }
61309
+ return new StorageUtility(mockStorage({}), mockStorage(stored));
60804
61310
  };
60805
61311
 
60806
61312
 
60807
61313
 
60808
61314
 
61315
+ /***/ }),
61316
+
61317
+ /***/ "./node_modules/@inrupt/universal-fetch/dist/index-browser.mjs":
61318
+ /*!*********************************************************************!*\
61319
+ !*** ./node_modules/@inrupt/universal-fetch/dist/index-browser.mjs ***!
61320
+ \*********************************************************************/
61321
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
61322
+
61323
+ "use strict";
61324
+ __webpack_require__.r(__webpack_exports__);
61325
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
61326
+ /* harmony export */ "Headers": () => (/* binding */ Headers),
61327
+ /* harmony export */ "Request": () => (/* binding */ Request),
61328
+ /* harmony export */ "Response": () => (/* binding */ Response),
61329
+ /* harmony export */ "default": () => (/* binding */ indexBrowser),
61330
+ /* harmony export */ "fetch": () => (/* binding */ fetch)
61331
+ /* harmony export */ });
61332
+ var indexBrowser = globalThis.fetch;
61333
+ const { fetch, Response, Request, Headers } = globalThis;
61334
+
61335
+
61336
+
61337
+
60809
61338
  /***/ }),
60810
61339
 
60811
61340
  /***/ "./node_modules/jose/dist/browser/index.js":
@@ -61873,14 +62402,17 @@ __webpack_require__.r(__webpack_exports__);
61873
62402
  /* harmony export */ "createRemoteJWKSet": () => (/* binding */ createRemoteJWKSet)
61874
62403
  /* harmony export */ });
61875
62404
  /* harmony import */ var _runtime_fetch_jwks_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../runtime/fetch_jwks.js */ "./node_modules/jose/dist/browser/runtime/fetch_jwks.js");
61876
- /* harmony import */ var _runtime_env_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../runtime/env.js */ "./node_modules/jose/dist/browser/runtime/env.js");
61877
- /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
61878
- /* harmony import */ var _local_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./local.js */ "./node_modules/jose/dist/browser/jwks/local.js");
61879
-
62405
+ /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
62406
+ /* harmony import */ var _local_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./local.js */ "./node_modules/jose/dist/browser/jwks/local.js");
61880
62407
 
61881
62408
 
61882
62409
 
61883
- class RemoteJWKSet extends _local_js__WEBPACK_IMPORTED_MODULE_3__.LocalJWKSet {
62410
+ function isCloudflareWorkers() {
62411
+ return (typeof WebSocketPair !== 'undefined' ||
62412
+ (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
62413
+ (typeof EdgeRuntime !== 'undefined' && EdgeRuntime === 'vercel'));
62414
+ }
62415
+ class RemoteJWKSet extends _local_js__WEBPACK_IMPORTED_MODULE_2__.LocalJWKSet {
61884
62416
  constructor(url, options) {
61885
62417
  super({ keys: [] });
61886
62418
  this._jwks = undefined;
@@ -61913,7 +62445,7 @@ class RemoteJWKSet extends _local_js__WEBPACK_IMPORTED_MODULE_3__.LocalJWKSet {
61913
62445
  return await super.getKey(protectedHeader, token);
61914
62446
  }
61915
62447
  catch (err) {
61916
- if (err instanceof _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JWKSNoMatchingKey) {
62448
+ if (err instanceof _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JWKSNoMatchingKey) {
61917
62449
  if (this.coolingDown() === false) {
61918
62450
  await this.reload();
61919
62451
  return super.getKey(protectedHeader, token);
@@ -61923,13 +62455,13 @@ class RemoteJWKSet extends _local_js__WEBPACK_IMPORTED_MODULE_3__.LocalJWKSet {
61923
62455
  }
61924
62456
  }
61925
62457
  async reload() {
61926
- if (this._pendingFetch && (0,_runtime_env_js__WEBPACK_IMPORTED_MODULE_1__.isCloudflareWorkers)()) {
62458
+ if (this._pendingFetch && isCloudflareWorkers()) {
61927
62459
  this._pendingFetch = undefined;
61928
62460
  }
61929
62461
  this._pendingFetch || (this._pendingFetch = (0,_runtime_fetch_jwks_js__WEBPACK_IMPORTED_MODULE_0__["default"])(this._url, this._timeoutDuration, this._options)
61930
62462
  .then((json) => {
61931
- if (!(0,_local_js__WEBPACK_IMPORTED_MODULE_3__.isJWKSLike)(json)) {
61932
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JWKSInvalid('JSON Web Key Set malformed');
62463
+ if (!(0,_local_js__WEBPACK_IMPORTED_MODULE_2__.isJWKSLike)(json)) {
62464
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JWKSInvalid('JSON Web Key Set malformed');
61933
62465
  }
61934
62466
  this._jwks = { keys: json.keys };
61935
62467
  this._jwksTimestamp = Date.now();
@@ -63117,8 +63649,6 @@ __webpack_require__.r(__webpack_exports__);
63117
63649
  /* harmony export */ "checkEncCryptoKey": () => (/* binding */ checkEncCryptoKey),
63118
63650
  /* harmony export */ "checkSigCryptoKey": () => (/* binding */ checkSigCryptoKey)
63119
63651
  /* harmony export */ });
63120
- /* harmony import */ var _runtime_env_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../runtime/env.js */ "./node_modules/jose/dist/browser/runtime/env.js");
63121
-
63122
63652
  function unusable(name, prop = 'algorithm.name') {
63123
63653
  return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
63124
63654
  }
@@ -63193,11 +63723,6 @@ function checkSigCryptoKey(key, alg, ...usages) {
63193
63723
  }
63194
63724
  case 'EdDSA': {
63195
63725
  if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
63196
- if ((0,_runtime_env_js__WEBPACK_IMPORTED_MODULE_0__.isCloudflareWorkers)()) {
63197
- if (isAlgorithm(key.algorithm, 'NODE-ED25519'))
63198
- break;
63199
- throw unusable('Ed25519, Ed448, or NODE-ED25519');
63200
- }
63201
63726
  throw unusable('Ed25519 or Ed448');
63202
63727
  }
63203
63728
  break;
@@ -64028,14 +64553,12 @@ __webpack_require__.r(__webpack_exports__);
64028
64553
  /* harmony export */ "toPKCS8": () => (/* binding */ toPKCS8),
64029
64554
  /* harmony export */ "toSPKI": () => (/* binding */ toSPKI)
64030
64555
  /* harmony export */ });
64031
- /* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./env.js */ "./node_modules/jose/dist/browser/runtime/env.js");
64032
- /* harmony import */ var _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./webcrypto.js */ "./node_modules/jose/dist/browser/runtime/webcrypto.js");
64033
- /* harmony import */ var _lib_invalid_key_input_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../lib/invalid_key_input.js */ "./node_modules/jose/dist/browser/lib/invalid_key_input.js");
64034
- /* harmony import */ var _base64url_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./base64url.js */ "./node_modules/jose/dist/browser/runtime/base64url.js");
64035
- /* harmony import */ var _lib_format_pem_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../lib/format_pem.js */ "./node_modules/jose/dist/browser/lib/format_pem.js");
64036
- /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
64037
- /* harmony import */ var _is_key_like_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./is_key_like.js */ "./node_modules/jose/dist/browser/runtime/is_key_like.js");
64038
-
64556
+ /* harmony import */ var _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./webcrypto.js */ "./node_modules/jose/dist/browser/runtime/webcrypto.js");
64557
+ /* harmony import */ var _lib_invalid_key_input_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../lib/invalid_key_input.js */ "./node_modules/jose/dist/browser/lib/invalid_key_input.js");
64558
+ /* harmony import */ var _base64url_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./base64url.js */ "./node_modules/jose/dist/browser/runtime/base64url.js");
64559
+ /* harmony import */ var _lib_format_pem_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../lib/format_pem.js */ "./node_modules/jose/dist/browser/lib/format_pem.js");
64560
+ /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
64561
+ /* harmony import */ var _is_key_like_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./is_key_like.js */ "./node_modules/jose/dist/browser/runtime/is_key_like.js");
64039
64562
 
64040
64563
 
64041
64564
 
@@ -64043,8 +64566,8 @@ __webpack_require__.r(__webpack_exports__);
64043
64566
 
64044
64567
 
64045
64568
  const genericExport = async (keyType, keyFormat, key) => {
64046
- if (!(0,_webcrypto_js__WEBPACK_IMPORTED_MODULE_1__.isCryptoKey)(key)) {
64047
- throw new TypeError((0,_lib_invalid_key_input_js__WEBPACK_IMPORTED_MODULE_2__["default"])(key, ..._is_key_like_js__WEBPACK_IMPORTED_MODULE_6__.types));
64569
+ if (!(0,_webcrypto_js__WEBPACK_IMPORTED_MODULE_0__.isCryptoKey)(key)) {
64570
+ throw new TypeError((0,_lib_invalid_key_input_js__WEBPACK_IMPORTED_MODULE_1__["default"])(key, ..._is_key_like_js__WEBPACK_IMPORTED_MODULE_5__.types));
64048
64571
  }
64049
64572
  if (!key.extractable) {
64050
64573
  throw new TypeError('CryptoKey is not extractable');
@@ -64052,7 +64575,7 @@ const genericExport = async (keyType, keyFormat, key) => {
64052
64575
  if (key.type !== keyType) {
64053
64576
  throw new TypeError(`key is not a ${keyType} key`);
64054
64577
  }
64055
- return (0,_lib_format_pem_js__WEBPACK_IMPORTED_MODULE_4__["default"])((0,_base64url_js__WEBPACK_IMPORTED_MODULE_3__.encodeBase64)(new Uint8Array(await _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
64578
+ return (0,_lib_format_pem_js__WEBPACK_IMPORTED_MODULE_3__["default"])((0,_base64url_js__WEBPACK_IMPORTED_MODULE_2__.encodeBase64)(new Uint8Array(await _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__["default"].subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
64056
64579
  };
64057
64580
  const toSPKI = (key) => {
64058
64581
  return genericExport('public', 'spki', key);
@@ -64090,11 +64613,11 @@ const getNamedCurve = (keyData) => {
64090
64613
  case findOid(keyData, [0x2b, 0x65, 0x71]):
64091
64614
  return 'Ed448';
64092
64615
  default:
64093
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_5__.JOSENotSupported('Invalid or unsupported EC Key Curve or OKP Key Sub Type');
64616
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_4__.JOSENotSupported('Invalid or unsupported EC Key Curve or OKP Key Sub Type');
64094
64617
  }
64095
64618
  };
64096
64619
  const genericImport = async (replace, keyFormat, pem, alg, options) => {
64097
- var _a, _b;
64620
+ var _a;
64098
64621
  let algorithm;
64099
64622
  let keyUsages;
64100
64623
  const keyData = new Uint8Array(atob(pem.replace(replace, ''))
@@ -64150,20 +64673,9 @@ const genericImport = async (replace, keyFormat, pem, alg, options) => {
64150
64673
  keyUsages = isPublic ? ['verify'] : ['sign'];
64151
64674
  break;
64152
64675
  default:
64153
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_5__.JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
64154
- }
64155
- try {
64156
- return await _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.importKey(keyFormat, keyData, algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
64157
- }
64158
- catch (err) {
64159
- if (algorithm.name === 'Ed25519' &&
64160
- (err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
64161
- (0,_env_js__WEBPACK_IMPORTED_MODULE_0__.isCloudflareWorkers)()) {
64162
- algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
64163
- return await _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.importKey(keyFormat, keyData, algorithm, (_b = options === null || options === void 0 ? void 0 : options.extractable) !== null && _b !== void 0 ? _b : false, keyUsages);
64164
- }
64165
- throw err;
64676
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_4__.JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
64166
64677
  }
64678
+ return _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__["default"].subtle.importKey(keyFormat, keyData, algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
64167
64679
  };
64168
64680
  const fromPKCS8 = (pem, alg, options) => {
64169
64681
  return genericImport(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, 'pkcs8', pem, alg, options);
@@ -64232,12 +64744,12 @@ function parseElement(bytes) {
64232
64744
  }
64233
64745
  function spkiFromX509(buf) {
64234
64746
  const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
64235
- return (0,_base64url_js__WEBPACK_IMPORTED_MODULE_3__.encodeBase64)(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
64747
+ return (0,_base64url_js__WEBPACK_IMPORTED_MODULE_2__.encodeBase64)(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
64236
64748
  }
64237
64749
  function getSPKI(x509) {
64238
64750
  const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
64239
- const raw = (0,_base64url_js__WEBPACK_IMPORTED_MODULE_3__.decodeBase64)(pem);
64240
- return (0,_lib_format_pem_js__WEBPACK_IMPORTED_MODULE_4__["default"])(spkiFromX509(raw), 'PUBLIC KEY');
64751
+ const raw = (0,_base64url_js__WEBPACK_IMPORTED_MODULE_2__.decodeBase64)(pem);
64752
+ return (0,_lib_format_pem_js__WEBPACK_IMPORTED_MODULE_3__["default"])(spkiFromX509(raw), 'PUBLIC KEY');
64241
64753
  }
64242
64754
  const fromX509 = (pem, alg, options) => {
64243
64755
  let spki;
@@ -64665,26 +65177,6 @@ const encrypt = async (enc, plaintext, cek, iv, aad) => {
64665
65177
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (encrypt);
64666
65178
 
64667
65179
 
64668
- /***/ }),
64669
-
64670
- /***/ "./node_modules/jose/dist/browser/runtime/env.js":
64671
- /*!*******************************************************!*\
64672
- !*** ./node_modules/jose/dist/browser/runtime/env.js ***!
64673
- \*******************************************************/
64674
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
64675
-
64676
- "use strict";
64677
- __webpack_require__.r(__webpack_exports__);
64678
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
64679
- /* harmony export */ "isCloudflareWorkers": () => (/* binding */ isCloudflareWorkers)
64680
- /* harmony export */ });
64681
- function isCloudflareWorkers() {
64682
- return (typeof WebSocketPair !== 'undefined' ||
64683
- (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
64684
- (typeof EdgeRuntime !== 'undefined' && EdgeRuntime === 'vercel'));
64685
- }
64686
-
64687
-
64688
65180
  /***/ }),
64689
65181
 
64690
65182
  /***/ "./node_modules/jose/dist/browser/runtime/fetch_jwks.js":
@@ -64749,11 +65241,9 @@ __webpack_require__.r(__webpack_exports__);
64749
65241
  /* harmony export */ "generateKeyPair": () => (/* binding */ generateKeyPair),
64750
65242
  /* harmony export */ "generateSecret": () => (/* binding */ generateSecret)
64751
65243
  /* harmony export */ });
64752
- /* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./env.js */ "./node_modules/jose/dist/browser/runtime/env.js");
64753
- /* harmony import */ var _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./webcrypto.js */ "./node_modules/jose/dist/browser/runtime/webcrypto.js");
64754
- /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
64755
- /* harmony import */ var _random_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./random.js */ "./node_modules/jose/dist/browser/runtime/random.js");
64756
-
65244
+ /* harmony import */ var _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./webcrypto.js */ "./node_modules/jose/dist/browser/runtime/webcrypto.js");
65245
+ /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
65246
+ /* harmony import */ var _random_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./random.js */ "./node_modules/jose/dist/browser/runtime/random.js");
64757
65247
 
64758
65248
 
64759
65249
 
@@ -64774,7 +65264,7 @@ async function generateSecret(alg, options) {
64774
65264
  case 'A192CBC-HS384':
64775
65265
  case 'A256CBC-HS512':
64776
65266
  length = parseInt(alg.slice(-3), 10);
64777
- return (0,_random_js__WEBPACK_IMPORTED_MODULE_3__["default"])(new Uint8Array(length >> 3));
65267
+ return (0,_random_js__WEBPACK_IMPORTED_MODULE_2__["default"])(new Uint8Array(length >> 3));
64778
65268
  case 'A128KW':
64779
65269
  case 'A192KW':
64780
65270
  case 'A256KW':
@@ -64793,20 +65283,20 @@ async function generateSecret(alg, options) {
64793
65283
  keyUsages = ['encrypt', 'decrypt'];
64794
65284
  break;
64795
65285
  default:
64796
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65286
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
64797
65287
  }
64798
- return _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.generateKey(algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
65288
+ return _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__["default"].subtle.generateKey(algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
64799
65289
  }
64800
65290
  function getModulusLengthOption(options) {
64801
65291
  var _a;
64802
65292
  const modulusLength = (_a = options === null || options === void 0 ? void 0 : options.modulusLength) !== null && _a !== void 0 ? _a : 2048;
64803
65293
  if (typeof modulusLength !== 'number' || modulusLength < 2048) {
64804
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used');
65294
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used');
64805
65295
  }
64806
65296
  return modulusLength;
64807
65297
  }
64808
65298
  async function generateKeyPair(alg, options) {
64809
- var _a, _b, _c, _d;
65299
+ var _a, _b, _c;
64810
65300
  let algorithm;
64811
65301
  let keyUsages;
64812
65302
  switch (alg) {
@@ -64865,7 +65355,7 @@ async function generateKeyPair(alg, options) {
64865
65355
  algorithm = { name: crv };
64866
65356
  break;
64867
65357
  default:
64868
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported crv option provided');
65358
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported crv option provided');
64869
65359
  }
64870
65360
  break;
64871
65361
  case 'ECDH-ES':
@@ -64886,25 +65376,14 @@ async function generateKeyPair(alg, options) {
64886
65376
  algorithm = { name: crv };
64887
65377
  break;
64888
65378
  default:
64889
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448');
65379
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448');
64890
65380
  }
64891
65381
  break;
64892
65382
  }
64893
65383
  default:
64894
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
64895
- }
64896
- try {
64897
- return (await _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.generateKey(algorithm, (_c = options === null || options === void 0 ? void 0 : options.extractable) !== null && _c !== void 0 ? _c : false, keyUsages));
64898
- }
64899
- catch (err) {
64900
- if (algorithm.name === 'Ed25519' &&
64901
- (err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
64902
- (0,_env_js__WEBPACK_IMPORTED_MODULE_0__.isCloudflareWorkers)()) {
64903
- algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
64904
- return (await _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.generateKey(algorithm, (_d = options === null || options === void 0 ? void 0 : options.extractable) !== null && _d !== void 0 ? _d : false, keyUsages));
64905
- }
64906
- throw err;
65384
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
64907
65385
  }
65386
+ return (_webcrypto_js__WEBPACK_IMPORTED_MODULE_0__["default"].subtle.generateKey(algorithm, (_c = options === null || options === void 0 ? void 0 : options.extractable) !== null && _c !== void 0 ? _c : false, keyUsages));
64908
65387
  }
64909
65388
 
64910
65389
 
@@ -64979,11 +65458,9 @@ __webpack_require__.r(__webpack_exports__);
64979
65458
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
64980
65459
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
64981
65460
  /* harmony export */ });
64982
- /* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./env.js */ "./node_modules/jose/dist/browser/runtime/env.js");
64983
- /* harmony import */ var _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./webcrypto.js */ "./node_modules/jose/dist/browser/runtime/webcrypto.js");
64984
- /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
64985
- /* harmony import */ var _base64url_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./base64url.js */ "./node_modules/jose/dist/browser/runtime/base64url.js");
64986
-
65461
+ /* harmony import */ var _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./webcrypto.js */ "./node_modules/jose/dist/browser/runtime/webcrypto.js");
65462
+ /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
65463
+ /* harmony import */ var _base64url_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./base64url.js */ "./node_modules/jose/dist/browser/runtime/base64url.js");
64987
65464
 
64988
65465
 
64989
65466
 
@@ -65002,7 +65479,7 @@ function subtleMapping(jwk) {
65002
65479
  case 'A128CBC-HS256':
65003
65480
  case 'A192CBC-HS384':
65004
65481
  case 'A256CBC-HS512':
65005
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported(`${jwk.alg} keys cannot be imported as CryptoKey instances`);
65482
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported(`${jwk.alg} keys cannot be imported as CryptoKey instances`);
65006
65483
  case 'A128GCM':
65007
65484
  case 'A192GCM':
65008
65485
  case 'A256GCM':
@@ -65025,7 +65502,7 @@ function subtleMapping(jwk) {
65025
65502
  keyUsages = ['deriveBits'];
65026
65503
  break;
65027
65504
  default:
65028
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65505
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65029
65506
  }
65030
65507
  break;
65031
65508
  }
@@ -65054,7 +65531,7 @@ function subtleMapping(jwk) {
65054
65531
  keyUsages = jwk.d ? ['decrypt', 'unwrapKey'] : ['encrypt', 'wrapKey'];
65055
65532
  break;
65056
65533
  default:
65057
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65534
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65058
65535
  }
65059
65536
  break;
65060
65537
  }
@@ -65080,7 +65557,7 @@ function subtleMapping(jwk) {
65080
65557
  keyUsages = jwk.d ? ['deriveBits'] : [];
65081
65558
  break;
65082
65559
  default:
65083
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65560
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65084
65561
  }
65085
65562
  break;
65086
65563
  }
@@ -65098,12 +65575,12 @@ function subtleMapping(jwk) {
65098
65575
  keyUsages = jwk.d ? ['deriveBits'] : [];
65099
65576
  break;
65100
65577
  default:
65101
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65578
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
65102
65579
  }
65103
65580
  break;
65104
65581
  }
65105
65582
  default:
65106
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_2__.JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
65583
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
65107
65584
  }
65108
65585
  return { algorithm, keyUsages };
65109
65586
  }
@@ -65119,23 +65596,12 @@ const parse = async (jwk) => {
65119
65596
  (_b = jwk.key_ops) !== null && _b !== void 0 ? _b : keyUsages,
65120
65597
  ];
65121
65598
  if (algorithm.name === 'PBKDF2') {
65122
- return _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.importKey('raw', (0,_base64url_js__WEBPACK_IMPORTED_MODULE_3__.decode)(jwk.k), ...rest);
65599
+ return _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__["default"].subtle.importKey('raw', (0,_base64url_js__WEBPACK_IMPORTED_MODULE_2__.decode)(jwk.k), ...rest);
65123
65600
  }
65124
65601
  const keyData = { ...jwk };
65125
65602
  delete keyData.alg;
65126
65603
  delete keyData.use;
65127
- try {
65128
- return await _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.importKey('jwk', keyData, ...rest);
65129
- }
65130
- catch (err) {
65131
- if (algorithm.name === 'Ed25519' &&
65132
- (err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
65133
- (0,_env_js__WEBPACK_IMPORTED_MODULE_0__.isCloudflareWorkers)()) {
65134
- rest[0] = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
65135
- return await _webcrypto_js__WEBPACK_IMPORTED_MODULE_1__["default"].subtle.importKey('jwk', keyData, ...rest);
65136
- }
65137
- throw err;
65138
- }
65604
+ return _webcrypto_js__WEBPACK_IMPORTED_MODULE_0__["default"].subtle.importKey('jwk', keyData, ...rest);
65139
65605
  };
65140
65606
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (parse);
65141
65607
 
@@ -65377,9 +65843,7 @@ __webpack_require__.r(__webpack_exports__);
65377
65843
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
65378
65844
  /* harmony export */ "default": () => (/* binding */ subtleDsa)
65379
65845
  /* harmony export */ });
65380
- /* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./env.js */ "./node_modules/jose/dist/browser/runtime/env.js");
65381
- /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
65382
-
65846
+ /* harmony import */ var _util_errors_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util/errors.js */ "./node_modules/jose/dist/browser/util/errors.js");
65383
65847
 
65384
65848
  function subtleDsa(alg, algorithm) {
65385
65849
  const hash = `SHA-${alg.slice(-3)}`;
@@ -65401,12 +65865,9 @@ function subtleDsa(alg, algorithm) {
65401
65865
  case 'ES512':
65402
65866
  return { hash, name: 'ECDSA', namedCurve: algorithm.namedCurve };
65403
65867
  case 'EdDSA':
65404
- if ((0,_env_js__WEBPACK_IMPORTED_MODULE_0__.isCloudflareWorkers)() && algorithm.name === 'NODE-ED25519') {
65405
- return { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
65406
- }
65407
65868
  return { name: algorithm.name };
65408
65869
  default:
65409
- throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_1__.JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
65870
+ throw new _util_errors_js__WEBPACK_IMPORTED_MODULE_0__.JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
65410
65871
  }
65411
65872
  }
65412
65873