@@ -233,18 +233,27 @@ export class Accounts implements IModule {
233233 return ;
234234 }
235235
236- // store key
237- await BrowserStorage . set ( {
238- key : { enc : encKey , hash : encKeyHash }
239- } ) ;
240236 // change entry encryption to key and remove old hash
237+ let oldKeys : string [ ] = [ ] ;
241238 for ( const entry of state . state . entries ) {
242239 await entry . changeEncryption (
243240 new Encryption ( wordArray . toString ( ) )
244241 ) ;
245- await entry . genUUID ( ) ;
242+ oldKeys . push ( entry . hash ) ;
243+ entry . genUUID ( ) ;
246244 }
247245
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+
248257 state . state . encryption . updateEncryptionPassword (
249258 wordArray . toString ( )
250259 ) ;
@@ -320,16 +329,34 @@ export class Accounts implements IModule {
320329 return ;
321330 }
322331
323- // store key
324- await BrowserStorage . set ( {
325- key : { enc : encKey , hash : encKeyHash }
326- } ) ;
327332 // change entry encryption and regen hash
333+ let removeHashes : string [ ] = [ ] ;
328334 for ( const entry of state . state . entries ) {
329335 await entry . changeEncryption (
330336 new Encryption ( wordArray . toString ( ) )
331337 ) ;
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+ } ) ;
333360 }
334361
335362 state . state . encryption . updateEncryptionPassword (
@@ -351,6 +378,7 @@ export class Accounts implements IModule {
351378 for ( const entry of state . state . entries ) {
352379 await entry . changeEncryption ( new Encryption ( "" ) ) ;
353380 }
381+ await EntryStorage . set ( state . state . entries ) ;
354382
355383 state . state . encryption . updateEncryptionPassword ( "" ) ;
356384
0 commit comments