@@ -233,18 +233,27 @@ export class Accounts implements IModule {
233
233
return ;
234
234
}
235
235
236
- // store key
237
- await BrowserStorage . set ( {
238
- key : { enc : encKey , hash : encKeyHash }
239
- } ) ;
240
236
// change entry encryption to key and remove old hash
237
+ let oldKeys : string [ ] = [ ] ;
241
238
for ( const entry of state . state . entries ) {
242
239
await entry . changeEncryption (
243
240
new Encryption ( wordArray . toString ( ) )
244
241
) ;
245
- await entry . genUUID ( ) ;
242
+ oldKeys . push ( entry . hash ) ;
243
+ entry . genUUID ( ) ;
246
244
}
247
245
246
+ // store key
247
+ await BrowserStorage . set ( {
248
+ key : { enc : encKey , hash : encKeyHash }
249
+ } ) ;
250
+ await EntryStorage . set ( state . state . entries ) ;
251
+ await new Promise ( resolve => {
252
+ BrowserStorage . remove ( oldKeys , ( ) => {
253
+ resolve ( ) ;
254
+ } ) ;
255
+ } ) ;
256
+
248
257
state . state . encryption . updateEncryptionPassword (
249
258
wordArray . toString ( )
250
259
) ;
@@ -320,16 +329,34 @@ export class Accounts implements IModule {
320
329
return ;
321
330
}
322
331
323
- // store key
324
- await BrowserStorage . set ( {
325
- key : { enc : encKey , hash : encKeyHash }
326
- } ) ;
327
332
// change entry encryption and regen hash
333
+ let removeHashes : string [ ] = [ ] ;
328
334
for ( const entry of state . state . entries ) {
329
335
await entry . changeEncryption (
330
336
new Encryption ( wordArray . toString ( ) )
331
337
) ;
332
- await entry . genUUID ( ) ;
338
+ // if not uuidv4 regen
339
+ if (
340
+ / [ 0 - 9 A - F ] { 8 } - [ 0 - 9 A - F ] { 4 } - 4 [ 0 - 9 A - F ] { 3 } - [ 8 9 A B ] [ 0 - 9 A - F ] { 3 } - [ 0 - 9 A - F ] { 12 } / i. test (
341
+ entry . hash
342
+ )
343
+ ) {
344
+ removeHashes . push ( entry . hash ) ;
345
+ entry . genUUID ( ) ;
346
+ }
347
+ }
348
+
349
+ // store key
350
+ await BrowserStorage . set ( {
351
+ key : { enc : encKey , hash : encKeyHash }
352
+ } ) ;
353
+ await EntryStorage . set ( state . state . entries ) ;
354
+ if ( removeHashes . length ) {
355
+ await new Promise ( resolve => {
356
+ BrowserStorage . remove ( removeHashes , ( ) => {
357
+ resolve ( ) ;
358
+ } ) ;
359
+ } ) ;
333
360
}
334
361
335
362
state . state . encryption . updateEncryptionPassword (
@@ -351,6 +378,7 @@ export class Accounts implements IModule {
351
378
for ( const entry of state . state . entries ) {
352
379
await entry . changeEncryption ( new Encryption ( "" ) ) ;
353
380
}
381
+ await EntryStorage . set ( state . state . entries ) ;
354
382
355
383
state . state . encryption . updateEncryptionPassword ( "" ) ;
356
384
0 commit comments