cozy-keys-lib 3.9.1 → 4.1.0

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.
@@ -36,6 +36,8 @@ import { CipherType } from './@bitwarden/jslib/enums/cipherType';
36
36
  import { KdfType } from './@bitwarden/jslib/enums/kdfType';
37
37
  import { ImportCiphersRequest } from './@bitwarden/jslib/models/request/importCiphersRequest';
38
38
  import { CipherRequest } from './@bitwarden/jslib/models/request/cipherRequest';
39
+ import { CipherString } from './@bitwarden/jslib/models/domain/cipherString';
40
+ import { SymmetricCryptoKey } from './@bitwarden/jslib/models/domain/symmetricCryptoKey';
39
41
  import { KdfRequest } from './@bitwarden/jslib/models/request/kdfRequest';
40
42
  import WebPlatformUtilsService from './WebPlatformUtilsService';
41
43
  import HtmlStorageService from './HtmlStorageService';
@@ -764,6 +766,68 @@ function () {
764
766
 
765
767
  return getMasterKey;
766
768
  }()
769
+ /**
770
+ * @typedef EncryptionKey
771
+ * @property {SymmetricCryptoKey} key - The encryption key
772
+ * @property {CipherString} encryptedKey - The encrypted key
773
+ *
774
+ * Generate a new encryption key
775
+ * @return {EncryptionKey} the generated key and its encrypted version
776
+ */
777
+
778
+ }, {
779
+ key: "generateEncryptionKey",
780
+ value: function () {
781
+ var _generateEncryptionKey = _asyncToGenerator(
782
+ /*#__PURE__*/
783
+ _regeneratorRuntime.mark(function _callee13() {
784
+ var encKey, _ref6, _ref7, key, encryptedKey;
785
+
786
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
787
+ while (1) {
788
+ switch (_context13.prev = _context13.next) {
789
+ case 0:
790
+ _context13.next = 2;
791
+ return this.getEncryptionKey();
792
+
793
+ case 2:
794
+ encKey = _context13.sent;
795
+
796
+ if (encKey) {
797
+ _context13.next = 5;
798
+ break;
799
+ }
800
+
801
+ throw new Error('NO_ENCRYPTION_KEY');
802
+
803
+ case 5:
804
+ _context13.next = 7;
805
+ return this.cryptoService.makeEncKey(encKey);
806
+
807
+ case 7:
808
+ _ref6 = _context13.sent;
809
+ _ref7 = _slicedToArray(_ref6, 2);
810
+ key = _ref7[0];
811
+ encryptedKey = _ref7[1];
812
+ return _context13.abrupt("return", {
813
+ key: key,
814
+ encryptedKey: encryptedKey
815
+ });
816
+
817
+ case 12:
818
+ case "end":
819
+ return _context13.stop();
820
+ }
821
+ }
822
+ }, _callee13, this);
823
+ }));
824
+
825
+ function generateEncryptionKey() {
826
+ return _generateEncryptionKey.apply(this, arguments);
827
+ }
828
+
829
+ return generateEncryptionKey;
830
+ }()
767
831
  /**
768
832
  * Manually encrypt the encryption key
769
833
  * Usefull for a password change, with a new master key
@@ -777,44 +841,44 @@ function () {
777
841
  value: function () {
778
842
  var _encryptEncryptionKey = _asyncToGenerator(
779
843
  /*#__PURE__*/
780
- _regeneratorRuntime.mark(function _callee13(encryptionKey, masterKey) {
781
- var key, toEncrypt, _ref6, _ref7, encrypted;
844
+ _regeneratorRuntime.mark(function _callee14(encryptionKey, masterKey) {
845
+ var key, toEncrypt, _ref8, _ref9, encrypted;
782
846
 
783
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
847
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
784
848
  while (1) {
785
- switch (_context13.prev = _context13.next) {
849
+ switch (_context14.prev = _context14.next) {
786
850
  case 0:
787
- _context13.t0 = masterKey;
851
+ _context14.t0 = masterKey;
788
852
 
789
- if (_context13.t0) {
790
- _context13.next = 5;
853
+ if (_context14.t0) {
854
+ _context14.next = 5;
791
855
  break;
792
856
  }
793
857
 
794
- _context13.next = 4;
858
+ _context14.next = 4;
795
859
  return this.getMasterKey();
796
860
 
797
861
  case 4:
798
- _context13.t0 = _context13.sent;
862
+ _context14.t0 = _context14.sent;
799
863
 
800
864
  case 5:
801
- key = _context13.t0;
865
+ key = _context14.t0;
802
866
  toEncrypt = encryptionKey.key;
803
- _context13.next = 9;
867
+ _context14.next = 9;
804
868
  return this.cryptoService.buildEncKey(key, toEncrypt);
805
869
 
806
870
  case 9:
807
- _ref6 = _context13.sent;
808
- _ref7 = _slicedToArray(_ref6, 2);
809
- encrypted = _ref7[1];
810
- return _context13.abrupt("return", encrypted);
871
+ _ref8 = _context14.sent;
872
+ _ref9 = _slicedToArray(_ref8, 2);
873
+ encrypted = _ref9[1];
874
+ return _context14.abrupt("return", encrypted);
811
875
 
812
876
  case 13:
813
877
  case "end":
814
- return _context13.stop();
878
+ return _context14.stop();
815
879
  }
816
880
  }
817
- }, _callee13, this);
881
+ }, _callee14, this);
818
882
  }));
819
883
 
820
884
  function encryptEncryptionKey(_x22, _x23) {
@@ -835,59 +899,59 @@ function () {
835
899
  value: function () {
836
900
  var _unlock = _asyncToGenerator(
837
901
  /*#__PURE__*/
838
- _regeneratorRuntime.mark(function _callee14(masterPassword) {
902
+ _regeneratorRuntime.mark(function _callee15(masterPassword) {
839
903
  var isAuthed, kdf, kdfIterations, storedKeyHash, key, keyHash;
840
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
904
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
841
905
  while (1) {
842
- switch (_context14.prev = _context14.next) {
906
+ switch (_context15.prev = _context15.next) {
843
907
  case 0:
844
- _context14.next = 2;
908
+ _context15.next = 2;
845
909
  return this.initFinished;
846
910
 
847
911
  case 2:
848
- _context14.next = 4;
912
+ _context15.next = 4;
849
913
  return this.userService.isAuthenticated();
850
914
 
851
915
  case 4:
852
- isAuthed = _context14.sent;
916
+ isAuthed = _context15.sent;
853
917
  kdf = this.cryptoService.kdf;
854
918
  kdfIterations = this.cryptoService.kdfIterations;
855
- _context14.next = 9;
919
+ _context15.next = 9;
856
920
  return this.cryptoService.getKeyHash();
857
921
 
858
922
  case 9:
859
- storedKeyHash = _context14.sent;
923
+ storedKeyHash = _context15.sent;
860
924
 
861
925
  if (!(!isAuthed || !kdf || !storedKeyHash)) {
862
- _context14.next = 15;
926
+ _context15.next = 15;
863
927
  break;
864
928
  }
865
929
 
866
- _context14.next = 13;
930
+ _context15.next = 13;
867
931
  return this.login(masterPassword);
868
932
 
869
933
  case 13:
870
- _context14.next = 25;
934
+ _context15.next = 25;
871
935
  break;
872
936
 
873
937
  case 15:
874
- _context14.next = 17;
938
+ _context15.next = 17;
875
939
  return this.cryptoService.makeKey(masterPassword, this.email, kdf, kdfIterations);
876
940
 
877
941
  case 17:
878
- key = _context14.sent;
879
- _context14.next = 20;
942
+ key = _context15.sent;
943
+ _context15.next = 20;
880
944
  return this.cryptoService.hashPassword(this.masterPassword, key);
881
945
 
882
946
  case 20:
883
- keyHash = _context14.sent;
947
+ keyHash = _context15.sent;
884
948
 
885
949
  if (!(storedKeyHash == keyHash)) {
886
- _context14.next = 24;
950
+ _context15.next = 24;
887
951
  break;
888
952
  }
889
953
 
890
- _context14.next = 24;
954
+ _context15.next = 24;
891
955
  return this.cryptoService.setKey(key);
892
956
 
893
957
  case 24:
@@ -896,14 +960,14 @@ function () {
896
960
  case 25:
897
961
  this.sync();
898
962
  this.emit('unlock', this);
899
- return _context14.abrupt("return", true);
963
+ return _context15.abrupt("return", true);
900
964
 
901
965
  case 28:
902
966
  case "end":
903
- return _context14.stop();
967
+ return _context15.stop();
904
968
  }
905
969
  }
906
- }, _callee14, this);
970
+ }, _callee15, this);
907
971
  }));
908
972
 
909
973
  function unlock(_x24) {
@@ -923,30 +987,30 @@ function () {
923
987
  value: function () {
924
988
  var _sync = _asyncToGenerator(
925
989
  /*#__PURE__*/
926
- _regeneratorRuntime.mark(function _callee15() {
990
+ _regeneratorRuntime.mark(function _callee16() {
927
991
  var sync;
928
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
992
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
929
993
  while (1) {
930
- switch (_context15.prev = _context15.next) {
994
+ switch (_context16.prev = _context16.next) {
931
995
  case 0:
932
- _context15.next = 2;
996
+ _context16.next = 2;
933
997
  return this.initFinished;
934
998
 
935
999
  case 2:
936
- _context15.next = 4;
1000
+ _context16.next = 4;
937
1001
  return this.syncService.fullSync();
938
1002
 
939
1003
  case 4:
940
- sync = _context15.sent;
1004
+ sync = _context16.sent;
941
1005
  this.emit('sync', this);
942
- return _context15.abrupt("return", sync);
1006
+ return _context16.abrupt("return", sync);
943
1007
 
944
1008
  case 7:
945
1009
  case "end":
946
- return _context15.stop();
1010
+ return _context16.stop();
947
1011
  }
948
1012
  }
949
- }, _callee15, this);
1013
+ }, _callee16, this);
950
1014
  }));
951
1015
 
952
1016
  function sync() {
@@ -968,32 +1032,32 @@ function () {
968
1032
  value: function () {
969
1033
  var _getAll = _asyncToGenerator(
970
1034
  /*#__PURE__*/
971
- _regeneratorRuntime.mark(function _callee16() {
972
- var _ref8,
1035
+ _regeneratorRuntime.mark(function _callee17() {
1036
+ var _ref10,
973
1037
  type,
974
1038
  all,
975
- _args16 = arguments;
1039
+ _args17 = arguments;
976
1040
 
977
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1041
+ return _regeneratorRuntime.wrap(function _callee17$(_context17) {
978
1042
  while (1) {
979
- switch (_context16.prev = _context16.next) {
1043
+ switch (_context17.prev = _context17.next) {
980
1044
  case 0:
981
- _ref8 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, type = _ref8.type;
982
- _context16.next = 3;
1045
+ _ref10 = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : {}, type = _ref10.type;
1046
+ _context17.next = 3;
983
1047
  return this.cipherService.getAll();
984
1048
 
985
1049
  case 3:
986
- all = _context16.sent;
987
- return _context16.abrupt("return", type ? all.filter(function (cipher) {
1050
+ all = _context17.sent;
1051
+ return _context17.abrupt("return", type ? all.filter(function (cipher) {
988
1052
  return cipher.type == type;
989
1053
  }) : all);
990
1054
 
991
1055
  case 5:
992
1056
  case "end":
993
- return _context16.stop();
1057
+ return _context17.stop();
994
1058
  }
995
1059
  }
996
- }, _callee16, this);
1060
+ }, _callee17, this);
997
1061
  }));
998
1062
 
999
1063
  function getAll() {
@@ -1012,21 +1076,21 @@ function () {
1012
1076
  value: function () {
1013
1077
  var _getAllLogins = _asyncToGenerator(
1014
1078
  /*#__PURE__*/
1015
- _regeneratorRuntime.mark(function _callee17() {
1016
- return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1079
+ _regeneratorRuntime.mark(function _callee18() {
1080
+ return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1017
1081
  while (1) {
1018
- switch (_context17.prev = _context17.next) {
1082
+ switch (_context18.prev = _context18.next) {
1019
1083
  case 0:
1020
- return _context17.abrupt("return", this.getAll({
1084
+ return _context18.abrupt("return", this.getAll({
1021
1085
  type: CipherType.Login
1022
1086
  }));
1023
1087
 
1024
1088
  case 1:
1025
1089
  case "end":
1026
- return _context17.stop();
1090
+ return _context18.stop();
1027
1091
  }
1028
1092
  }
1029
- }, _callee17, this);
1093
+ }, _callee18, this);
1030
1094
  }));
1031
1095
 
1032
1096
  function getAllLogins() {
@@ -1035,39 +1099,6 @@ function () {
1035
1099
 
1036
1100
  return getAllLogins;
1037
1101
  }()
1038
- /**
1039
- * Decrypt a cipher
1040
- * @param {Cipher} cipher
1041
- * @return {CipherView} decrypted cipher
1042
- */
1043
-
1044
- }, {
1045
- key: "decrypt",
1046
- value: function () {
1047
- var _decrypt = _asyncToGenerator(
1048
- /*#__PURE__*/
1049
- _regeneratorRuntime.mark(function _callee18(cipher) {
1050
- return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1051
- while (1) {
1052
- switch (_context18.prev = _context18.next) {
1053
- case 0:
1054
- this.attachToGlobal();
1055
- return _context18.abrupt("return", cipher.decrypt());
1056
-
1057
- case 2:
1058
- case "end":
1059
- return _context18.stop();
1060
- }
1061
- }
1062
- }, _callee18, this);
1063
- }));
1064
-
1065
- function decrypt(_x25) {
1066
- return _decrypt.apply(this, arguments);
1067
- }
1068
-
1069
- return decrypt;
1070
- }()
1071
1102
  /**
1072
1103
  * Get all data from the local vault and decrypt them
1073
1104
  *
@@ -1088,7 +1119,7 @@ function () {
1088
1119
  _regeneratorRuntime.mark(function _callee19() {
1089
1120
  var _this2 = this;
1090
1121
 
1091
- var _ref9,
1122
+ var _ref11,
1092
1123
  type,
1093
1124
  uri,
1094
1125
  all,
@@ -1099,7 +1130,7 @@ function () {
1099
1130
  while (1) {
1100
1131
  switch (_context19.prev = _context19.next) {
1101
1132
  case 0:
1102
- _ref9 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, type = _ref9.type, uri = _ref9.uri;
1133
+ _ref11 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, type = _ref11.type, uri = _ref11.uri;
1103
1134
  this.attachToGlobal();
1104
1135
 
1105
1136
  if (!uri) {
@@ -1190,7 +1221,7 @@ function () {
1190
1221
  value: function () {
1191
1222
  var _getAllDecryptedFor = _asyncToGenerator(
1192
1223
  /*#__PURE__*/
1193
- _regeneratorRuntime.mark(function _callee21(_ref10) {
1224
+ _regeneratorRuntime.mark(function _callee21(_ref12) {
1194
1225
  var _this3 = this;
1195
1226
 
1196
1227
  var type, uri, username, name, all;
@@ -1198,7 +1229,7 @@ function () {
1198
1229
  while (1) {
1199
1230
  switch (_context21.prev = _context21.next) {
1200
1231
  case 0:
1201
- type = _ref10.type, uri = _ref10.uri, username = _ref10.username, name = _ref10.name;
1232
+ type = _ref12.type, uri = _ref12.uri, username = _ref12.username, name = _ref12.name;
1202
1233
  _context21.next = 3;
1203
1234
  return this.getAllDecrypted({
1204
1235
  type: type,
@@ -1228,7 +1259,7 @@ function () {
1228
1259
  }, _callee21, this);
1229
1260
  }));
1230
1261
 
1231
- function getAllDecryptedFor(_x26) {
1262
+ function getAllDecryptedFor(_x25) {
1232
1263
  return _getAllDecryptedFor.apply(this, arguments);
1233
1264
  }
1234
1265
 
@@ -1317,7 +1348,7 @@ function () {
1317
1348
  }, _callee22, this);
1318
1349
  }));
1319
1350
 
1320
- function getByIdOrSearch(_x27, _x28, _x29) {
1351
+ function getByIdOrSearch(_x26, _x27, _x28) {
1321
1352
  return _getByIdOrSearch.apply(this, arguments);
1322
1353
  }
1323
1354
 
@@ -1375,7 +1406,7 @@ function () {
1375
1406
  }, _callee23, this);
1376
1407
  }));
1377
1408
 
1378
- function get(_x30) {
1409
+ function get(_x29) {
1379
1410
  return _get.apply(this, arguments);
1380
1411
  }
1381
1412
 
@@ -1462,30 +1493,32 @@ function () {
1462
1493
  }, _callee25, this);
1463
1494
  }));
1464
1495
 
1465
- function encrypt(_x31) {
1496
+ function encrypt(_x30) {
1466
1497
  return _encrypt.apply(this, arguments);
1467
1498
  }
1468
1499
 
1469
1500
  return encrypt;
1470
1501
  }()
1471
1502
  /**
1472
- * Save a new or modified (encrypted) cipher to the server
1473
- * @param {Cipher} - cipher to save
1503
+ * Decrypt a cipher
1504
+ * @param {Cipher} cipher
1505
+ * @return {CipherView} decrypted cipher
1474
1506
  */
1475
1507
 
1476
1508
  }, {
1477
- key: "saveCipher",
1509
+ key: "decrypt",
1478
1510
  value: function () {
1479
- var _saveCipher = _asyncToGenerator(
1511
+ var _decrypt = _asyncToGenerator(
1480
1512
  /*#__PURE__*/
1481
1513
  _regeneratorRuntime.mark(function _callee26(cipher) {
1482
1514
  return _regeneratorRuntime.wrap(function _callee26$(_context26) {
1483
1515
  while (1) {
1484
1516
  switch (_context26.prev = _context26.next) {
1485
1517
  case 0:
1486
- return _context26.abrupt("return", this.cipherService.saveWithServer(cipher));
1518
+ this.attachToGlobal();
1519
+ return _context26.abrupt("return", cipher.decrypt());
1487
1520
 
1488
- case 1:
1521
+ case 2:
1489
1522
  case "end":
1490
1523
  return _context26.stop();
1491
1524
  }
@@ -1493,7 +1526,171 @@ function () {
1493
1526
  }, _callee26, this);
1494
1527
  }));
1495
1528
 
1496
- function saveCipher(_x32) {
1529
+ function decrypt(_x31) {
1530
+ return _decrypt.apply(this, arguments);
1531
+ }
1532
+
1533
+ return decrypt;
1534
+ }()
1535
+ /**
1536
+ * Decrypt an encryption key, encrypted with the vault encryption key
1537
+ * @param {string} encryptedKey - The string-encoded encrypted key
1538
+ * @return {SymmetricCryptoKey} The encryption key
1539
+ */
1540
+
1541
+ }, {
1542
+ key: "decryptEncryptionKey",
1543
+ value: function () {
1544
+ var _decryptEncryptionKey = _asyncToGenerator(
1545
+ /*#__PURE__*/
1546
+ _regeneratorRuntime.mark(function _callee27(encryptedKey) {
1547
+ var encKey, cipher, decryptedBuffer;
1548
+ return _regeneratorRuntime.wrap(function _callee27$(_context27) {
1549
+ while (1) {
1550
+ switch (_context27.prev = _context27.next) {
1551
+ case 0:
1552
+ _context27.next = 2;
1553
+ return this.getEncryptionKey();
1554
+
1555
+ case 2:
1556
+ encKey = _context27.sent;
1557
+
1558
+ if (encKey) {
1559
+ _context27.next = 5;
1560
+ break;
1561
+ }
1562
+
1563
+ throw new Error('NO_ENCRYPTION_KEY');
1564
+
1565
+ case 5:
1566
+ cipher = new CipherString(encryptedKey);
1567
+ _context27.next = 8;
1568
+ return this.cryptoService.decryptToBytes(cipher, encKey);
1569
+
1570
+ case 8:
1571
+ decryptedBuffer = _context27.sent;
1572
+ return _context27.abrupt("return", new SymmetricCryptoKey(decryptedBuffer));
1573
+
1574
+ case 10:
1575
+ case "end":
1576
+ return _context27.stop();
1577
+ }
1578
+ }
1579
+ }, _callee27, this);
1580
+ }));
1581
+
1582
+ function decryptEncryptionKey(_x32) {
1583
+ return _decryptEncryptionKey.apply(this, arguments);
1584
+ }
1585
+
1586
+ return decryptEncryptionKey;
1587
+ }()
1588
+ /**
1589
+ * Encrypt a file
1590
+ * @param {ArrayBuffer} file - file to encrypt
1591
+ * @param {string} encryptedKey - the encrypted encryption key
1592
+ * @return {ArrayBuffer} encrypted file
1593
+ */
1594
+
1595
+ }, {
1596
+ key: "encryptFile",
1597
+ value: function () {
1598
+ var _encryptFile = _asyncToGenerator(
1599
+ /*#__PURE__*/
1600
+ _regeneratorRuntime.mark(function _callee28(file, encryptedKey) {
1601
+ var encryptionKey;
1602
+ return _regeneratorRuntime.wrap(function _callee28$(_context28) {
1603
+ while (1) {
1604
+ switch (_context28.prev = _context28.next) {
1605
+ case 0:
1606
+ this.attachToGlobal();
1607
+ _context28.next = 3;
1608
+ return this.decryptEncryptionKey(encryptedKey);
1609
+
1610
+ case 3:
1611
+ encryptionKey = _context28.sent;
1612
+ return _context28.abrupt("return", this.cryptoService.encryptToBytes(file, encryptionKey));
1613
+
1614
+ case 5:
1615
+ case "end":
1616
+ return _context28.stop();
1617
+ }
1618
+ }
1619
+ }, _callee28, this);
1620
+ }));
1621
+
1622
+ function encryptFile(_x33, _x34) {
1623
+ return _encryptFile.apply(this, arguments);
1624
+ }
1625
+
1626
+ return encryptFile;
1627
+ }()
1628
+ /**
1629
+ * Decrypt a file
1630
+ * @param {ArrayBuffer} encryptedFile - encrypted file
1631
+ * @param {string} encryptedKey - the encrypted decryption key
1632
+ * @return {ArrayBuffer} decrypted file
1633
+ */
1634
+
1635
+ }, {
1636
+ key: "decryptFile",
1637
+ value: function () {
1638
+ var _decryptFile = _asyncToGenerator(
1639
+ /*#__PURE__*/
1640
+ _regeneratorRuntime.mark(function _callee29(encryptedFile, encryptedKey) {
1641
+ var decryptionKey;
1642
+ return _regeneratorRuntime.wrap(function _callee29$(_context29) {
1643
+ while (1) {
1644
+ switch (_context29.prev = _context29.next) {
1645
+ case 0:
1646
+ this.attachToGlobal();
1647
+ _context29.next = 3;
1648
+ return this.decryptEncryptionKey(encryptedKey);
1649
+
1650
+ case 3:
1651
+ decryptionKey = _context29.sent;
1652
+ return _context29.abrupt("return", this.cryptoService.decryptFromBytes(encryptedFile, decryptionKey));
1653
+
1654
+ case 5:
1655
+ case "end":
1656
+ return _context29.stop();
1657
+ }
1658
+ }
1659
+ }, _callee29, this);
1660
+ }));
1661
+
1662
+ function decryptFile(_x35, _x36) {
1663
+ return _decryptFile.apply(this, arguments);
1664
+ }
1665
+
1666
+ return decryptFile;
1667
+ }()
1668
+ /**
1669
+ * Save a new or modified (encrypted) cipher to the server
1670
+ * @param {Cipher} - cipher to save
1671
+ */
1672
+
1673
+ }, {
1674
+ key: "saveCipher",
1675
+ value: function () {
1676
+ var _saveCipher = _asyncToGenerator(
1677
+ /*#__PURE__*/
1678
+ _regeneratorRuntime.mark(function _callee30(cipher) {
1679
+ return _regeneratorRuntime.wrap(function _callee30$(_context30) {
1680
+ while (1) {
1681
+ switch (_context30.prev = _context30.next) {
1682
+ case 0:
1683
+ return _context30.abrupt("return", this.cipherService.saveWithServer(cipher));
1684
+
1685
+ case 1:
1686
+ case "end":
1687
+ return _context30.stop();
1688
+ }
1689
+ }
1690
+ }, _callee30, this);
1691
+ }));
1692
+
1693
+ function saveCipher(_x37) {
1497
1694
  return _saveCipher.apply(this, arguments);
1498
1695
  }
1499
1696
 
@@ -1509,19 +1706,19 @@ function () {
1509
1706
  value: function () {
1510
1707
  var _postImportCiphers = _asyncToGenerator(
1511
1708
  /*#__PURE__*/
1512
- _regeneratorRuntime.mark(function _callee27(encryptedCiphersToSave) {
1709
+ _regeneratorRuntime.mark(function _callee31(encryptedCiphersToSave) {
1513
1710
  var _groupBy, _groupBy$true, existingCiphersToSave, _groupBy$false, newCiphersToSave, req, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, existingCipherToSave;
1514
1711
 
1515
- return _regeneratorRuntime.wrap(function _callee27$(_context27) {
1712
+ return _regeneratorRuntime.wrap(function _callee31$(_context31) {
1516
1713
  while (1) {
1517
- switch (_context27.prev = _context27.next) {
1714
+ switch (_context31.prev = _context31.next) {
1518
1715
  case 0:
1519
1716
  _groupBy = groupBy(encryptedCiphersToSave, function (x) {
1520
1717
  return Boolean(x.id);
1521
1718
  }), _groupBy$true = _groupBy.true, existingCiphersToSave = _groupBy$true === void 0 ? [] : _groupBy$true, _groupBy$false = _groupBy.false, newCiphersToSave = _groupBy$false === void 0 ? [] : _groupBy$false;
1522
1719
 
1523
1720
  if (!(newCiphersToSave.length > 0)) {
1524
- _context27.next = 7;
1721
+ _context31.next = 7;
1525
1722
  break;
1526
1723
  }
1527
1724
 
@@ -1531,12 +1728,12 @@ function () {
1531
1728
  var cipherReq = new CipherRequest(cipher);
1532
1729
  req.ciphers.push(cipherReq);
1533
1730
  });
1534
- _context27.next = 7;
1731
+ _context31.next = 7;
1535
1732
  return this.apiService.postImportCiphers(req);
1536
1733
 
1537
1734
  case 7:
1538
1735
  if (!(existingCiphersToSave.length > 0)) {
1539
- _context27.next = 35;
1736
+ _context31.next = 35;
1540
1737
  break;
1541
1738
  }
1542
1739
 
@@ -1544,73 +1741,73 @@ function () {
1544
1741
  _iteratorNormalCompletion = true;
1545
1742
  _didIteratorError = false;
1546
1743
  _iteratorError = undefined;
1547
- _context27.prev = 12;
1744
+ _context31.prev = 12;
1548
1745
  _iterator = existingCiphersToSave[Symbol.iterator]();
1549
1746
 
1550
1747
  case 14:
1551
1748
  if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
1552
- _context27.next = 21;
1749
+ _context31.next = 21;
1553
1750
  break;
1554
1751
  }
1555
1752
 
1556
1753
  existingCipherToSave = _step.value;
1557
- _context27.next = 18;
1754
+ _context31.next = 18;
1558
1755
  return this.saveCipher(existingCipherToSave);
1559
1756
 
1560
1757
  case 18:
1561
1758
  _iteratorNormalCompletion = true;
1562
- _context27.next = 14;
1759
+ _context31.next = 14;
1563
1760
  break;
1564
1761
 
1565
1762
  case 21:
1566
- _context27.next = 27;
1763
+ _context31.next = 27;
1567
1764
  break;
1568
1765
 
1569
1766
  case 23:
1570
- _context27.prev = 23;
1571
- _context27.t0 = _context27["catch"](12);
1767
+ _context31.prev = 23;
1768
+ _context31.t0 = _context31["catch"](12);
1572
1769
  _didIteratorError = true;
1573
- _iteratorError = _context27.t0;
1770
+ _iteratorError = _context31.t0;
1574
1771
 
1575
1772
  case 27:
1576
- _context27.prev = 27;
1577
- _context27.prev = 28;
1773
+ _context31.prev = 27;
1774
+ _context31.prev = 28;
1578
1775
 
1579
1776
  if (!_iteratorNormalCompletion && _iterator.return != null) {
1580
1777
  _iterator.return();
1581
1778
  }
1582
1779
 
1583
1780
  case 30:
1584
- _context27.prev = 30;
1781
+ _context31.prev = 30;
1585
1782
 
1586
1783
  if (!_didIteratorError) {
1587
- _context27.next = 33;
1784
+ _context31.next = 33;
1588
1785
  break;
1589
1786
  }
1590
1787
 
1591
1788
  throw _iteratorError;
1592
1789
 
1593
1790
  case 33:
1594
- return _context27.finish(30);
1791
+ return _context31.finish(30);
1595
1792
 
1596
1793
  case 34:
1597
- return _context27.finish(27);
1794
+ return _context31.finish(27);
1598
1795
 
1599
1796
  case 35:
1600
- return _context27.abrupt("return", {
1797
+ return _context31.abrupt("return", {
1601
1798
  nbNewCiphers: newCiphersToSave.length,
1602
1799
  nbUpdatedCiphers: existingCiphersToSave.length
1603
1800
  });
1604
1801
 
1605
1802
  case 36:
1606
1803
  case "end":
1607
- return _context27.stop();
1804
+ return _context31.stop();
1608
1805
  }
1609
1806
  }
1610
- }, _callee27, this, [[12, 23, 27, 35], [28,, 30, 34]]);
1807
+ }, _callee31, this, [[12, 23, 27, 35], [28,, 30, 34]]);
1611
1808
  }));
1612
1809
 
1613
- function postImportCiphers(_x33) {
1810
+ function postImportCiphers(_x38) {
1614
1811
  return _postImportCiphers.apply(this, arguments);
1615
1812
  }
1616
1813
 
@@ -1626,24 +1823,24 @@ function () {
1626
1823
  value: function () {
1627
1824
  var _deleteCipher = _asyncToGenerator(
1628
1825
  /*#__PURE__*/
1629
- _regeneratorRuntime.mark(function _callee28(id) {
1826
+ _regeneratorRuntime.mark(function _callee32(id) {
1630
1827
  var realId;
1631
- return _regeneratorRuntime.wrap(function _callee28$(_context28) {
1828
+ return _regeneratorRuntime.wrap(function _callee32$(_context32) {
1632
1829
  while (1) {
1633
- switch (_context28.prev = _context28.next) {
1830
+ switch (_context32.prev = _context32.next) {
1634
1831
  case 0:
1635
1832
  realId = id.id ? id.id : id;
1636
- return _context28.abrupt("return", this.cipherService.deleteWithServer(realId));
1833
+ return _context32.abrupt("return", this.cipherService.deleteWithServer(realId));
1637
1834
 
1638
1835
  case 2:
1639
1836
  case "end":
1640
- return _context28.stop();
1837
+ return _context32.stop();
1641
1838
  }
1642
1839
  }
1643
- }, _callee28, this);
1840
+ }, _callee32, this);
1644
1841
  }));
1645
1842
 
1646
- function deleteCipher(_x34) {
1843
+ function deleteCipher(_x39) {
1647
1844
  return _deleteCipher.apply(this, arguments);
1648
1845
  }
1649
1846
 
@@ -1660,46 +1857,46 @@ function () {
1660
1857
  value: function () {
1661
1858
  var _shareWithCozy = _asyncToGenerator(
1662
1859
  /*#__PURE__*/
1663
- _regeneratorRuntime.mark(function _callee29(cipherView) {
1860
+ _regeneratorRuntime.mark(function _callee33(cipherView) {
1664
1861
  var org, cols, colIds;
1665
- return _regeneratorRuntime.wrap(function _callee29$(_context29) {
1862
+ return _regeneratorRuntime.wrap(function _callee33$(_context33) {
1666
1863
  while (1) {
1667
- switch (_context29.prev = _context29.next) {
1864
+ switch (_context33.prev = _context33.next) {
1668
1865
  case 0:
1669
1866
  this.attachToGlobal();
1670
- _context29.next = 3;
1867
+ _context33.next = 3;
1671
1868
  return this.getCozyOrg();
1672
1869
 
1673
1870
  case 3:
1674
- org = _context29.sent;
1871
+ org = _context33.sent;
1675
1872
 
1676
1873
  if (!(cipherView.organizationId != org.id)) {
1677
- _context29.next = 12;
1874
+ _context33.next = 12;
1678
1875
  break;
1679
1876
  }
1680
1877
 
1681
- _context29.next = 7;
1878
+ _context33.next = 7;
1682
1879
  return this.getCollectionsForOrg(org);
1683
1880
 
1684
1881
  case 7:
1685
- cols = _context29.sent;
1882
+ cols = _context33.sent;
1686
1883
  colIds = cols.map(function (col) {
1687
1884
  return col.id;
1688
1885
  });
1689
- return _context29.abrupt("return", this.cipherService.shareWithServer(cipherView, org.id, colIds));
1886
+ return _context33.abrupt("return", this.cipherService.shareWithServer(cipherView, org.id, colIds));
1690
1887
 
1691
1888
  case 12:
1692
- return _context29.abrupt("return", undefined);
1889
+ return _context33.abrupt("return", undefined);
1693
1890
 
1694
1891
  case 13:
1695
1892
  case "end":
1696
- return _context29.stop();
1893
+ return _context33.stop();
1697
1894
  }
1698
1895
  }
1699
- }, _callee29, this);
1896
+ }, _callee33, this);
1700
1897
  }));
1701
1898
 
1702
- function shareWithCozy(_x35) {
1899
+ function shareWithCozy(_x40) {
1703
1900
  return _shareWithCozy.apply(this, arguments);
1704
1901
  }
1705
1902
 
@@ -1717,31 +1914,31 @@ function () {
1717
1914
  value: function () {
1718
1915
  var _getCollectionsForOrg = _asyncToGenerator(
1719
1916
  /*#__PURE__*/
1720
- _regeneratorRuntime.mark(function _callee30(org) {
1917
+ _regeneratorRuntime.mark(function _callee34(org) {
1721
1918
  var id, collections;
1722
- return _regeneratorRuntime.wrap(function _callee30$(_context30) {
1919
+ return _regeneratorRuntime.wrap(function _callee34$(_context34) {
1723
1920
  while (1) {
1724
- switch (_context30.prev = _context30.next) {
1921
+ switch (_context34.prev = _context34.next) {
1725
1922
  case 0:
1726
1923
  id = org.id ? org.id : org;
1727
- _context30.next = 3;
1924
+ _context34.next = 3;
1728
1925
  return this.collectionService.getAll();
1729
1926
 
1730
1927
  case 3:
1731
- collections = _context30.sent;
1732
- return _context30.abrupt("return", collections.filter(function (col) {
1928
+ collections = _context34.sent;
1929
+ return _context34.abrupt("return", collections.filter(function (col) {
1733
1930
  return col.organizationId === id;
1734
1931
  }));
1735
1932
 
1736
1933
  case 5:
1737
1934
  case "end":
1738
- return _context30.stop();
1935
+ return _context34.stop();
1739
1936
  }
1740
1937
  }
1741
- }, _callee30, this);
1938
+ }, _callee34, this);
1742
1939
  }));
1743
1940
 
1744
- function getCollectionsForOrg(_x36) {
1941
+ function getCollectionsForOrg(_x41) {
1745
1942
  return _getCollectionsForOrg.apply(this, arguments);
1746
1943
  }
1747
1944
 
@@ -1758,27 +1955,27 @@ function () {
1758
1955
  value: function () {
1759
1956
  var _getCozyOrg = _asyncToGenerator(
1760
1957
  /*#__PURE__*/
1761
- _regeneratorRuntime.mark(function _callee31() {
1958
+ _regeneratorRuntime.mark(function _callee35() {
1762
1959
  var orgs;
1763
- return _regeneratorRuntime.wrap(function _callee31$(_context31) {
1960
+ return _regeneratorRuntime.wrap(function _callee35$(_context35) {
1764
1961
  while (1) {
1765
- switch (_context31.prev = _context31.next) {
1962
+ switch (_context35.prev = _context35.next) {
1766
1963
  case 0:
1767
- _context31.next = 2;
1964
+ _context35.next = 2;
1768
1965
  return this.userService.getAllOrganizations();
1769
1966
 
1770
1967
  case 2:
1771
- orgs = _context31.sent;
1772
- return _context31.abrupt("return", orgs.filter(function (org) {
1968
+ orgs = _context35.sent;
1969
+ return _context35.abrupt("return", orgs.filter(function (org) {
1773
1970
  return org.name.match(/^cozy\b/i);
1774
1971
  })[0]);
1775
1972
 
1776
1973
  case 4:
1777
1974
  case "end":
1778
- return _context31.stop();
1975
+ return _context35.stop();
1779
1976
  }
1780
1977
  }
1781
- }, _callee31, this);
1978
+ }, _callee35, this);
1782
1979
  }));
1783
1980
 
1784
1981
  function getCozyOrg() {
@@ -1804,34 +2001,34 @@ function () {
1804
2001
  value: function () {
1805
2002
  var _createOrUpdateCipher = _asyncToGenerator(
1806
2003
  /*#__PURE__*/
1807
- _regeneratorRuntime.mark(function _callee32(decryptedData) {
2004
+ _regeneratorRuntime.mark(function _callee36(decryptedData) {
1808
2005
  var originalCipher,
1809
2006
  orgId,
1810
2007
  key,
1811
- _args32 = arguments;
1812
- return _regeneratorRuntime.wrap(function _callee32$(_context32) {
2008
+ _args36 = arguments;
2009
+ return _regeneratorRuntime.wrap(function _callee36$(_context36) {
1813
2010
  while (1) {
1814
- switch (_context32.prev = _context32.next) {
2011
+ switch (_context36.prev = _context36.next) {
1815
2012
  case 0:
1816
- originalCipher = _args32.length > 1 && _args32[1] !== undefined ? _args32[1] : null;
2013
+ originalCipher = _args36.length > 1 && _args36[1] !== undefined ? _args36[1] : null;
1817
2014
  this.attachToGlobal();
1818
2015
  orgId = decryptedData.organizationId;
1819
- _context32.next = 5;
2016
+ _context36.next = 5;
1820
2017
  return orgId ? this.cryptoService.getOrgKey(orgId) : this.cryptoService.getEncKey();
1821
2018
 
1822
2019
  case 5:
1823
- key = _context32.sent;
1824
- return _context32.abrupt("return", this.cipherService.encrypt(decryptedData, key, originalCipher));
2020
+ key = _context36.sent;
2021
+ return _context36.abrupt("return", this.cipherService.encrypt(decryptedData, key, originalCipher));
1825
2022
 
1826
2023
  case 7:
1827
2024
  case "end":
1828
- return _context32.stop();
2025
+ return _context36.stop();
1829
2026
  }
1830
2027
  }
1831
- }, _callee32, this);
2028
+ }, _callee36, this);
1832
2029
  }));
1833
2030
 
1834
- function createOrUpdateCipher(_x37) {
2031
+ function createOrUpdateCipher(_x42) {
1835
2032
  return _createOrUpdateCipher.apply(this, arguments);
1836
2033
  }
1837
2034
 
@@ -1848,43 +2045,43 @@ function () {
1848
2045
  value: function () {
1849
2046
  var _createNewCozySharedCipher = _asyncToGenerator(
1850
2047
  /*#__PURE__*/
1851
- _regeneratorRuntime.mark(function _callee33(decryptedData) {
2048
+ _regeneratorRuntime.mark(function _callee37(decryptedData) {
1852
2049
  var originalCipher,
1853
2050
  org,
1854
2051
  cols,
1855
2052
  colIds,
1856
- _args33 = arguments;
1857
- return _regeneratorRuntime.wrap(function _callee33$(_context33) {
2053
+ _args37 = arguments;
2054
+ return _regeneratorRuntime.wrap(function _callee37$(_context37) {
1858
2055
  while (1) {
1859
- switch (_context33.prev = _context33.next) {
2056
+ switch (_context37.prev = _context37.next) {
1860
2057
  case 0:
1861
- originalCipher = _args33.length > 1 && _args33[1] !== undefined ? _args33[1] : null;
1862
- _context33.next = 3;
2058
+ originalCipher = _args37.length > 1 && _args37[1] !== undefined ? _args37[1] : null;
2059
+ _context37.next = 3;
1863
2060
  return this.getCozyOrg();
1864
2061
 
1865
2062
  case 3:
1866
- org = _context33.sent;
1867
- _context33.next = 6;
2063
+ org = _context37.sent;
2064
+ _context37.next = 6;
1868
2065
  return this.getCollectionsForOrg(org);
1869
2066
 
1870
2067
  case 6:
1871
- cols = _context33.sent;
2068
+ cols = _context37.sent;
1872
2069
  colIds = cols.map(function (col) {
1873
2070
  return col.id;
1874
2071
  });
1875
2072
  decryptedData.organizationId = org.id;
1876
2073
  decryptedData.collectionIds = colIds;
1877
- return _context33.abrupt("return", this.createOrUpdateCipher(decryptedData, originalCipher));
2074
+ return _context37.abrupt("return", this.createOrUpdateCipher(decryptedData, originalCipher));
1878
2075
 
1879
2076
  case 11:
1880
2077
  case "end":
1881
- return _context33.stop();
2078
+ return _context37.stop();
1882
2079
  }
1883
2080
  }
1884
- }, _callee33, this);
2081
+ }, _callee37, this);
1885
2082
  }));
1886
2083
 
1887
- function createNewCozySharedCipher(_x38) {
2084
+ function createNewCozySharedCipher(_x43) {
1888
2085
  return _createNewCozySharedCipher.apply(this, arguments);
1889
2086
  }
1890
2087
 
@@ -1918,32 +2115,32 @@ function () {
1918
2115
  value: function () {
1919
2116
  var _import2 = _asyncToGenerator(
1920
2117
  /*#__PURE__*/
1921
- _regeneratorRuntime.mark(function _callee34(fileContent, format) {
2118
+ _regeneratorRuntime.mark(function _callee38(fileContent, format) {
1922
2119
  var _this5 = this;
1923
2120
 
1924
2121
  var importer, parseResult, supportedCiphers, ciphersToSave, postImportRes;
1925
- return _regeneratorRuntime.wrap(function _callee34$(_context34) {
2122
+ return _regeneratorRuntime.wrap(function _callee38$(_context38) {
1926
2123
  while (1) {
1927
- switch (_context34.prev = _context34.next) {
2124
+ switch (_context38.prev = _context38.next) {
1928
2125
  case 0:
1929
2126
  importer = this.importService.getImporter(format, false);
1930
2127
 
1931
2128
  if (importer) {
1932
- _context34.next = 3;
2129
+ _context38.next = 3;
1933
2130
  break;
1934
2131
  }
1935
2132
 
1936
2133
  throw new Error('IMPORT_UNKNOWN_FORMAT');
1937
2134
 
1938
2135
  case 3:
1939
- _context34.next = 5;
2136
+ _context38.next = 5;
1940
2137
  return importer.parse(fileContent);
1941
2138
 
1942
2139
  case 5:
1943
- parseResult = _context34.sent;
2140
+ parseResult = _context38.sent;
1944
2141
 
1945
2142
  if (parseResult.success) {
1946
- _context34.next = 8;
2143
+ _context38.next = 8;
1947
2144
  break;
1948
2145
  }
1949
2146
 
@@ -1959,32 +2156,32 @@ function () {
1959
2156
  });
1960
2157
  logger.info("Parsed ".concat(parseResult.ciphers.length));
1961
2158
  logger.info("Importing ".concat(supportedCiphers.length, " supported ciphers"));
1962
- _context34.next = 14;
2159
+ _context38.next = 14;
1963
2160
  return Promise.all(supportedCiphers.map(function (cipher) {
1964
2161
  return _this5.prepareCipherToImport(cipher);
1965
2162
  }));
1966
2163
 
1967
2164
  case 14:
1968
- ciphersToSave = _context34.sent;
1969
- _context34.next = 17;
2165
+ ciphersToSave = _context38.sent;
2166
+ _context38.next = 17;
1970
2167
  return this.postImportCiphers(ciphersToSave);
1971
2168
 
1972
2169
  case 17:
1973
- postImportRes = _context34.sent;
1974
- return _context34.abrupt("return", _objectSpread({}, postImportRes, {
2170
+ postImportRes = _context38.sent;
2171
+ return _context38.abrupt("return", _objectSpread({}, postImportRes, {
1975
2172
  nbParsedCiphers: parseResult.ciphers.length,
1976
2173
  nbSupportedCiphers: supportedCiphers.length
1977
2174
  }));
1978
2175
 
1979
2176
  case 19:
1980
2177
  case "end":
1981
- return _context34.stop();
2178
+ return _context38.stop();
1982
2179
  }
1983
2180
  }
1984
- }, _callee34, this);
2181
+ }, _callee38, this);
1985
2182
  }));
1986
2183
 
1987
- function _import(_x39, _x40) {
2184
+ function _import(_x44, _x45) {
1988
2185
  return _import2.apply(this, arguments);
1989
2186
  }
1990
2187
 
@@ -1995,12 +2192,12 @@ function () {
1995
2192
  value: function () {
1996
2193
  var _searchExistingCipher = _asyncToGenerator(
1997
2194
  /*#__PURE__*/
1998
- _regeneratorRuntime.mark(function _callee35(cipher) {
2195
+ _regeneratorRuntime.mark(function _callee39(cipher) {
1999
2196
  var encryptedExistingCipher, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, uri, search, sort, decrypted;
2000
2197
 
2001
- return _regeneratorRuntime.wrap(function _callee35$(_context35) {
2198
+ return _regeneratorRuntime.wrap(function _callee39$(_context39) {
2002
2199
  while (1) {
2003
- switch (_context35.prev = _context35.next) {
2200
+ switch (_context39.prev = _context39.next) {
2004
2201
  case 0:
2005
2202
  // Since we search existing cipher by username, password and URI; and a
2006
2203
  // cipher being imported can have multiple URIs, we have to look for an
@@ -2009,12 +2206,12 @@ function () {
2009
2206
  _iteratorNormalCompletion2 = true;
2010
2207
  _didIteratorError2 = false;
2011
2208
  _iteratorError2 = undefined;
2012
- _context35.prev = 3;
2209
+ _context39.prev = 3;
2013
2210
  _iterator2 = cipher.login.uris[Symbol.iterator]();
2014
2211
 
2015
2212
  case 5:
2016
2213
  if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
2017
- _context35.next = 27;
2214
+ _context39.next = 27;
2018
2215
  break;
2019
2216
  }
2020
2217
 
@@ -2028,83 +2225,83 @@ function () {
2028
2225
  sort = [function (cipherView) {
2029
2226
  return cipherView.login.password === cipher.login.password ? 0 : 1;
2030
2227
  }, 'revisionDate'];
2031
- _context35.next = 12;
2228
+ _context39.next = 12;
2032
2229
  return this.getByIdOrSearch(null, search, sort);
2033
2230
 
2034
2231
  case 12:
2035
- encryptedExistingCipher = _context35.sent;
2232
+ encryptedExistingCipher = _context39.sent;
2036
2233
  logger.debug('Found potential matching cipher', encryptedExistingCipher);
2037
2234
 
2038
2235
  if (!encryptedExistingCipher) {
2039
- _context35.next = 24;
2236
+ _context39.next = 24;
2040
2237
  break;
2041
2238
  }
2042
2239
 
2043
- _context35.next = 17;
2240
+ _context39.next = 17;
2044
2241
  return this.decrypt(encryptedExistingCipher);
2045
2242
 
2046
2243
  case 17:
2047
- decrypted = _context35.sent;
2244
+ decrypted = _context39.sent;
2048
2245
 
2049
2246
  if (!(decrypted.login.password == cipher.login.password)) {
2050
- _context35.next = 23;
2247
+ _context39.next = 23;
2051
2248
  break;
2052
2249
  }
2053
2250
 
2054
2251
  logger.debug('Passwords are identical !');
2055
- return _context35.abrupt("return", encryptedExistingCipher);
2252
+ return _context39.abrupt("return", encryptedExistingCipher);
2056
2253
 
2057
2254
  case 23:
2058
2255
  logger.debug('Passwords are different');
2059
2256
 
2060
2257
  case 24:
2061
2258
  _iteratorNormalCompletion2 = true;
2062
- _context35.next = 5;
2259
+ _context39.next = 5;
2063
2260
  break;
2064
2261
 
2065
2262
  case 27:
2066
- _context35.next = 33;
2263
+ _context39.next = 33;
2067
2264
  break;
2068
2265
 
2069
2266
  case 29:
2070
- _context35.prev = 29;
2071
- _context35.t0 = _context35["catch"](3);
2267
+ _context39.prev = 29;
2268
+ _context39.t0 = _context39["catch"](3);
2072
2269
  _didIteratorError2 = true;
2073
- _iteratorError2 = _context35.t0;
2270
+ _iteratorError2 = _context39.t0;
2074
2271
 
2075
2272
  case 33:
2076
- _context35.prev = 33;
2077
- _context35.prev = 34;
2273
+ _context39.prev = 33;
2274
+ _context39.prev = 34;
2078
2275
 
2079
2276
  if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
2080
2277
  _iterator2.return();
2081
2278
  }
2082
2279
 
2083
2280
  case 36:
2084
- _context35.prev = 36;
2281
+ _context39.prev = 36;
2085
2282
 
2086
2283
  if (!_didIteratorError2) {
2087
- _context35.next = 39;
2284
+ _context39.next = 39;
2088
2285
  break;
2089
2286
  }
2090
2287
 
2091
2288
  throw _iteratorError2;
2092
2289
 
2093
2290
  case 39:
2094
- return _context35.finish(36);
2291
+ return _context39.finish(36);
2095
2292
 
2096
2293
  case 40:
2097
- return _context35.finish(33);
2294
+ return _context39.finish(33);
2098
2295
 
2099
2296
  case 41:
2100
2297
  case "end":
2101
- return _context35.stop();
2298
+ return _context39.stop();
2102
2299
  }
2103
2300
  }
2104
- }, _callee35, this, [[3, 29, 33, 41], [34,, 36, 40]]);
2301
+ }, _callee39, this, [[3, 29, 33, 41], [34,, 36, 40]]);
2105
2302
  }));
2106
2303
 
2107
- function searchExistingCipher(_x41) {
2304
+ function searchExistingCipher(_x46) {
2108
2305
  return _searchExistingCipher.apply(this, arguments);
2109
2306
  }
2110
2307
 
@@ -2115,22 +2312,22 @@ function () {
2115
2312
  value: function () {
2116
2313
  var _mergeCiphers = _asyncToGenerator(
2117
2314
  /*#__PURE__*/
2118
- _regeneratorRuntime.mark(function _callee36(encryptedExistingCipher, cipher) {
2315
+ _regeneratorRuntime.mark(function _callee40(encryptedExistingCipher, cipher) {
2119
2316
  var decryptedExistingCipher, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, mergedCipher;
2120
2317
 
2121
- return _regeneratorRuntime.wrap(function _callee36$(_context36) {
2318
+ return _regeneratorRuntime.wrap(function _callee40$(_context40) {
2122
2319
  while (1) {
2123
- switch (_context36.prev = _context36.next) {
2320
+ switch (_context40.prev = _context40.next) {
2124
2321
  case 0:
2125
- _context36.next = 2;
2322
+ _context40.next = 2;
2126
2323
  return this.decrypt(encryptedExistingCipher);
2127
2324
 
2128
2325
  case 2:
2129
- decryptedExistingCipher = _context36.sent;
2326
+ decryptedExistingCipher = _context40.sent;
2130
2327
  _iteratorNormalCompletion3 = true;
2131
2328
  _didIteratorError3 = false;
2132
2329
  _iteratorError3 = undefined;
2133
- _context36.prev = 6;
2330
+ _context40.prev = 6;
2134
2331
 
2135
2332
  _loop = function _loop() {
2136
2333
  var uri = _step3.value;
@@ -2147,58 +2344,58 @@ function () {
2147
2344
  _loop();
2148
2345
  }
2149
2346
 
2150
- _context36.next = 15;
2347
+ _context40.next = 15;
2151
2348
  break;
2152
2349
 
2153
2350
  case 11:
2154
- _context36.prev = 11;
2155
- _context36.t0 = _context36["catch"](6);
2351
+ _context40.prev = 11;
2352
+ _context40.t0 = _context40["catch"](6);
2156
2353
  _didIteratorError3 = true;
2157
- _iteratorError3 = _context36.t0;
2354
+ _iteratorError3 = _context40.t0;
2158
2355
 
2159
2356
  case 15:
2160
- _context36.prev = 15;
2161
- _context36.prev = 16;
2357
+ _context40.prev = 15;
2358
+ _context40.prev = 16;
2162
2359
 
2163
2360
  if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
2164
2361
  _iterator3.return();
2165
2362
  }
2166
2363
 
2167
2364
  case 18:
2168
- _context36.prev = 18;
2365
+ _context40.prev = 18;
2169
2366
 
2170
2367
  if (!_didIteratorError3) {
2171
- _context36.next = 21;
2368
+ _context40.next = 21;
2172
2369
  break;
2173
2370
  }
2174
2371
 
2175
2372
  throw _iteratorError3;
2176
2373
 
2177
2374
  case 21:
2178
- return _context36.finish(18);
2375
+ return _context40.finish(18);
2179
2376
 
2180
2377
  case 22:
2181
- return _context36.finish(15);
2378
+ return _context40.finish(15);
2182
2379
 
2183
2380
  case 23:
2184
2381
  logger.info('Merging ciphers', decryptedExistingCipher, cipher);
2185
- _context36.next = 26;
2382
+ _context40.next = 26;
2186
2383
  return this.createOrUpdateCipher(decryptedExistingCipher, encryptedExistingCipher);
2187
2384
 
2188
2385
  case 26:
2189
- mergedCipher = _context36.sent;
2386
+ mergedCipher = _context40.sent;
2190
2387
  logger.info('Merge result', mergedCipher);
2191
- return _context36.abrupt("return", mergedCipher);
2388
+ return _context40.abrupt("return", mergedCipher);
2192
2389
 
2193
2390
  case 29:
2194
2391
  case "end":
2195
- return _context36.stop();
2392
+ return _context40.stop();
2196
2393
  }
2197
2394
  }
2198
- }, _callee36, this, [[6, 11, 15, 23], [16,, 18, 22]]);
2395
+ }, _callee40, this, [[6, 11, 15, 23], [16,, 18, 22]]);
2199
2396
  }));
2200
2397
 
2201
- function mergeCiphers(_x42, _x43) {
2398
+ function mergeCiphers(_x47, _x48) {
2202
2399
  return _mergeCiphers.apply(this, arguments);
2203
2400
  }
2204
2401
 
@@ -2215,54 +2412,54 @@ function () {
2215
2412
  value: function () {
2216
2413
  var _prepareCipherToImport = _asyncToGenerator(
2217
2414
  /*#__PURE__*/
2218
- _regeneratorRuntime.mark(function _callee37(cipher) {
2415
+ _regeneratorRuntime.mark(function _callee41(cipher) {
2219
2416
  var cipherToSave, encryptedExistingCipher;
2220
- return _regeneratorRuntime.wrap(function _callee37$(_context37) {
2417
+ return _regeneratorRuntime.wrap(function _callee41$(_context41) {
2221
2418
  while (1) {
2222
- switch (_context37.prev = _context37.next) {
2419
+ switch (_context41.prev = _context41.next) {
2223
2420
  case 0:
2224
2421
  logger.info('Preparing cipher to import');
2225
2422
  cipher.login.uris = cipher.login.uris || [];
2226
- _context37.next = 4;
2423
+ _context41.next = 4;
2227
2424
  return this.searchExistingCipher(cipher);
2228
2425
 
2229
2426
  case 4:
2230
- encryptedExistingCipher = _context37.sent;
2427
+ encryptedExistingCipher = _context41.sent;
2231
2428
 
2232
2429
  if (!encryptedExistingCipher) {
2233
- _context37.next = 12;
2430
+ _context41.next = 12;
2234
2431
  break;
2235
2432
  }
2236
2433
 
2237
2434
  logger.info('Found existing cipher');
2238
- _context37.next = 9;
2435
+ _context41.next = 9;
2239
2436
  return this.mergeCiphers(encryptedExistingCipher, cipher);
2240
2437
 
2241
2438
  case 9:
2242
- cipherToSave = _context37.sent;
2243
- _context37.next = 16;
2439
+ cipherToSave = _context41.sent;
2440
+ _context41.next = 16;
2244
2441
  break;
2245
2442
 
2246
2443
  case 12:
2247
2444
  logger.info('Creating a new cipher');
2248
- _context37.next = 15;
2445
+ _context41.next = 15;
2249
2446
  return this.createOrUpdateCipher(cipher);
2250
2447
 
2251
2448
  case 15:
2252
- cipherToSave = _context37.sent;
2449
+ cipherToSave = _context41.sent;
2253
2450
 
2254
2451
  case 16:
2255
- return _context37.abrupt("return", cipherToSave);
2452
+ return _context41.abrupt("return", cipherToSave);
2256
2453
 
2257
2454
  case 17:
2258
2455
  case "end":
2259
- return _context37.stop();
2456
+ return _context41.stop();
2260
2457
  }
2261
2458
  }
2262
- }, _callee37, this);
2459
+ }, _callee41, this);
2263
2460
  }));
2264
2461
 
2265
- function prepareCipherToImport(_x44) {
2462
+ function prepareCipherToImport(_x49) {
2266
2463
  return _prepareCipherToImport.apply(this, arguments);
2267
2464
  }
2268
2465
 
@@ -2279,29 +2476,29 @@ function () {
2279
2476
  value: function () {
2280
2477
  var _importCipher = _asyncToGenerator(
2281
2478
  /*#__PURE__*/
2282
- _regeneratorRuntime.mark(function _callee38(cipher) {
2479
+ _regeneratorRuntime.mark(function _callee42(cipher) {
2283
2480
  var cipherToSave;
2284
- return _regeneratorRuntime.wrap(function _callee38$(_context38) {
2481
+ return _regeneratorRuntime.wrap(function _callee42$(_context42) {
2285
2482
  while (1) {
2286
- switch (_context38.prev = _context38.next) {
2483
+ switch (_context42.prev = _context42.next) {
2287
2484
  case 0:
2288
- _context38.next = 2;
2485
+ _context42.next = 2;
2289
2486
  return this.prepareCipherToImport(cipher);
2290
2487
 
2291
2488
  case 2:
2292
- cipherToSave = _context38.sent;
2293
- _context38.next = 5;
2489
+ cipherToSave = _context42.sent;
2490
+ _context42.next = 5;
2294
2491
  return this.saveCipher(cipherToSave);
2295
2492
 
2296
2493
  case 5:
2297
2494
  case "end":
2298
- return _context38.stop();
2495
+ return _context42.stop();
2299
2496
  }
2300
2497
  }
2301
- }, _callee38, this);
2498
+ }, _callee42, this);
2302
2499
  }));
2303
2500
 
2304
- function importCipher(_x45) {
2501
+ function importCipher(_x50) {
2305
2502
  return _importCipher.apply(this, arguments);
2306
2503
  }
2307
2504