@lifeready/core 1.1.15 → 1.1.17

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.
@@ -953,7 +953,7 @@
953
953
 
954
954
  var WebCryptoService = /** @class */ (function () {
955
955
  function WebCryptoService() {
956
- this.crypto = window.crypto;
956
+ this.kcCrypto = window.crypto;
957
957
  }
958
958
  WebCryptoService.prototype.toHex = function (buffer) {
959
959
  // Ref: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
@@ -969,7 +969,7 @@
969
969
  case 0:
970
970
  encoder = new TextEncoder();
971
971
  data = encoder.encode(message);
972
- return [4 /*yield*/, this.crypto.subtle.digest(algorithm, data)];
972
+ return [4 /*yield*/, this.kcCrypto.subtle.digest(algorithm, data)];
973
973
  case 1:
974
974
  hash = _a.sent();
975
975
  return [2 /*return*/, this.toHex(hash)];
@@ -986,25 +986,6 @@
986
986
  },] }
987
987
  ];
988
988
 
989
- function sha256(message) {
990
- return __awaiter(this, void 0, void 0, function () {
991
- var msgBuffer, hashBuffer, hashArray, hashHex;
992
- return __generator(this, function (_a) {
993
- switch (_a.label) {
994
- case 0:
995
- msgBuffer = new TextEncoder().encode(message);
996
- return [4 /*yield*/, crypto.subtle.digest('SHA-256', msgBuffer)];
997
- case 1:
998
- hashBuffer = _a.sent();
999
- hashArray = Array.from(new Uint8Array(hashBuffer));
1000
- hashHex = hashArray
1001
- .map(function (b) { return ('00' + b.toString(16)).slice(-2); })
1002
- .join('');
1003
- return [2 /*return*/, hashHex];
1004
- }
1005
- });
1006
- });
1007
- }
1008
989
  var KeyFactoryService = /** @class */ (function () {
1009
990
  function KeyFactoryService(webCryptoService) {
1010
991
  this.webCryptoService = webCryptoService;
@@ -1023,7 +1004,7 @@
1023
1004
  this.DEFAULT_PASS_IDP_PBKDF_ITER = this.MIN_PASS_IDP_PBKDF_ITER;
1024
1005
  this.DEFAULT_PASS_KEY_PBKDF_ITER = this.MIN_PASS_KEY_PBKDF_ITER;
1025
1006
  this.DEFAULT_LBOP_KEY_PBKDF_ITER = this.MIN_LBOP_KEY_PBKDF_ITER;
1026
- this.crypto = this.webCryptoService.crypto;
1007
+ this.kcCrypto = this.webCryptoService.kcCrypto;
1027
1008
  }
1028
1009
  KeyFactoryService.asKey = function (key, form, extras) {
1029
1010
  // <AZ> Using a single global key store did not seem to improve speed.
@@ -1036,7 +1017,7 @@
1036
1017
  }
1037
1018
  var validChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1038
1019
  var array = new Uint32Array(digits);
1039
- this.crypto.getRandomValues(array);
1020
+ this.kcCrypto.getRandomValues(array);
1040
1021
  array = array.map(function (x) { return validChars.charCodeAt(x % validChars.length); });
1041
1022
  return String.fromCharCode.apply(null, array);
1042
1023
  };
@@ -1051,7 +1032,7 @@
1051
1032
  throw new LrBadArgumentException('chooseN <= 0');
1052
1033
  }
1053
1034
  var values = new Uint32Array(chooseN);
1054
- this.crypto.getRandomValues(values);
1035
+ this.kcCrypto.getRandomValues(values);
1055
1036
  var ret = [];
1056
1037
  values.forEach(function (v) { return ret.push(array[v % array.length]); });
1057
1038
  return ret;
@@ -1064,7 +1045,7 @@
1064
1045
  var key, jwk;
1065
1046
  return __generator(this, function (_a) {
1066
1047
  switch (_a.label) {
1067
- case 0: return [4 /*yield*/, this.crypto.subtle.generateKey({
1048
+ case 0: return [4 /*yield*/, this.kcCrypto.subtle.generateKey({
1068
1049
  name: 'AES-GCM',
1069
1050
  length: 256,
1070
1051
  }, true, // whether the key is extractable (i.e. can be used in exportKey)
@@ -1072,7 +1053,7 @@
1072
1053
  )];
1073
1054
  case 1:
1074
1055
  key = _a.sent();
1075
- return [4 /*yield*/, this.crypto.subtle.exportKey('jwk', key)];
1056
+ return [4 /*yield*/, this.kcCrypto.subtle.exportKey('jwk', key)];
1076
1057
  case 2:
1077
1058
  jwk = _a.sent();
1078
1059
  // Removing the fields not needed by node-jose
@@ -1088,13 +1069,13 @@
1088
1069
  var key, jwk;
1089
1070
  return __generator(this, function (_a) {
1090
1071
  switch (_a.label) {
1091
- case 0: return [4 /*yield*/, this.crypto.subtle.generateKey({
1072
+ case 0: return [4 /*yield*/, this.kcCrypto.subtle.generateKey({
1092
1073
  name: 'HMAC',
1093
1074
  hash: { name: 'SHA-512' },
1094
1075
  }, true, ['sign', 'verify'])];
1095
1076
  case 1:
1096
1077
  key = _a.sent();
1097
- return [4 /*yield*/, this.crypto.subtle.exportKey('jwk', key)];
1078
+ return [4 /*yield*/, this.kcCrypto.subtle.exportKey('jwk', key)];
1098
1079
  case 2:
1099
1080
  jwk = _a.sent();
1100
1081
  // Removing the fields not needed by node-jose
@@ -1110,7 +1091,7 @@
1110
1091
  var key, jwk;
1111
1092
  return __generator(this, function (_a) {
1112
1093
  switch (_a.label) {
1113
- case 0: return [4 /*yield*/, this.crypto.subtle.generateKey({
1094
+ case 0: return [4 /*yield*/, this.kcCrypto.subtle.generateKey({
1114
1095
  name: 'RSA-OAEP',
1115
1096
  modulusLength: 2048,
1116
1097
  // As per suggestion: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams
@@ -1121,7 +1102,7 @@
1121
1102
  )];
1122
1103
  case 1:
1123
1104
  key = _a.sent();
1124
- return [4 /*yield*/, this.crypto.subtle.exportKey('jwk', key.privateKey)];
1105
+ return [4 /*yield*/, this.kcCrypto.subtle.exportKey('jwk', key.privateKey)];
1125
1106
  case 2:
1126
1107
  jwk = _a.sent();
1127
1108
  // Removing the fields not needed by node-jose
@@ -1137,7 +1118,7 @@
1137
1118
  var key, jwk;
1138
1119
  return __generator(this, function (_a) {
1139
1120
  switch (_a.label) {
1140
- case 0: return [4 /*yield*/, this.crypto.subtle.generateKey({
1121
+ case 0: return [4 /*yield*/, this.kcCrypto.subtle.generateKey({
1141
1122
  name: 'RSASSA-PKCS1-v1_5',
1142
1123
  modulusLength: 2048,
1143
1124
  // As per suggestion: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams
@@ -1148,7 +1129,7 @@
1148
1129
  )];
1149
1130
  case 1:
1150
1131
  key = _a.sent();
1151
- return [4 /*yield*/, this.crypto.subtle.exportKey('jwk', key.privateKey)];
1132
+ return [4 /*yield*/, this.kcCrypto.subtle.exportKey('jwk', key.privateKey)];
1152
1133
  case 2:
1153
1134
  jwk = _a.sent();
1154
1135
  // Removing the fields not needed by node-jose
@@ -1159,33 +1140,37 @@
1159
1140
  });
1160
1141
  });
1161
1142
  };
1143
+ KeyFactoryService.prototype.importPassword = function (plainPassword) {
1144
+ return __awaiter(this, void 0, void 0, function () {
1145
+ var enc;
1146
+ return __generator(this, function (_a) {
1147
+ enc = new TextEncoder();
1148
+ return [2 /*return*/, this.kcCrypto.subtle.importKey('raw', enc.encode(plainPassword), 'PBKDF2', false, ['deriveKey'])];
1149
+ });
1150
+ });
1151
+ };
1162
1152
  KeyFactoryService.prototype.deriveKey = function (_a) {
1163
1153
  var password = _a.password, salt = _a.salt, iterations = _a.iterations, kid = _a.kid;
1164
1154
  return __awaiter(this, void 0, void 0, function () {
1165
- var enc, rawKey, passKey, passKeyJson, jwk;
1155
+ var passKey, passKeyJson, jwk;
1166
1156
  return __generator(this, function (_a) {
1167
1157
  switch (_a.label) {
1168
- case 0:
1169
- enc = new TextEncoder();
1170
- return [4 /*yield*/, this.crypto.subtle.importKey('raw', enc.encode(password), 'PBKDF2', false, ['deriveBits', 'deriveKey'])];
1158
+ case 0: return [4 /*yield*/, this.kcCrypto.subtle.deriveKey({
1159
+ name: 'PBKDF2',
1160
+ salt: new TextEncoder().encode(salt),
1161
+ iterations: iterations,
1162
+ hash: 'SHA-256',
1163
+ }, password, { name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt'])];
1171
1164
  case 1:
1172
- rawKey = _a.sent();
1173
- return [4 /*yield*/, crypto.subtle.deriveKey({
1174
- name: 'PBKDF2',
1175
- salt: new TextEncoder().encode(salt),
1176
- iterations: iterations,
1177
- hash: 'SHA-256',
1178
- }, rawKey, { name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt'])];
1179
- case 2:
1180
1165
  passKey = _a.sent();
1181
- return [4 /*yield*/, crypto.subtle.exportKey('jwk', passKey)];
1182
- case 3:
1166
+ return [4 /*yield*/, this.kcCrypto.subtle.exportKey('jwk', passKey)];
1167
+ case 2:
1183
1168
  passKeyJson = _a.sent();
1184
1169
  if (kid) {
1185
1170
  passKeyJson.kid = kid;
1186
1171
  }
1187
1172
  return [4 /*yield*/, KeyFactoryService.asKey(passKeyJson)];
1188
- case 4:
1173
+ case 3:
1189
1174
  jwk = _a.sent();
1190
1175
  return [2 /*return*/, { jwk: jwk }];
1191
1176
  }
@@ -5049,30 +5034,30 @@
5049
5034
  this.idleService = idleService;
5050
5035
  this.CLIENT_NONCE_LENGTH = 32;
5051
5036
  }
5052
- PasswordService.prototype.checkPassword = function (password) {
5037
+ PasswordService.prototype.checkPassword = function (plainPassword) {
5053
5038
  return __awaiter(this, void 0, void 0, function () {
5054
5039
  var years, _a;
5055
5040
  return __generator(this, function (_b) {
5056
5041
  switch (_b.label) {
5057
5042
  case 0:
5058
- years = this.passwordStrength(password).years;
5043
+ years = this.passwordStrength(plainPassword).years;
5059
5044
  _a = {
5060
- length: password.length,
5045
+ length: plainPassword.length,
5061
5046
  timeToCrack: moment$1.duration({ years: years })
5062
5047
  };
5063
- return [4 /*yield*/, this.getExposureCount(password)];
5048
+ return [4 /*yield*/, this.getExposureCount(plainPassword)];
5064
5049
  case 1: return [2 /*return*/, (_a.passwordExposed = _b.sent(),
5065
5050
  _a)];
5066
5051
  }
5067
5052
  });
5068
5053
  });
5069
5054
  };
5070
- PasswordService.prototype.getExposureCount = function (password) {
5055
+ PasswordService.prototype.getExposureCount = function (plainPassword) {
5071
5056
  return __awaiter(this, void 0, void 0, function () {
5072
5057
  var sha1Password, first5sha1, response, results;
5073
5058
  return __generator(this, function (_a) {
5074
5059
  switch (_a.label) {
5075
- case 0: return [4 /*yield*/, this.webCryptoService.stringDigest('SHA-1', password)];
5060
+ case 0: return [4 /*yield*/, this.webCryptoService.stringDigest('SHA-1', plainPassword)];
5076
5061
  case 1:
5077
5062
  sha1Password = _a.sent();
5078
5063
  first5sha1 = sha1Password.substring(0, 5);
@@ -5424,6 +5409,10 @@
5424
5409
  { type: IdleService }
5425
5410
  ]; };
5426
5411
 
5412
+ var TP_PASSWORD_RESET_CLIENT_NONCE_LENGTH = 32;
5413
+ var TP_PASSWORD_RESET_SLIP39_PASSPHRASE = 'lifeready';
5414
+ var TP_PASSWORD_RESET_USERNAME_SUFFIX = '.tp_password_reset';
5415
+
5427
5416
  var SecretShare = /** @class */ (function () {
5428
5417
  function SecretShare(assembly, subAssembly, mnemonics) {
5429
5418
  if (assembly === void 0) { assembly = 0; }
@@ -5647,10 +5636,6 @@
5647
5636
  },] }
5648
5637
  ];
5649
5638
 
5650
- var TP_PASSWORD_RESET_CLIENT_NONCE_LENGTH = 32;
5651
- var TP_PASSWORD_RESET_SLIP39_PASSPHRASE = 'lifeready';
5652
- var TP_PASSWORD_RESET_USERNAME_SUFFIX = '.tp_password_reset';
5653
-
5654
5639
  var TpsKeysQuery = gqlTyped(templateObject_1$9 || (templateObject_1$9 = __makeTemplateObject(["\nquery TpsKeysQuery($ids: [ID]) {\n tps(id_In: $ids) {\n edges {\n node {\n id\n currentUserSharedKey {\n userSharedKey {\n sharedKey {\n id\n }\n mkSharedKey {\n id\n }\n }\n }\n }\n }\n }\n}"], ["\nquery TpsKeysQuery($ids: [ID]) {\n tps(id_In: $ids) {\n edges {\n node {\n id\n currentUserSharedKey {\n userSharedKey {\n sharedKey {\n id\n }\n mkSharedKey {\n id\n }\n }\n }\n }\n }\n }\n}"])));
5655
5640
  var templateObject_1$9;
5656
5641
 
@@ -6152,7 +6137,7 @@
6152
6137
  return TpAssemblyController;
6153
6138
  }());
6154
6139
 
6155
- exports.ɵj = /** @class */ (function (_super) {
6140
+ exports.ɵi = /** @class */ (function (_super) {
6156
6141
  __extends(TpPasswordResetAssemblyController, _super);
6157
6142
  function TpPasswordResetAssemblyController(ngZone, injector) {
6158
6143
  var _this = _super.call(this, injector) || this;
@@ -6166,21 +6151,21 @@
6166
6151
  };
6167
6152
  return TpPasswordResetAssemblyController;
6168
6153
  }(TpAssemblyController));
6169
- exports.ɵj.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetAssemblyController_Factory() { return new exports.ɵj(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR)); }, token: exports.ɵj, providedIn: "root" });
6170
- exports.ɵj.decorators = [
6154
+ exports.ɵi.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetAssemblyController_Factory() { return new exports.ɵi(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR)); }, token: exports.ɵi, providedIn: "root" });
6155
+ exports.ɵi.decorators = [
6171
6156
  { type: i0.Injectable, args: [{
6172
6157
  providedIn: 'root',
6173
6158
  },] }
6174
6159
  ];
6175
- exports.ɵj.ctorParameters = function () { return [
6160
+ exports.ɵi.ctorParameters = function () { return [
6176
6161
  { type: i0.NgZone },
6177
6162
  { type: i0.Injector }
6178
6163
  ]; };
6179
- exports.ɵj = __decorate([
6164
+ exports.ɵi = __decorate([
6180
6165
  RunOutsideAngular({
6181
6166
  ngZoneName: 'ngZone',
6182
6167
  })
6183
- ], exports.ɵj);
6168
+ ], exports.ɵi);
6184
6169
 
6185
6170
  var CancelTpPasswordResetRequestMutation = gqlTyped(templateObject_1$a || (templateObject_1$a = __makeTemplateObject(["\nmutation CancelTpPasswordResetRequestMutation {\n cancelTpPasswordResetRequest(input: {}) {\n id\n }\n}"], ["\nmutation CancelTpPasswordResetRequestMutation {\n cancelTpPasswordResetRequest(input: {}) {\n id\n }\n}"])));
6186
6171
  var CreateTpAssemblyKeyChallengeMutation = gqlTyped(templateObject_2$7 || (templateObject_2$7 = __makeTemplateObject(["\nmutation CreateTpAssemblyKeyChallengeMutation(\n $input: CreateTpAssemblyKeyChallengeInput!\n) {\n createTpAssemblyKeyChallenge(input: $input) {\n challenge\n }\n}"], ["\nmutation CreateTpAssemblyKeyChallengeMutation(\n $input: CreateTpAssemblyKeyChallengeInput!\n) {\n createTpAssemblyKeyChallenge(input: $input) {\n challenge\n }\n}"])));
@@ -6208,7 +6193,7 @@
6208
6193
  return function () { return authService.initialise(); };
6209
6194
  };
6210
6195
  var LifeReadyAuthService = /** @class */ (function () {
6211
- function LifeReadyAuthService(config, auth, keyFactory, keyService, profileService, keyGraphService, passwordService, idleService, lrGraphQL, tpPasswordResetProcessorService, persistService, encryptionService, slip39Service, assemblyController) {
6196
+ function LifeReadyAuthService(config, auth, keyFactory, keyService, profileService, keyGraphService, passwordService, idleService, lrGraphQL, tpPasswordResetProcessorService, persistService, encryptionService, assemblyController) {
6212
6197
  this.config = config;
6213
6198
  this.auth = auth;
6214
6199
  this.keyFactory = keyFactory;
@@ -6221,7 +6206,6 @@
6221
6206
  this.tpPasswordResetProcessorService = tpPasswordResetProcessorService;
6222
6207
  this.persistService = persistService;
6223
6208
  this.encryptionService = encryptionService;
6224
- this.slip39Service = slip39Service;
6225
6209
  this.assemblyController = assemblyController;
6226
6210
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6227
6211
  this.hubSubject = new rxjs.ReplaySubject(1);
@@ -6238,6 +6222,9 @@
6238
6222
  });
6239
6223
  });
6240
6224
  };
6225
+ LifeReadyAuthService.prototype.importPassword = function (plainPassword) {
6226
+ return this.keyFactory.importPassword(plainPassword);
6227
+ };
6241
6228
  LifeReadyAuthService.prototype.addLogoutListener = function (callback) {
6242
6229
  this.logoutListeners.add(callback);
6243
6230
  };
@@ -6858,7 +6845,7 @@
6858
6845
  };
6859
6846
  return LifeReadyAuthService;
6860
6847
  }());
6861
- LifeReadyAuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LifeReadyAuthService_Factory() { return new LifeReadyAuthService(i0.ɵɵinject(LR_CONFIG), i0.ɵɵinject(i4.AuthClass), i0.ɵɵinject(KeyFactoryService), i0.ɵɵinject(KeyService), i0.ɵɵinject(ProfileService), i0.ɵɵinject(KeyGraphService), i0.ɵɵinject(PasswordService), i0.ɵɵinject(IdleService), i0.ɵɵinject(exports.ɵf), i0.ɵɵinject(exports.ɵg), i0.ɵɵinject(PersistService), i0.ɵɵinject(EncryptionService), i0.ɵɵinject(Slip39Service), i0.ɵɵinject(exports.ɵj)); }, token: LifeReadyAuthService, providedIn: "root" });
6848
+ LifeReadyAuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LifeReadyAuthService_Factory() { return new LifeReadyAuthService(i0.ɵɵinject(LR_CONFIG), i0.ɵɵinject(i4.AuthClass), i0.ɵɵinject(KeyFactoryService), i0.ɵɵinject(KeyService), i0.ɵɵinject(ProfileService), i0.ɵɵinject(KeyGraphService), i0.ɵɵinject(PasswordService), i0.ɵɵinject(IdleService), i0.ɵɵinject(exports.ɵf), i0.ɵɵinject(exports.ɵg), i0.ɵɵinject(PersistService), i0.ɵɵinject(EncryptionService), i0.ɵɵinject(exports.ɵi)); }, token: LifeReadyAuthService, providedIn: "root" });
6862
6849
  LifeReadyAuthService.decorators = [
6863
6850
  { type: i0.Injectable, args: [{
6864
6851
  providedIn: 'root',
@@ -6877,8 +6864,7 @@
6877
6864
  { type: exports.ɵg },
6878
6865
  { type: PersistService },
6879
6866
  { type: EncryptionService },
6880
- { type: Slip39Service },
6881
- { type: exports.ɵj }
6867
+ { type: exports.ɵi }
6882
6868
  ]; };
6883
6869
 
6884
6870
  (function (FileType) {
@@ -10460,16 +10446,16 @@
10460
10446
  LbopService.prototype.create = function (_a) {
10461
10447
  var name = _a.name;
10462
10448
  return __awaiter(this, void 0, void 0, function () {
10463
- var lbops, lbopString, _loop_1, this_1, state_1, lbopKeyParams, lbopKey, lbopKeyVerifier, wrappedLbopKeyVerifier, currentUser, masterKey, wrappedMasterKey, meta, cipherMeta, res;
10464
- return __generator(this, function (_a) {
10465
- switch (_a.label) {
10449
+ var lbops, lbopString, _loop_1, this_1, state_1, lbopKeyParams, lbopKey, _a, _b, _c, _d, _e, lbopKeyVerifier, wrappedLbopKeyVerifier, currentUser, masterKey, wrappedMasterKey, meta, cipherMeta, res;
10450
+ return __generator(this, function (_f) {
10451
+ switch (_f.label) {
10466
10452
  case 0:
10467
10453
  if (slip39.Slip39Helper.WORD_LIST.length !== 1024) {
10468
10454
  throw new LrBadLogicException('Slip39Helper.WORD_LIST.length != 1024');
10469
10455
  }
10470
10456
  return [4 /*yield*/, this.list()];
10471
10457
  case 1:
10472
- lbops = _a.sent();
10458
+ lbops = _f.sent();
10473
10459
  _loop_1 = function () {
10474
10460
  lbopString = this_1.keyFactory
10475
10461
  .randomChoices(slip39.Slip39Helper.WORD_LIST, this_1.LBOP_WORDS)
@@ -10488,29 +10474,33 @@
10488
10474
  }
10489
10475
  return [4 /*yield*/, this.keyFactory.createLbopKeyParams()];
10490
10476
  case 2:
10491
- lbopKeyParams = _a.sent();
10492
- return [4 /*yield*/, this.keyFactory.deriveLbopKey(Object.assign({ password: lbopString }, lbopKeyParams))];
10493
- case 3:
10494
- lbopKey = (_a.sent()).jwk;
10495
- return [4 /*yield*/, this.keyFactory.createSignKey()];
10477
+ lbopKeyParams = _f.sent();
10478
+ _b = (_a = this.keyFactory).deriveLbopKey;
10479
+ _d = (_c = Object).assign;
10480
+ _e = {};
10481
+ return [4 /*yield*/, this.keyFactory.importPassword(lbopString)];
10482
+ case 3: return [4 /*yield*/, _b.apply(_a, [_d.apply(_c, [(_e.password = _f.sent(), _e), lbopKeyParams])])];
10496
10483
  case 4:
10497
- lbopKeyVerifier = _a.sent();
10498
- return [4 /*yield*/, this.encryptionService.encrypt(lbopKey, lbopKeyVerifier.toJSON(true))];
10484
+ lbopKey = (_f.sent()).jwk;
10485
+ return [4 /*yield*/, this.keyFactory.createSignKey()];
10499
10486
  case 5:
10500
- wrappedLbopKeyVerifier = _a.sent();
10501
- return [4 /*yield*/, this.authService.getUser()];
10487
+ lbopKeyVerifier = _f.sent();
10488
+ return [4 /*yield*/, this.encryptionService.encrypt(lbopKey, lbopKeyVerifier.toJSON(true))];
10502
10489
  case 6:
10503
- currentUser = _a.sent();
10504
- return [4 /*yield*/, this.keyGraph.getKey(currentUser.currentUserKey.masterKey.id)];
10490
+ wrappedLbopKeyVerifier = _f.sent();
10491
+ return [4 /*yield*/, this.authService.getUser()];
10505
10492
  case 7:
10506
- masterKey = _a.sent();
10507
- return [4 /*yield*/, this.encryptionService.encrypt(lbopKey, masterKey.jwk.toJSON(true))];
10493
+ currentUser = _f.sent();
10494
+ return [4 /*yield*/, this.keyGraph.getKey(currentUser.currentUserKey.masterKey.id)];
10508
10495
  case 8:
10509
- wrappedMasterKey = _a.sent();
10496
+ masterKey = _f.sent();
10497
+ return [4 /*yield*/, this.encryptionService.encrypt(lbopKey, masterKey.jwk.toJSON(true))];
10498
+ case 9:
10499
+ wrappedMasterKey = _f.sent();
10510
10500
  meta = Object.assign(Object.assign({}, (name && { name: name })), { partial: this.getPartial(lbopString) });
10511
10501
  return [4 /*yield*/, this.encryptionService.encrypt(masterKey.jwk, meta)];
10512
- case 9:
10513
- cipherMeta = _a.sent();
10502
+ case 10:
10503
+ cipherMeta = _f.sent();
10514
10504
  return [4 /*yield*/, this.lrApollo.mutate({
10515
10505
  mutation: CreateLbopQuery,
10516
10506
  variables: {
@@ -10524,8 +10514,8 @@
10524
10514
  },
10525
10515
  },
10526
10516
  })];
10527
- case 10:
10528
- res = _a.sent();
10517
+ case 11:
10518
+ res = _f.sent();
10529
10519
  return [2 /*return*/, Object.assign(Object.assign({}, res.createLbop.lbop), { lbopString: lbopString })];
10530
10520
  }
10531
10521
  });
@@ -10548,59 +10538,63 @@
10548
10538
  // --------------------------------------------------------------------------------------------------------------------
10549
10539
  LbopService.prototype.verifyLbops = function (challengeResult, lbopString) {
10550
10540
  return __awaiter(this, void 0, void 0, function () {
10551
- var clientNonce, _a, _b, lbop, lbopKey, lbopKeyVerifier, serverNonce, signedChallenge, error_1, e_1_1;
10552
- var e_1, _c;
10553
- return __generator(this, function (_d) {
10554
- switch (_d.label) {
10541
+ var clientNonce, _a, _b, lbop, lbopKey, _c, _d, _e, _f, _g, lbopKeyVerifier, serverNonce, signedChallenge, error_1, e_1_1;
10542
+ var e_1, _h;
10543
+ return __generator(this, function (_j) {
10544
+ switch (_j.label) {
10555
10545
  case 0:
10556
10546
  clientNonce = this.keyFactory.randomString(this.CLIENT_NONCE_LENGTH);
10557
- _d.label = 1;
10547
+ _j.label = 1;
10558
10548
  case 1:
10559
- _d.trys.push([1, 10, 11, 12]);
10549
+ _j.trys.push([1, 11, 12, 13]);
10560
10550
  _a = __values(challengeResult.lbops), _b = _a.next();
10561
- _d.label = 2;
10551
+ _j.label = 2;
10562
10552
  case 2:
10563
- if (!!_b.done) return [3 /*break*/, 9];
10553
+ if (!!_b.done) return [3 /*break*/, 10];
10564
10554
  lbop = _b.value;
10565
- return [4 /*yield*/, this.keyFactory.deriveLbopKey(Object.assign({ password: lbopString }, lbop.lbopKeyParams))];
10566
- case 3:
10567
- lbopKey = (_d.sent()).jwk;
10568
- _d.label = 4;
10555
+ _d = (_c = this.keyFactory).deriveLbopKey;
10556
+ _f = (_e = Object).assign;
10557
+ _g = {};
10558
+ return [4 /*yield*/, this.keyFactory.importPassword(lbopString)];
10559
+ case 3: return [4 /*yield*/, _d.apply(_c, [_f.apply(_e, [(_g.password = _j.sent(), _g), lbop.lbopKeyParams])])];
10569
10560
  case 4:
10570
- _d.trys.push([4, 7, , 8]);
10571
- return [4 /*yield*/, this.encryptionService.decrypt(lbopKey, lbop.wrappedLbopKeyVerifier)];
10561
+ lbopKey = (_j.sent()).jwk;
10562
+ _j.label = 5;
10572
10563
  case 5:
10573
- lbopKeyVerifier = (_d.sent());
10564
+ _j.trys.push([5, 8, , 9]);
10565
+ return [4 /*yield*/, this.encryptionService.decrypt(lbopKey, lbop.wrappedLbopKeyVerifier)];
10566
+ case 6:
10567
+ lbopKeyVerifier = (_j.sent());
10574
10568
  serverNonce = challengeResult.challenge.serverNonce;
10575
10569
  return [4 /*yield*/, this.encryptionService.sign(lbopKeyVerifier, {
10576
10570
  serverNonce: serverNonce,
10577
10571
  clientNonce: clientNonce,
10578
10572
  })];
10579
- case 6:
10580
- signedChallenge = _d.sent();
10573
+ case 7:
10574
+ signedChallenge = _j.sent();
10581
10575
  return [2 /*return*/, {
10582
10576
  lbop: lbop,
10583
10577
  signedChallenge: signedChallenge,
10584
10578
  lbopKey: lbopKey,
10585
10579
  }];
10586
- case 7:
10587
- error_1 = _d.sent();
10588
- return [3 /*break*/, 8];
10589
10580
  case 8:
10581
+ error_1 = _j.sent();
10582
+ return [3 /*break*/, 9];
10583
+ case 9:
10590
10584
  _b = _a.next();
10591
10585
  return [3 /*break*/, 2];
10592
- case 9: return [3 /*break*/, 12];
10593
- case 10:
10594
- e_1_1 = _d.sent();
10595
- e_1 = { error: e_1_1 };
10596
- return [3 /*break*/, 12];
10586
+ case 10: return [3 /*break*/, 13];
10597
10587
  case 11:
10588
+ e_1_1 = _j.sent();
10589
+ e_1 = { error: e_1_1 };
10590
+ return [3 /*break*/, 13];
10591
+ case 12:
10598
10592
  try {
10599
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
10593
+ if (_b && !_b.done && (_h = _a.return)) _h.call(_a);
10600
10594
  }
10601
10595
  finally { if (e_1) throw e_1.error; }
10602
10596
  return [7 /*endfinally*/];
10603
- case 12: throw new LrException({
10597
+ case 13: throw new LrException({
10604
10598
  source: 'LBOP',
10605
10599
  code: 'INVALID_PASSPHRASE',
10606
10600
  message: 'Invalid passphrase.',
@@ -12866,7 +12860,7 @@
12866
12860
 
12867
12861
  var SCENARIO_SLIP39_PASSPHRASE = 'lifeready';
12868
12862
 
12869
- exports.ɵo = /** @class */ (function (_super) {
12863
+ exports.ɵn = /** @class */ (function (_super) {
12870
12864
  __extends(ScenarioAssemblyController, _super);
12871
12865
  function ScenarioAssemblyController(ngZone, injector) {
12872
12866
  var _this = _super.call(this, injector) || this;
@@ -12880,21 +12874,21 @@
12880
12874
  };
12881
12875
  return ScenarioAssemblyController;
12882
12876
  }(TpAssemblyController));
12883
- exports.ɵo.ɵprov = i0.ɵɵdefineInjectable({ factory: function ScenarioAssemblyController_Factory() { return new exports.ɵo(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR)); }, token: exports.ɵo, providedIn: "root" });
12884
- exports.ɵo.decorators = [
12877
+ exports.ɵn.ɵprov = i0.ɵɵdefineInjectable({ factory: function ScenarioAssemblyController_Factory() { return new exports.ɵn(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR)); }, token: exports.ɵn, providedIn: "root" });
12878
+ exports.ɵn.decorators = [
12885
12879
  { type: i0.Injectable, args: [{
12886
12880
  providedIn: 'root',
12887
12881
  },] }
12888
12882
  ];
12889
- exports.ɵo.ctorParameters = function () { return [
12883
+ exports.ɵn.ctorParameters = function () { return [
12890
12884
  { type: i0.NgZone },
12891
12885
  { type: i0.Injector }
12892
12886
  ]; };
12893
- exports.ɵo = __decorate([
12887
+ exports.ɵn = __decorate([
12894
12888
  RunOutsideAngular({
12895
12889
  ngZoneName: 'ngZone',
12896
12890
  })
12897
- ], exports.ɵo);
12891
+ ], exports.ɵn);
12898
12892
 
12899
12893
  var CreateScenarioMutation = gqlTyped(templateObject_1$q || (templateObject_1$q = __makeTemplateObject(["\nmutation CreateScenarioMutation($input: CreateScenarioInput!) {\n createScenario(input: $input) {\n scenario {\n id\n }\n }\n}\n"], ["\nmutation CreateScenarioMutation($input: CreateScenarioInput!) {\n createScenario(input: $input) {\n scenario {\n id\n }\n }\n}\n"])));
12900
12894
  var UpdateScenarioMutation = gqlTyped(templateObject_2$m || (templateObject_2$m = __makeTemplateObject(["\nmutation UpdateScenarioMutation($input: UpdateScenarioInput!) {\n updateScenario(input: $input) {\n scenario {\n id\n }\n }\n}\n"], ["\nmutation UpdateScenarioMutation($input: UpdateScenarioInput!) {\n updateScenario(input: $input) {\n scenario {\n id\n }\n }\n}\n"])));
@@ -13736,7 +13730,7 @@
13736
13730
  return ScenarioService;
13737
13731
  }(LrService));
13738
13732
  exports.ScenarioService.SLIP39_PASSPHRASE = 'lifeready';
13739
- exports.ScenarioService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ScenarioService_Factory() { return new exports.ScenarioService(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(KeyGraphService), i0.ɵɵinject(exports.Item2Service), i0.ɵɵinject(exports.ɵo), i0.ɵɵinject(EncryptionService)); }, token: exports.ScenarioService, providedIn: "root" });
13733
+ exports.ScenarioService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ScenarioService_Factory() { return new exports.ScenarioService(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(KeyGraphService), i0.ɵɵinject(exports.Item2Service), i0.ɵɵinject(exports.ɵn), i0.ɵɵinject(EncryptionService)); }, token: exports.ScenarioService, providedIn: "root" });
13740
13734
  exports.ScenarioService.decorators = [
13741
13735
  { type: i0.Injectable, args: [{
13742
13736
  providedIn: 'root',
@@ -13747,7 +13741,7 @@
13747
13741
  { type: i0.Injector },
13748
13742
  { type: KeyGraphService },
13749
13743
  { type: exports.Item2Service },
13750
- { type: exports.ɵo },
13744
+ { type: exports.ɵn },
13751
13745
  { type: EncryptionService }
13752
13746
  ]; };
13753
13747
  exports.ScenarioService = __decorate([
@@ -13966,7 +13960,7 @@
13966
13960
  })
13967
13961
  ], exports.SharedContactCard2Service);
13968
13962
 
13969
- exports.ɵp = /** @class */ (function (_super) {
13963
+ exports.ɵo = /** @class */ (function (_super) {
13970
13964
  __extends(TpPasswordResetPrivateService, _super);
13971
13965
  function TpPasswordResetPrivateService(ngZone, injector) {
13972
13966
  var _this = _super.call(this, injector) || this;
@@ -14015,21 +14009,21 @@
14015
14009
  };
14016
14010
  return TpPasswordResetPrivateService;
14017
14011
  }(LrService));
14018
- exports.ɵp.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetPrivateService_Factory() { return new exports.ɵp(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR)); }, token: exports.ɵp, providedIn: "root" });
14019
- exports.ɵp.decorators = [
14012
+ exports.ɵo.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetPrivateService_Factory() { return new exports.ɵo(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR)); }, token: exports.ɵo, providedIn: "root" });
14013
+ exports.ɵo.decorators = [
14020
14014
  { type: i0.Injectable, args: [{
14021
14015
  providedIn: 'root',
14022
14016
  },] }
14023
14017
  ];
14024
- exports.ɵp.ctorParameters = function () { return [
14018
+ exports.ɵo.ctorParameters = function () { return [
14025
14019
  { type: i0.NgZone },
14026
14020
  { type: i0.Injector }
14027
14021
  ]; };
14028
- exports.ɵp = __decorate([
14022
+ exports.ɵo = __decorate([
14029
14023
  RunOutsideAngular({
14030
14024
  ngZoneName: 'ngZone',
14031
14025
  })
14032
- ], exports.ɵp);
14026
+ ], exports.ɵo);
14033
14027
 
14034
14028
  exports.TpPasswordResetRequestService = /** @class */ (function (_super) {
14035
14029
  __extends(TpPasswordResetRequestService, _super);
@@ -14145,7 +14139,7 @@
14145
14139
  };
14146
14140
  return TpPasswordResetRequestService;
14147
14141
  }(LrService));
14148
- exports.TpPasswordResetRequestService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetRequestService_Factory() { return new exports.TpPasswordResetRequestService(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(EncryptionService), i0.ɵɵinject(exports.ɵp)); }, token: exports.TpPasswordResetRequestService, providedIn: "root" });
14142
+ exports.TpPasswordResetRequestService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetRequestService_Factory() { return new exports.TpPasswordResetRequestService(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(EncryptionService), i0.ɵɵinject(exports.ɵo)); }, token: exports.TpPasswordResetRequestService, providedIn: "root" });
14149
14143
  exports.TpPasswordResetRequestService.decorators = [
14150
14144
  { type: i0.Injectable, args: [{
14151
14145
  providedIn: 'root',
@@ -14155,7 +14149,7 @@
14155
14149
  { type: i0.NgZone },
14156
14150
  { type: i0.Injector },
14157
14151
  { type: EncryptionService },
14158
- { type: exports.ɵp }
14152
+ { type: exports.ɵo }
14159
14153
  ]; };
14160
14154
  exports.TpPasswordResetRequestService = __decorate([
14161
14155
  RunOutsideAngular({
@@ -14163,6 +14157,33 @@
14163
14157
  })
14164
14158
  ], exports.TpPasswordResetRequestService);
14165
14159
 
14160
+ var COGNITO_LOCALSTORAGE_PREFIX = 'CognitoIdentityServiceProvider';
14161
+ /**
14162
+ * Remove all keys in localstorage with matching prefix.
14163
+ * A prefix must be specified. If you want to remove everything, then just use localStorage.clear().
14164
+ *
14165
+ * @param prefix Keys with this prefix will be removed.
14166
+ */
14167
+ function clearLocalStorage(prefix) {
14168
+ if (!prefix) {
14169
+ throw new LrBadArgumentException('You must specify a non empty prefix.');
14170
+ }
14171
+ // Remove all persisted session variables
14172
+ Object.keys(localStorage).forEach(function (key) {
14173
+ if (key.startsWith(prefix)) {
14174
+ localStorage.removeItem(key);
14175
+ }
14176
+ });
14177
+ }
14178
+ /**
14179
+ * Clear all items related to cognito in localstorage.
14180
+ * The remember device function sometimes interferes with creating new users
14181
+ * on TP based password reset.
14182
+ */
14183
+ function clearCognitoLocalStorage() {
14184
+ clearLocalStorage(COGNITO_LOCALSTORAGE_PREFIX);
14185
+ }
14186
+
14166
14187
  exports.TpPasswordResetUserService = /** @class */ (function (_super) {
14167
14188
  __extends(TpPasswordResetUserService, _super);
14168
14189
  function TpPasswordResetUserService(ngZone, injector, config, keyFactory, encryptionService, passwordService, http, auth) {
@@ -14214,7 +14235,11 @@
14214
14235
  var passKeyBundle, masterKey, wrappedMasterKey, prk, masterKeyWrappedPrk, requestResetResult, signUpResult;
14215
14236
  return __generator(this, function (_a) {
14216
14237
  switch (_a.label) {
14217
- case 0: return [4 /*yield*/, this.passwordService.createPassKeyBundle(password)];
14238
+ case 0:
14239
+ // Clearing all localstorage data because cognito has the "remember device" functionality which sometimes
14240
+ // does not work properly. Clearing localstorage seems to solve this issue.
14241
+ clearCognitoLocalStorage();
14242
+ return [4 /*yield*/, this.passwordService.createPassKeyBundle(password)];
14218
14243
  case 1:
14219
14244
  passKeyBundle = _a.sent();
14220
14245
  return [4 /*yield*/, this.keyFactory.createKey()];
@@ -14390,7 +14415,7 @@
14390
14415
  };
14391
14416
  return TpPasswordResetService;
14392
14417
  }(LrService));
14393
- exports.TpPasswordResetService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetService_Factory() { return new exports.TpPasswordResetService(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(exports.ɵp), i0.ɵɵinject(exports.ɵj)); }, token: exports.TpPasswordResetService, providedIn: "root" });
14418
+ exports.TpPasswordResetService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TpPasswordResetService_Factory() { return new exports.TpPasswordResetService(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(exports.ɵo), i0.ɵɵinject(exports.ɵi)); }, token: exports.TpPasswordResetService, providedIn: "root" });
14394
14419
  exports.TpPasswordResetService.decorators = [
14395
14420
  { type: i0.Injectable, args: [{
14396
14421
  providedIn: 'root',
@@ -14399,8 +14424,8 @@
14399
14424
  exports.TpPasswordResetService.ctorParameters = function () { return [
14400
14425
  { type: i0.NgZone },
14401
14426
  { type: i0.Injector },
14402
- { type: exports.ɵp },
14403
- { type: exports.ɵj }
14427
+ { type: exports.ɵo },
14428
+ { type: exports.ɵi }
14404
14429
  ]; };
14405
14430
  exports.TpPasswordResetService = __decorate([
14406
14431
  RunOutsideAngular({
@@ -15026,11 +15051,10 @@
15026
15051
  exports.ɵd = KeyFactoryService;
15027
15052
  exports.ɵe = KeyMetaService;
15028
15053
  exports.ɵh = RunOutsideAngular;
15029
- exports.ɵi = Slip39Service;
15030
- exports.ɵk = TpAssemblyController;
15031
- exports.ɵl = LrService;
15032
- exports.ɵm = SharedContactCardService;
15033
- exports.ɵn = TrustedPartyService;
15054
+ exports.ɵj = TpAssemblyController;
15055
+ exports.ɵk = LrService;
15056
+ exports.ɵl = SharedContactCardService;
15057
+ exports.ɵm = TrustedPartyService;
15034
15058
 
15035
15059
  Object.defineProperty(exports, '__esModule', { value: true });
15036
15060